diff --git a/Document/Index/ArticleIndexer.php b/Document/Index/ArticleIndexer.php index fbc28a2da..378fdbbb5 100644 --- a/Document/Index/ArticleIndexer.php +++ b/Document/Index/ArticleIndexer.php @@ -23,9 +23,7 @@ use Sulu\Bundle\ArticleBundle\Event\IndexEvent; use Sulu\Bundle\ArticleBundle\Metadata\ArticleTypeTrait; use Sulu\Bundle\ArticleBundle\Metadata\ArticleViewDocumentIdTrait; -use Sulu\Bundle\ContactBundle\Entity\Contact; use Sulu\Bundle\ContactBundle\Entity\ContactRepository; -use Sulu\Bundle\SecurityBundle\Entity\User; use Sulu\Bundle\SecurityBundle\UserManager\UserManager; use Sulu\Component\Content\Document\LocalizationState; use Sulu\Component\Content\Document\WorkflowStage; @@ -200,29 +198,14 @@ protected function createOrUpdateArticle( $article->setChanged($document->getChanged()); $article->setCreated($document->getCreated()); $article->setAuthored($document->getAuthored()); - if ($document->getAuthor()) { - /** @var Contact $author */ - $author = $this->contactRepository->findById($document->getAuthor()); - if ($author) { - $article->setAuthorFullName($author->getFullName()); - $article->setAuthorId($author->getId()); - } + if ($document->getAuthor() && $author = $this->contactRepository->findById($document->getAuthor())) { + $article->setAuthorFullName($author->getFullName()); } - if ($document->getChanger()) { - /** @var User $changer */ - $changer = $this->userManager->getUserById($document->getChanger()); - if ($changer) { - $article->setChangerFullName($changer->getFullName()); - $article->setChangerContactId($changer->getContact()->getId()); - } + if ($document->getChanger() && $changer = $this->userManager->getUserById($document->getChanger())) { + $article->setChangerFullName($changer->getFullName()); } - if ($document->getCreator()) { - /** @var User $creator */ - $creator = $this->userManager->getUserById($document->getCreator()); - if ($creator) { - $article->setCreatorFullName($creator->getFullName()); - $article->setCreatorContactId($creator->getContact()->getId()); - } + if ($document->getCreator() && $creator = $this->userManager->getUserById($document->getCreator())) { + $article->setCreatorFullName($creator->getFullName()); } $article->setType($this->getType($structureMetadata)); $article->setStructureType($document->getStructureType()); @@ -237,9 +220,12 @@ protected function createOrUpdateArticle( ); $extensions = $document->getExtensionsData()->toArray(); - $article->setExcerpt($this->excerptFactory->create($extensions['excerpt'], $document->getLocale())); - $article->setSeo($this->seoFactory->create($extensions['seo'])); - + if (array_key_exists('excerpt', $extensions)) { + $article->setExcerpt($this->excerptFactory->create($extensions['excerpt'], $document->getLocale())); + } + if (array_key_exists('seo', $extensions)) { + $article->setSeo($this->seoFactory->create($extensions['seo'])); + } if ($structureMetadata->hasPropertyWithTagName('sulu.teaser.description')) { $descriptionProperty = $structureMetadata->getPropertyByTagName('sulu.teaser.description'); $article->setTeaserDescription( diff --git a/Document/Subscriber/ArticleSubscriber.php b/Document/Subscriber/ArticleSubscriber.php index 3afde320b..69562a1df 100644 --- a/Document/Subscriber/ArticleSubscriber.php +++ b/Document/Subscriber/ArticleSubscriber.php @@ -102,7 +102,7 @@ public static function getSubscribedEvents() { return [ Events::HYDRATE => [['handleHydrate', -500]], - Events::PERSIST => [['handleRoute', 0], ['handleRouteUpdate', 0], ['handleScheduleIndex', -500]], + Events::PERSIST => [['handleRouteUpdate', 1], ['handleRoute', 0], ['handleScheduleIndex', -500]], Events::REMOVE => [['handleRemove', -500], ['handleRemoveLive', -500]], Events::METADATA_LOAD => 'handleMetadataLoad', Events::PUBLISH => [['handleScheduleIndexLive', 0], ['handleScheduleIndex', 0]], @@ -147,7 +147,7 @@ public function handleRoute(AbstractMappingEvent $event) $document->setUuid($event->getNode()->getIdentifier()); - $route = $this->routeManager->create($document); + $route = $this->routeManager->create($document, $event->getOption('route_path')); $this->entityManager->persist($route); $this->entityManager->flush(); } diff --git a/Resources/public/dist/components/articles/list/main.js b/Resources/public/dist/components/articles/list/main.js index 8bf233b6a..f7fdf2b9b 100644 --- a/Resources/public/dist/components/articles/list/main.js +++ b/Resources/public/dist/components/articles/list/main.js @@ -1 +1 @@ -define(["underscore","services/husky/storage","sulucontent/components/copy-locale-overlay/main","sulucontent/components/open-ghost-overlay/main","services/suluarticle/article-manager"],function(a,b,c,d,e){"use strict";var f={options:{config:{},storageName:"articles"},templates:{list:['
','
','
','
'].join(""),draftIcon:'',publishedIcon:'',route:["articles","<% if (!!type) { %>:<%=type%><% } %>","/<%=locale%>"].join("")},translations:{headline:"sulu_article.list.title",unpublished:"public.unpublished",publishedWithDraft:"public.published-with-draft",filterMe:"sulu_article.list.filter.me",filterAll:"sulu_article.list.filter.all",openGhostOverlay:{info:"sulu_article.settings.open-ghost-overlay.info","new":"sulu_article.settings.open-ghost-overlay.new",copy:"sulu_article.settings.open-ghost-overlay.copy",ok:"sulu_article.settings.open-ghost-overlay.ok"}}};return{defaults:f,header:function(){this.storage=b.get("sulu",this.options.storageName);var c,d=this.options.config.types,e=this.options.config.typeNames,f={icon:"plus-circle",title:"public.add-new"},g=!1,h=null,i=this.options.type||this.storage.getWithDefault("type",null);return 1===e.length?f.callback=function(){this.toAdd(e[0])}.bind(this):(f.dropdownItems=a.map(e,function(a){return{title:d[a].title,callback:function(){this.toAdd(a)}.bind(this)}}.bind(this)),c=[],this.options.config.displayTabAll===!0&&c.push({name:"public.all",key:null}),a.each(e,function(a){c.push({id:a,name:d[a].title,key:a}),a===i&&(h=d[a].title)}.bind(this)),g={componentOptions:{callback:this.typeChange.bind(this),preselector:"name",preselect:h},data:c}),{noBack:!0,tabs:g,toolbar:{buttons:{addArticle:{options:f},deleteSelected:{}},languageChanger:{data:this.options.config.languageChanger,preSelected:this.options.locale}}}},layout:{content:{width:"max"}},initialize:function(){if(this.options.type)this.storage.set("type",this.options.type);else if(this.storage.has("type")){var a=this.templates.route({type:this.storage.get("type"),locale:this.options.locale});this.sandbox.emit("sulu.router.navigate",a,!1,!1),this.options.type=this.storage.get("type")}this.render(),this.bindCustomEvents()},render:function(){this.$el.html(this.templates.list()),this.sandbox.sulu.initListToolbarAndList.call(this,"article","/admin/api/articles/fields",{el:this.$find(".list-toolbar-container"),instanceName:"articles",template:this.retrieveListToolbarTemplate()},{el:this.sandbox.dom.find(".datagrid-container"),url:"/admin/api/articles?sortBy=authored&sortOrder=desc&locale="+this.options.locale+(this.options.type?"&type="+this.options.type:""),storageName:this.options.storageName,searchInstanceName:"articles",searchFields:["title"],resultKey:"articles",idKey:"uuid",instanceName:"articles",actionCallback:function(a,b){"ghost"===b.localizationState.state?e.load(a,this.options.locale).then(function(b){d.openGhost.call(this,b,this.translations.openGhostOverlay).then(function(b,d){b?c.copyLocale.call(this,a,d,[this.options.locale],function(){this.toEdit(a)}.bind(this)):this.toEdit(a)}.bind(this))}.bind(this)).fail(function(a){this.sandbox.emit("sulu.article.error",a.status,data)}.bind(this)):this.toEdit(a)}.bind(this),viewOptions:{table:{actionIconColumn:"title",badges:[{column:"title",callback:function(a,b){return!(!a.localizationState||"ghost"!==a.localizationState.state||a.localizationState.locale===this.options.locale)&&(b.title=a.localizationState.locale,b)}.bind(this)},{column:"title",callback:function(a,b){var c="",d=this.translations.unpublished;return a.published&&!a.publishedState&&(d=this.translations.publishedWithDraft,c+=this.templates.publishedIcon({title:d})),a.publishedState||(c+=this.templates.draftIcon({title:d})),b.title=c,b.cssClass="badge-none",b}.bind(this)}]}}})},toEdit:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(b||this.options.locale)+"/edit:"+a+"/details")},toAdd:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(b||this.options.locale)+"/add"+(this.options.config.typeNames.length>1?":"+a:""))},toList:function(a){1!==this.options.config.typeNames.length&&this.options.type?this.sandbox.emit("sulu.router.navigate","articles:"+this.options.type+"/"+(a||this.options.locale)):this.sandbox.emit("sulu.router.navigate","articles/"+(a||this.options.locale))},deleteItems:function(b){this.sandbox.util.save("/admin/api/articles?ids="+b.join(","),"DELETE").then(function(){a.each(b,function(a){this.sandbox.emit("husky.datagrid.articles.record.remove",a)}.bind(this))}.bind(this))},typeChange:function(a){var b=this.templates.route({type:a.key,locale:this.options.locale});this.options.type=a.key,this.sandbox.emit("husky.datagrid.articles.url.update",{page:1,type:a.key}),this.sandbox.emit("sulu.router.navigate",b,!1,!1),this.storage.set("type",a.key)},getCopyLocaleUrl:function(a,b,c){return e.getCopyLocaleUrl(a,b,c)},bindCustomEvents:function(){this.sandbox.on("husky.datagrid.articles.number.selections",function(a){var b=a>0?"enable":"disable";this.sandbox.emit("sulu.header.toolbar.item."+b,"deleteSelected",!1)}.bind(this)),this.sandbox.on("sulu.toolbar.delete",function(){this.sandbox.emit("husky.datagrid.articles.items.get-selected",this.deleteItems.bind(this))}.bind(this)),this.sandbox.on("sulu.header.language-changed",function(a){a.id!==this.options.locale&&(this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey,a.id),this.toList(a.id))}.bind(this))},retrieveListToolbarTemplate:function(){return this.sandbox.sulu.buttons.get({contactIdFilter:{options:{icon:"filter",group:2,title:this.translations.filterAll,showTitle:!0,dropdownOptions:{preSelected:"all",idAttribute:"id",markSelected:!0,changeButton:!0,callback:function(a){this.applyFilterToList.call(this,a)}.bind(this)},dropdownItems:[{id:"me",title:this.translations.filterMe},{id:"all",title:this.translations.filterAll}]}}})},applyFilterToList:function(a){var b=null;if(a.id)switch(a.id){case"me":b=this.sandbox.sulu.user.id;break;default:b=null}this.sandbox.emit("husky.datagrid.articles.url.update",{contactId:b})}}}); \ No newline at end of file +define(["underscore","services/husky/storage","sulucontent/components/copy-locale-overlay/main","sulucontent/components/open-ghost-overlay/main","services/suluarticle/article-manager"],function(a,b,c,d,e){"use strict";var f={options:{config:{},storageName:"articles"},templates:{list:['
','
','
','
'].join(""),draftIcon:'',publishedIcon:'',route:["articles","<% if (!!type) { %>:<%=type%><% } %>","/<%=locale%>"].join("")},translations:{headline:"sulu_article.list.title",unpublished:"public.unpublished",publishedWithDraft:"public.published-with-draft",filterMe:"sulu_article.list.filter.me",filterAll:"sulu_article.list.filter.all",openGhostOverlay:{info:"sulu_article.settings.open-ghost-overlay.info","new":"sulu_article.settings.open-ghost-overlay.new",copy:"sulu_article.settings.open-ghost-overlay.copy",ok:"sulu_article.settings.open-ghost-overlay.ok"}}};return{defaults:f,header:function(){this.storage=b.get("sulu",this.options.storageName);var c,d=this.options.config.types,e=this.options.config.typeNames,f={icon:"plus-circle",title:"public.add-new"},g=!1,h=null,i=this.options.type||this.storage.getWithDefault("type",null);return 1===e.length?f.callback=function(){this.toAdd(e[0])}.bind(this):(f.dropdownItems=a.map(e,function(a){return{title:d[a].title,callback:function(){this.toAdd(a)}.bind(this)}}.bind(this)),c=[],this.options.config.displayTabAll===!0&&c.push({name:"public.all",key:null}),a.each(e,function(a){c.push({id:a,name:d[a].title,key:a}),a===i&&(h=d[a].title)}.bind(this)),g={componentOptions:{callback:this.typeChange.bind(this),preselector:"name",preselect:h},data:c}),{noBack:!0,tabs:g,toolbar:{buttons:{addArticle:{options:f},deleteSelected:{}},languageChanger:{data:this.options.config.languageChanger,preSelected:this.options.locale}}}},layout:{content:{width:"max"}},initialize:function(){if(this.options.type)this.storage.set("type",this.options.type);else if(this.storage.has("type")){var a=this.templates.route({type:this.storage.get("type"),locale:this.options.locale});this.sandbox.emit("sulu.router.navigate",a,!1,!1),this.options.type=this.storage.get("type")}this.render(),this.bindCustomEvents()},render:function(){this.$el.html(this.templates.list()),this.sandbox.sulu.initListToolbarAndList.call(this,"article","/admin/api/articles/fields",{el:this.$find(".list-toolbar-container"),instanceName:"articles",template:this.retrieveListToolbarTemplate()},{el:this.sandbox.dom.find(".datagrid-container"),url:"/admin/api/articles?sortBy=authored&sortOrder=desc&locale="+this.options.locale+(this.options.type?"&type="+this.options.type:""),storageName:this.options.storageName,searchInstanceName:"articles",searchFields:["title"],resultKey:"articles",idKey:"uuid",instanceName:"articles",actionCallback:function(a,b){"ghost"===b.localizationState.state?e.load(a,this.options.locale).then(function(b){d.openGhost.call(this,b,this.translations.openGhostOverlay).then(function(b,d){b?c.copyLocale.call(this,a,d,[this.options.locale],function(){this.toEdit(a)}.bind(this)):this.toEdit(a)}.bind(this))}.bind(this)).fail(function(a){this.sandbox.emit("sulu.article.error",a.status,data)}.bind(this)):this.toEdit(a)}.bind(this),viewOptions:{table:{actionIconColumn:"title",badges:[{column:"title",callback:function(a,b){return!(!a.localizationState||"ghost"!==a.localizationState.state||a.localizationState.locale===this.options.locale)&&(b.title=a.localizationState.locale,b)}.bind(this)},{column:"title",callback:function(a,b){var c="",d=this.translations.unpublished;return a.published&&!a.publishedState&&(d=this.translations.publishedWithDraft,c+=this.templates.publishedIcon({title:d})),a.publishedState||(c+=this.templates.draftIcon({title:d})),b.title=c,b.cssClass="badge-none",b}.bind(this)}]}}})},toEdit:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(b||this.options.locale)+"/edit:"+a+"/details")},toAdd:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(b||this.options.locale)+"/add"+(this.options.config.typeNames.length>1?":"+a:""))},toList:function(a){1!==this.options.config.typeNames.length&&this.options.type?this.sandbox.emit("sulu.router.navigate","articles:"+this.options.type+"/"+(a||this.options.locale)):this.sandbox.emit("sulu.router.navigate","articles/"+(a||this.options.locale))},deleteItems:function(b){this.sandbox.util.save("/admin/api/articles?ids="+b.join(",")+"&locale="+this.options.locale,"DELETE").then(function(){a.each(b,function(a){this.sandbox.emit("husky.datagrid.articles.record.remove",a)}.bind(this))}.bind(this))},typeChange:function(a){var b=this.templates.route({type:a.key,locale:this.options.locale});this.options.type=a.key,this.sandbox.emit("husky.datagrid.articles.url.update",{page:1,type:a.key}),this.sandbox.emit("sulu.router.navigate",b,!1,!1),this.storage.set("type",a.key)},getCopyLocaleUrl:function(a,b,c){return e.getCopyLocaleUrl(a,b,c)},bindCustomEvents:function(){this.sandbox.on("husky.datagrid.articles.number.selections",function(a){var b=a>0?"enable":"disable";this.sandbox.emit("sulu.header.toolbar.item."+b,"deleteSelected",!1)}.bind(this)),this.sandbox.on("sulu.toolbar.delete",function(){this.sandbox.emit("husky.datagrid.articles.items.get-selected",this.deleteItems.bind(this))}.bind(this)),this.sandbox.on("sulu.header.language-changed",function(a){a.id!==this.options.locale&&(this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey,a.id),this.toList(a.id))}.bind(this))},retrieveListToolbarTemplate:function(){return this.sandbox.sulu.buttons.get({contactIdFilter:{options:{icon:"filter",group:2,title:this.translations.filterAll,showTitle:!0,dropdownOptions:{preSelected:"all",idAttribute:"id",markSelected:!0,changeButton:!0,callback:function(a){this.applyFilterToList.call(this,a)}.bind(this)},dropdownItems:[{id:"me",title:this.translations.filterMe},{id:"all",title:this.translations.filterAll}]}}})},applyFilterToList:function(a){var b=null;if(a.id)switch(a.id){case"me":b=this.sandbox.sulu.user.id;break;default:b=null}this.sandbox.emit("husky.datagrid.articles.url.update",{contactId:b})}}}); \ No newline at end of file diff --git a/Resources/public/js/components/articles/list/main.js b/Resources/public/js/components/articles/list/main.js index 05d77320b..614ca5514 100644 --- a/Resources/public/js/components/articles/list/main.js +++ b/Resources/public/js/components/articles/list/main.js @@ -277,7 +277,10 @@ define([ }, deleteItems: function(ids) { - this.sandbox.util.save('/admin/api/articles?ids=' + ids.join(','), 'DELETE').then(function() { + this.sandbox.util.save( + '/admin/api/articles?ids=' + ids.join(',') + '&locale=' + this.options.locale, + 'DELETE' + ).then(function() { _.each(ids, function(id) { this.sandbox.emit('husky.datagrid.articles.record.remove', id); }.bind(this)); diff --git a/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php b/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php index 144410403..e747b8885 100644 --- a/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php +++ b/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php @@ -116,7 +116,7 @@ public function testHandleRoute() $route = $this->prophesize(RouteInterface::class); $this->document->getRoutePath()->willReturn(null); $this->document->setUuid('123-123-123')->shouldBeCalled(); - $this->routeManager->create($this->document->reveal())->shouldBeCalled()->willReturn($route->reveal()); + $this->routeManager->create($this->document->reveal(), null)->shouldBeCalled()->willReturn($route->reveal()); $this->entityManager->persist($route->reveal())->shouldBeCalled(); $this->entityManager->flush()->shouldBeCalled(); @@ -124,6 +124,21 @@ public function testHandleRoute() $this->articleSubscriber->handleRoute($this->prophesizeEvent(PersistEvent::class)); } + public function testHandleRouteWithRoute() + { + $route = $this->prophesize(RouteInterface::class); + $this->document->getRoutePath()->willReturn(null); + $this->document->setUuid('123-123-123')->shouldBeCalled(); + $this->routeManager->create($this->document->reveal(), '/test-1') + ->shouldBeCalled() + ->willReturn($route->reveal()); + + $this->entityManager->persist($route->reveal())->shouldBeCalled(); + $this->entityManager->flush()->shouldBeCalled(); + + $this->articleSubscriber->handleRoute($this->prophesizeEvent(PersistEvent::class, '/test-1')); + } + public function testHandleRouteUpdate() { $route = $this->prophesize(RouteInterface::class);