summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/routes.php67
-rw-r--r--db/foldermapper.php5
-rw-r--r--external_api/folder.php37
-rw-r--r--folder.bl.php26
4 files changed, 98 insertions, 37 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 1427d4443..095e03f83 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -26,7 +26,7 @@ require_once \OC_App::getAppPath('news') . '/appinfo/bootstrap.php';
function callController($controllerName, $methodName, $urlParams, $disableAdminCheck=true,
$isAjax=false){
$container = createDIContainer();
-
+
// run security checks
$security = $container['Security'];
runSecurityChecks($security, $isAjax, $disableAdminCheck);
@@ -60,7 +60,7 @@ function callAjaxController($controllerName, $methodName, $urlParams, $disableAd
*/
function runSecurityChecks($security, $isAjax=false, $disableAdminCheck=true){
if($disableAdminCheck){
- $security->setIsAdminCheck(false);
+ $security->setIsAdminCheck(false);
}
if($isAjax){
@@ -80,19 +80,19 @@ function runSecurityChecks($security, $isAjax=false, $disableAdminCheck=true){
* Normal Routes
*/
$this->create('news_index', '/')->action(
- function($params){
+ function($params){
callController('NewsController', 'index', $params, true);
}
);
$this->create('news_index_feed', '/feed/{feedid}')->action(
- function($params){
+ function($params){
callController('NewsController', 'index', $params, true);
}
);
$this->create('news_export_opml', '/export/opml')->action(
- function($params){
+ function($params){
callController('NewsController', 'exportOPML', $params, true);
}
);
@@ -102,13 +102,13 @@ $this->create('news_export_opml', '/export/opml')->action(
* AJAX Routes
*/
$this->create('news_ajax_init', '/ajax/init')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'init', $params);
}
);
$this->create('news_ajax_setshowall', '/ajax/setshowall')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'setShowAll', $params);
}
);
@@ -118,25 +118,25 @@ $this->create('news_ajax_setshowall', '/ajax/setshowall')->action(
* Folders
*/
$this->create('news_ajax_collapsefolder', '/ajax/collapsefolder')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'collapseFolder', $params);
}
);
$this->create('news_ajax_changefoldername', '/ajax/changefoldername')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'changeFolderName', $params);
}
);
$this->create('news_ajax_createfolder', '/ajax/createfolder')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'createFolder', $params);
}
);
$this->create('news_ajax_deletefolder', '/ajax/deletefolder')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'deleteFolder', $params);
}
);
@@ -146,31 +146,31 @@ $this->create('news_ajax_deletefolder', '/ajax/deletefolder')->action(
* Feeds
*/
$this->create('news_ajax_loadfeed', '/ajax/loadfeed')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'loadFeed', $params);
}
);
$this->create('news_ajax_deletefeed', '/ajax/deletefeed')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'deleteFeed', $params);
}
);
$this->create('news_ajax_movefeedtofolder', '/ajax/movefeedtofolder')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'moveFeedToFolder', $params);
}
);
$this->create('news_ajax_updatefeed', '/ajax/updatefeed')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'updateFeed', $params);
}
);
$this->create('news_ajax_createfeed', '/ajax/createfeed')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'createFeed', $params);
}
);
@@ -180,13 +180,13 @@ $this->create('news_ajax_createfeed', '/ajax/createfeed')->action(
* Items
*/
$this->create('news_ajax_setitemstatus', '/ajax/setitemstatus')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'setItemStatus', $params);
}
);
$this->create('news_ajax_setallitemsread', '/ajax/setallitemsread')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'setAllItemsRead', $params);
}
);
@@ -196,7 +196,7 @@ $this->create('news_ajax_setallitemsread', '/ajax/setallitemsread')->action(
* Import stuff
*/
$this->create('news_ajax_importOPML', '/import')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'uploadOPML', $params);
}
);
@@ -205,13 +205,13 @@ $this->create('news_ajax_importOPML', '/import')->action(
/**
* External API
*/
-
-/**
+
+/**
* Feed API
*/
\OCP\API::register(
- 'get', '/news/feeds',
+ 'get', '/news/feeds',
function($urlParams) {
$container = createDIContainer();
return $container['FeedApi']->getAll($urlParams);
@@ -219,7 +219,7 @@ $this->create('news_ajax_importOPML', '/import')->action(
'news', \OC_API::USER_AUTH
);
\OCP\API::register(
- 'get', '/news/feeds/{feedid}',
+ 'get', '/news/feeds/{feedid}',
function($urlParams) {
$container = createDIContainer();
return $container['FeedApi']->getById($urlParams);
@@ -227,7 +227,7 @@ $this->create('news_ajax_importOPML', '/import')->action(
'news', \OC_API::USER_AUTH
);
\OCP\API::register(
- 'post', '/news/feeds/create',
+ 'post', '/news/feeds/create',
function($urlParams) {
$container = createDIContainer();
return $container['FeedApi']->create($urlParams);
@@ -235,7 +235,7 @@ $this->create('news_ajax_importOPML', '/import')->action(
'news', \OC_API::USER_AUTH
);
-/**
+/**
* Folder API
*/
@@ -247,7 +247,6 @@ $this->create('news_ajax_importOPML', '/import')->action(
},
'news', \OC_API::USER_AUTH
);
-
\OCP\API::register(
'post', '/news/folders/create',
function($urlParams) {
@@ -255,4 +254,20 @@ $this->create('news_ajax_importOPML', '/import')->action(
return $container['FolderApi']->create($urlParams);
},
'news', \OC_API::USER_AUTH
+);
+\OCP\API::register(
+ 'get', '/news/folders/{folderid}/delete',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FolderApi']->delete($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
+\OCP\API::register(
+ 'post', '/news/folders/{folderid}/modify',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FolderApi']->modify($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
); \ No newline at end of file
diff --git a/db/foldermapper.php b/db/foldermapper.php
index 52504ea6e..d9040b50b 100644
--- a/db/foldermapper.php
+++ b/db/foldermapper.php
@@ -53,7 +53,7 @@ class FolderMapper {
return $folderlist;
}
-
+
/**
* @brief Returns the forest (list of trees) of folders children of $parentid
* @param
@@ -111,6 +111,9 @@ class FolderMapper {
$result = $stmt->execute(array($this->userid, $id));
$row = $result->fetchRow();
+ if(!$row)
+ return null;
+
$folder = new Folder($row['name'], $row['id']);
$folder->setOpened($row['opened']);
diff --git a/external_api/folder.php b/external_api/folder.php
index 66e5f3915..68c8ff523 100644
--- a/external_api/folder.php
+++ b/external_api/folder.php
@@ -13,22 +13,47 @@ class FolderApi {
public function getAll() {
$folders = $this->bl->getAll();
$serializedFolders = array();
-
- //TODO: check the behaviour for nested folders
+
+ //TODO: check the behaviour for nested folders
foreach ($folders as $folder) {
$serializedFolders[] = $folder->jsonSerialize();
}
return new \OC_OCS_Result($serializedFolders);
}
-
+
public function create() {
-
$name = $_POST['name'];
$parentId = $_POST['parentid'];
-
+
$this->bl->create($name, $parentId);
-
+
return new \OC_OCS_Result();
}
+
+ public function delete($params) {
+ $id = $params['folderid'];
+ if(!is_numeric($id))
+ return new \OC_OCS_Result(null,999,'Invalid input! folderid must be an integer');
+
+ if($this->bl->delete($id))
+ return new \OC_OCS_Result();
+ else
+ return new \OC_OCS_Result(null,999,'Could not delete folder');
+ }
+
+ public function modify($params) {
+ $id = $params['folderid'];
+ if(!is_numeric($id))
+ return new \OC_OCS_Result(null,999,'Invalid input! folderid must be an integer'.$id);
+
+ $name = $_POST['name'];
+ $parentId = $_POST['parentid'];
+ $opened = $_POST['opened'];
+
+ if($this->bl->modify($id, $name, $parentid, $opened))
+ return new \OC_OCS_Result();
+ else
+ return new \OC_OCS_Result(null,999,'Could not modify folder');
+ }
}
diff --git a/folder.bl.php b/folder.bl.php
index 722baf8fc..85c386d90 100644
--- a/folder.bl.php
+++ b/folder.bl.php
@@ -7,14 +7,32 @@ class FolderBl {
public function __construct($folderMapper){
$this->folderMapper = $folderMapper;
}
-
+
public function getAll() {
- return $this->folderMapper->getAll();
+ return $this->folderMapper->getAll();
}
-
+
public function create($name, $parentId) {
//TODO: change the setparentid in the model class Folder
$folder = new Folder($name, null, null);
- return $this->folderMapper->save($folder);
+ return $this->folderMapper->save($folder);
+ }
+
+ public function delete($folderid) {
+ return $this->folderMapper->deleteById($folderid);
+ }
+
+ public function modify($folderid, $name = null, $parent = null, $opened = null) {
+ $folder = $this->folderMapper->find($folderid);
+ if(!$folder)
+ return false;
+
+ if($name)
+ $folder->setName($name);
+ if($parent)
+ $folder->setParentId($parent);
+ if($opened)
+ $folder->setOpened($opened);
+ return $this->folderMapper->update($folder);
}
}
pan> u32 *vaend) { unsigned long start, end; int nchunks; struct rpcrdma_write_array *ary = (struct rpcrdma_write_array *)va; /* Check for not write-array */ if (ary->wc_discrim == xdr_zero) return (u32 *)&ary->wc_nchunks; if ((unsigned long)ary + sizeof(struct rpcrdma_write_array) > (unsigned long)vaend) { dprintk("svcrdma: ary=%p, vaend=%p\n", ary, vaend); return NULL; } nchunks = ntohl(ary->wc_nchunks); start = (unsigned long)&ary->wc_array[0]; end = (unsigned long)vaend; if (nchunks < 0 || nchunks > (SIZE_MAX - start) / sizeof(struct rpcrdma_write_chunk) || (start + (sizeof(struct rpcrdma_write_chunk) * nchunks)) > end) { dprintk("svcrdma: ary=%p, wc_nchunks=%d, vaend=%p\n", ary, nchunks, vaend); return NULL; } /* * rs_length is the 2nd 4B field in wc_target and taking its * address skips the list terminator */ return (u32 *)&ary->wc_array[nchunks].wc_target.rs_length; } static u32 *decode_reply_array(u32 *va, u32 *vaend) { unsigned long start, end; int nchunks; struct rpcrdma_write_array *ary = (struct rpcrdma_write_array *)va; /* Check for no reply-array */ if (ary->wc_discrim == xdr_zero) return (u32 *)&ary->wc_nchunks; if ((unsigned long)ary + sizeof(struct rpcrdma_write_array) > (unsigned long)vaend) { dprintk("svcrdma: ary=%p, vaend=%p\n", ary, vaend); return NULL; } nchunks = ntohl(ary->wc_nchunks); start = (unsigned long)&ary->wc_array[0]; end = (unsigned long)vaend; if (nchunks < 0 || nchunks > (SIZE_MAX - start) / sizeof(struct rpcrdma_write_chunk) || (start + (sizeof(struct rpcrdma_write_chunk) * nchunks)) > end) { dprintk("svcrdma: ary=%p, wc_nchunks=%d, vaend=%p\n", ary, nchunks, vaend); return NULL; } return (u32 *)&ary->wc_array[nchunks]; } int svc_rdma_xdr_decode_req(struct rpcrdma_msg **rdma_req, struct svc_rqst *rqstp) { struct rpcrdma_msg *rmsgp = NULL; u32 *va; u32 *vaend; u32 hdr_len; rmsgp = (struct rpcrdma_msg *)rqstp->rq_arg.head[0].iov_base; /* Verify that there's enough bytes for header + something */ if (rqstp->rq_arg.len <= RPCRDMA_HDRLEN_MIN) { dprintk("svcrdma: header too short = %d\n", rqstp->rq_arg.len); return -EINVAL; } /* Decode the header */ rmsgp->rm_xid = ntohl(rmsgp->rm_xid); rmsgp->rm_vers = ntohl(rmsgp->rm_vers); rmsgp->rm_credit = ntohl(rmsgp->rm_credit); rmsgp->rm_type = ntohl(rmsgp->rm_type); if (rmsgp->rm_vers != RPCRDMA_VERSION) return -ENOSYS; /* Pull in the extra for the padded case and bump our pointer */ if (rmsgp->rm_type == RDMA_MSGP) { int hdrlen; rmsgp->rm_body.rm_padded.rm_align = ntohl(rmsgp->rm_body.rm_padded.rm_align); rmsgp->rm_body.rm_padded.rm_thresh = ntohl(rmsgp->rm_body.rm_padded.rm_thresh); va = &rmsgp->rm_body.rm_padded.rm_pempty[4]; rqstp->rq_arg.head[0].iov_base = va; hdrlen = (u32)((unsigned long)va - (unsigned long)rmsgp); rqstp->rq_arg.head[0].iov_len -= hdrlen; if (hdrlen > rqstp->rq_arg.len) return -EINVAL; return hdrlen; } /* The chunk list may contain either a read chunk list or a write * chunk list and a reply chunk list. */ va = &rmsgp->rm_body.rm_chunks[0]; vaend = (u32 *)((unsigned long)rmsgp + rqstp->rq_arg.len); va = decode_read_list(va, vaend); if (!va) return -EINVAL; va = decode_write_list(va, vaend); if (!va) return -EINVAL; va = decode_reply_array(va, vaend); if (!va) return -EINVAL; rqstp->rq_arg.head[0].iov_base = va; hdr_len = (unsigned long)va - (unsigned long)rmsgp; rqstp->rq_arg.head[0].iov_len -= hdr_len; *rdma_req = rmsgp; return hdr_len; } int svc_rdma_xdr_decode_deferred_req(struct svc_rqst *rqstp) { struct rpcrdma_msg *rmsgp = NULL; struct rpcrdma_read_chunk *ch; struct rpcrdma_write_array *ary; u32 *va; u32 hdrlen; dprintk("svcrdma: processing deferred RDMA header on rqstp=%p\n", rqstp); rmsgp = (struct rpcrdma_msg *)rqstp->rq_arg.head[0].iov_base; /* Pull in the extra for the padded case and bump our pointer */ if (rmsgp->rm_type == RDMA_MSGP) { va = &rmsgp->rm_body.rm_padded.rm_pempty[4]; rqstp->rq_arg.head[0].iov_base = va; hdrlen = (u32)((unsigned long)va - (unsigned long)rmsgp); rqstp->rq_arg.head[0].iov_len -= hdrlen; return hdrlen; } /* * Skip all chunks to find RPC msg. These were previously processed */ va = &rmsgp->rm_body.rm_chunks[0]; /* Skip read-list */ for (ch = (struct rpcrdma_read_chunk *)va; ch->rc_discrim != xdr_zero; ch++); va = (u32 *)&ch->rc_position; /* Skip write-list */ ary = (struct rpcrdma_write_array *)va; if (ary->wc_discrim == xdr_zero) va = (u32 *)&ary->wc_nchunks; else /* * rs_length is the 2nd 4B field in wc_target and taking its * address skips the list terminator */