diff --git a/.travis.yml b/.travis.yml index 02abdeef..e7b222e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ matrix: - CODE_COVERAGE="--coverage-clover=coverage.clover" before_install: + - phpenv config-add Tests/travis.php.ini - composer self-update install: diff --git a/Admin/CommentAdmin.php b/Admin/CommentAdmin.php index 3e228de1..8e0c3c20 100644 --- a/Admin/CommentAdmin.php +++ b/Admin/CommentAdmin.php @@ -23,6 +23,7 @@ class CommentAdmin extends Admin { const COMMENT_SECURITY_CONTEXT = 'sulu.comment.comments'; + const THREAD_SECURITY_CONTEXT = 'sulu.comment.threads'; /** diff --git a/Controller/CommentController.php b/Controller/CommentController.php index 8d7ff776..e04fd6d8 100644 --- a/Controller/CommentController.php +++ b/Controller/CommentController.php @@ -196,9 +196,11 @@ public function postTriggerAction($id, Request $request) switch ($action) { case 'unpublish': $commentManager->unpublish($comment); + break; case 'publish': $commentManager->publish($comment); + break; default: throw new RestException('Unrecognized action: ' . $action); diff --git a/Controller/WebsiteCommentController.php b/Controller/WebsiteCommentController.php index 009245a2..ec8038a1 100644 --- a/Controller/WebsiteCommentController.php +++ b/Controller/WebsiteCommentController.php @@ -46,7 +46,7 @@ public function cgetCommentsAction($threadId, Request $request) $page ? 20 : null ); - if ($request->getRequestFormat() === 'json') { + if ('json' === $request->getRequestFormat()) { return $this->handleView($this->view($comments)); } @@ -101,7 +101,7 @@ public function postCommentsAction($threadId, Request $request) $this->get('doctrine.orm.entity_manager')->flush(); - if ($request->getRequestFormat() === 'json') { + if ('json' === $request->getRequestFormat()) { return $this->handleView($this->view($comment)); } diff --git a/Entity/Comment.php b/Entity/Comment.php index 26e8061b..a664e988 100644 --- a/Entity/Comment.php +++ b/Entity/Comment.php @@ -124,7 +124,7 @@ public function unpublish() */ public function isPublished() { - return $this->state === self::STATE_PUBLISHED; + return self::STATE_PUBLISHED === $this->state; } /** diff --git a/Entity/CommentInterface.php b/Entity/CommentInterface.php index 07a70cd7..88e00d1f 100644 --- a/Entity/CommentInterface.php +++ b/Entity/CommentInterface.php @@ -17,6 +17,7 @@ interface CommentInterface { const STATE_UNPUBLISHED = 0; + const STATE_PUBLISHED = 1; /** diff --git a/Events/Events.php b/Events/Events.php index f10d7cdf..56a40b81 100644 --- a/Events/Events.php +++ b/Events/Events.php @@ -17,19 +17,23 @@ final class Events { const PRE_PERSIST_EVENT = 'sulu_comment.pre_persist'; + const POST_PERSIST_EVENT = 'sulu_comment.post_persist'; const PRE_DELETE_EVENT = 'sulu_comment.pre_delete'; + const POST_DELETE_EVENT = 'sulu_comment.post_delete'; const PRE_UPDATE_EVENT = 'sulu_comment.pre_update'; const PUBLISH_EVENT = 'sulu_comment.publish'; + const UNPUBLISH_EVENT = 'sulu_comment.unpublish'; const THREAD_PRE_UPDATE_EVENT = 'sulu_comment.thread.pre_update'; const THREAD_PRE_DELETE_EVENT = 'sulu_comment.thread.pre_delete'; + const THREAD_POST_DELETE_EVENT = 'sulu_comment.thread.post_delete'; /** diff --git a/Resources/public/dist/components/comments/list/main.js b/Resources/public/dist/components/comments/list/main.js index 0fee1d4e..1ecaa175 100644 --- a/Resources/public/dist/components/comments/list/main.js +++ b/Resources/public/dist/components/comments/list/main.js @@ -1 +1 @@ -define(["services/sulucomment/comment-manager","services/sulucomment/comment-router","text!./list.html"],function(a,b,c){var d={templates:{list:c},translations:{title:"sulu_comment.comments"}};return{defaults:d,header:function(){return{title:this.translations.title,underline:!1,noBack:!0,toolbar:{buttons:{deleteSelected:{options:{callback:function(){this.sandbox.emit("husky.datagrid.comments.items.get-selected",this.deleteItems.bind(this))}.bind(this)}}}}}},layout:{content:{width:"max"}},initialize:function(){this.render(),this.bindCustomEvents()},render:function(){this.$el.html(this.templates.list()),this.sandbox.sulu.initListToolbarAndList.call(this,"comments",a.url()+"/fields",{el:this.$find("#list-toolbar-container"),instanceName:"comments",template:this.sandbox.sulu.buttons.get({settings:{options:{dropdownItems:[{type:"columnOptions"}]}}})},{el:this.sandbox.dom.find("#comments-list"),url:a.url()+"?sortBy=created&sortOrder=desc",searchInstanceName:"comments",searchFields:["title"],resultKey:"comments",instanceName:"comments",actionCallback:function(a){b.toEdit(a)},contentFilters:{message:function(a){var b=document.createElement("div");return b.innerHTML=a,a=b.textContent||b.innerText,this.sandbox.util.cropMiddle(a,300)}.bind(this)},viewOptions:{table:{selectItem:{type:"checkbox",inFirstCell:!1}}}})},deleteItems:function(b){this.sandbox.emit("sulu.header.toolbar.item.loading","deleteSelected"),a.deleteMultiple(b).then(function(){for(var a in b)this.sandbox.emit("husky.datagrid.comments.record.remove",b[a]);this.sandbox.emit("sulu.header.toolbar.item.disable","deleteSelected")}.bind(this))},bindCustomEvents:function(){this.sandbox.on("husky.datagrid.comments.number.selections",function(a){var b=a>0?"enable":"disable";this.sandbox.emit("sulu.header.toolbar.item."+b,"deleteSelected",!1)}.bind(this))}}}); \ No newline at end of file +define(["services/sulucomment/comment-manager","services/sulucomment/comment-router","text!./list.html"],function(a,b,c){var d={templates:{list:c},translations:{title:"sulu_comment.comments"}};return{defaults:d,header:function(){return{title:this.translations.title,underline:!1,noBack:!0,toolbar:{buttons:{deleteSelected:{options:{callback:function(){this.sandbox.emit("husky.datagrid.comments.items.get-selected",this.deleteItems.bind(this))}.bind(this)}},"export":{options:{url:"/admin/api/comments.csv"}}}}}},layout:{content:{width:"max"}},initialize:function(){this.render(),this.bindCustomEvents()},render:function(){this.$el.html(this.templates.list()),this.sandbox.sulu.initListToolbarAndList.call(this,"comments",a.url()+"/fields",{el:this.$find("#list-toolbar-container"),instanceName:"comments",template:this.sandbox.sulu.buttons.get({settings:{options:{dropdownItems:[{type:"columnOptions"}]}}})},{el:this.sandbox.dom.find("#comments-list"),url:a.url()+"?sortBy=created&sortOrder=desc",searchInstanceName:"comments",searchFields:["title"],resultKey:"comments",instanceName:"comments",actionCallback:function(a){b.toEdit(a)},contentFilters:{message:function(a){var b=document.createElement("div");return b.innerHTML=a,a=b.textContent||b.innerText,this.sandbox.util.cropMiddle(a,300)}.bind(this)},viewOptions:{table:{selectItem:{type:"checkbox",inFirstCell:!1}}}})},deleteItems:function(b){this.sandbox.emit("sulu.header.toolbar.item.loading","deleteSelected"),a.deleteMultiple(b).then(function(){for(var a in b)this.sandbox.emit("husky.datagrid.comments.record.remove",b[a]);this.sandbox.emit("sulu.header.toolbar.item.disable","deleteSelected")}.bind(this))},bindCustomEvents:function(){this.sandbox.on("husky.datagrid.comments.number.selections",function(a){var b=a>0?"enable":"disable";this.sandbox.emit("sulu.header.toolbar.item."+b,"deleteSelected",!1)}.bind(this))}}}); \ No newline at end of file diff --git a/Resources/public/dist/components/threads/list/main.js b/Resources/public/dist/components/threads/list/main.js index eff35407..b129be01 100644 --- a/Resources/public/dist/components/threads/list/main.js +++ b/Resources/public/dist/components/threads/list/main.js @@ -1 +1 @@ -define(["services/sulucomment/thread-manager","services/sulucomment/thread-router","text!./list.html"],function(a,b,c){var d={templates:{list:c},translations:{title:"sulu_comment.threads"}};return{defaults:d,header:function(){return{title:this.translations.title,underline:!1,noBack:!0,toolbar:{buttons:{deleteSelected:{options:{callback:function(){this.sandbox.emit("husky.datagrid.threads.items.get-selected",this.deleteItems.bind(this))}.bind(this)}}}}}},layout:{content:{width:"max"}},initialize:function(){this.render(),this.bindCustomEvents()},render:function(){this.$el.html(this.templates.list()),this.sandbox.sulu.initListToolbarAndList.call(this,"threads",a.url()+"/fields",{el:this.$find("#list-toolbar-container"),instanceName:"threads",template:this.sandbox.sulu.buttons.get({settings:{options:{dropdownItems:[{type:"columnOptions"}]}}})},{el:this.sandbox.dom.find("#threads-list"),url:a.url()+"?sortBy=created&sortOrder=desc",searchInstanceName:"threads",searchFields:["title"],resultKey:"threads",instanceName:"threads",actionCallback:function(a){b.toEdit(a)},viewOptions:{table:{selectItem:{type:"checkbox",inFirstCell:!1}}}})},deleteItems:function(b){this.sandbox.emit("sulu.header.toolbar.item.loading","deleteSelected"),a.deleteMultiple(b).then(function(){for(var a in b)this.sandbox.emit("husky.datagrid.threads.record.remove",b[a]);this.sandbox.emit("sulu.header.toolbar.item.disable","deleteSelected")}.bind(this))},bindCustomEvents:function(){this.sandbox.on("husky.datagrid.threads.number.selections",function(a){var b=a>0?"enable":"disable";this.sandbox.emit("sulu.header.toolbar.item."+b,"deleteSelected",!1)}.bind(this))}}}); \ No newline at end of file +define(["services/sulucomment/thread-manager","services/sulucomment/thread-router","text!./list.html"],function(a,b,c){var d={templates:{list:c},translations:{title:"sulu_comment.threads"}};return{defaults:d,header:function(){return{title:this.translations.title,underline:!1,noBack:!0,toolbar:{buttons:{deleteSelected:{options:{callback:function(){this.sandbox.emit("husky.datagrid.threads.items.get-selected",this.deleteItems.bind(this))}.bind(this)}},"export":{options:{url:"/admin/api/threads.csv"}}}}}},layout:{content:{width:"max"}},initialize:function(){this.render(),this.bindCustomEvents()},render:function(){this.$el.html(this.templates.list()),this.sandbox.sulu.initListToolbarAndList.call(this,"threads",a.url()+"/fields",{el:this.$find("#list-toolbar-container"),instanceName:"threads",template:this.sandbox.sulu.buttons.get({settings:{options:{dropdownItems:[{type:"columnOptions"}]}}})},{el:this.sandbox.dom.find("#threads-list"),url:a.url()+"?sortBy=created&sortOrder=desc",searchInstanceName:"threads",searchFields:["title"],resultKey:"threads",instanceName:"threads",actionCallback:function(a){b.toEdit(a)},viewOptions:{table:{selectItem:{type:"checkbox",inFirstCell:!1}}}})},deleteItems:function(b){this.sandbox.emit("sulu.header.toolbar.item.loading","deleteSelected"),a.deleteMultiple(b).then(function(){for(var a in b)this.sandbox.emit("husky.datagrid.threads.record.remove",b[a]);this.sandbox.emit("sulu.header.toolbar.item.disable","deleteSelected")}.bind(this))},bindCustomEvents:function(){this.sandbox.on("husky.datagrid.threads.number.selections",function(a){var b=a>0?"enable":"disable";this.sandbox.emit("sulu.header.toolbar.item."+b,"deleteSelected",!1)}.bind(this))}}}); \ No newline at end of file diff --git a/Resources/public/js/components/comments/list/main.js b/Resources/public/js/components/comments/list/main.js index 514c3502..274f081b 100644 --- a/Resources/public/js/components/comments/list/main.js +++ b/Resources/public/js/components/comments/list/main.js @@ -45,6 +45,11 @@ define([ ); }.bind(this) } + }, + export: { + options: { + url: '/admin/api/comments.csv' + } } } } diff --git a/Resources/public/js/components/threads/list/main.js b/Resources/public/js/components/threads/list/main.js index 537526d7..c1e14875 100644 --- a/Resources/public/js/components/threads/list/main.js +++ b/Resources/public/js/components/threads/list/main.js @@ -45,6 +45,11 @@ define([ ); }.bind(this) } + }, + export: { + options: { + url: '/admin/api/threads.csv' + } } } } diff --git a/Tests/app/AppKernel.php b/Tests/app/AppKernel.php index 58edb35c..6c966929 100644 --- a/Tests/app/AppKernel.php +++ b/Tests/app/AppKernel.php @@ -37,7 +37,7 @@ public function registerBundles() parent::registerBundles() ); - if ($this->getContext() !== self::CONTEXT_ADMIN) { + if (self::CONTEXT_ADMIN !== $this->getContext()) { $bundles[] = new \FOS\RestBundle\FOSRestBundle(); } diff --git a/Tests/travis.php.ini b/Tests/travis.php.ini new file mode 100644 index 00000000..0b134267 --- /dev/null +++ b/Tests/travis.php.ini @@ -0,0 +1 @@ +memory_limit = 4G