Skip to content

Commit

Permalink
changed order of handle-route (update before create) and added route_…
Browse files Browse the repository at this point in the history
…path to create (#99)
  • Loading branch information
wachterjohannes authored and alexander-schranz committed Mar 14, 2017
1 parent ce4fe65 commit 21f0e75
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 35 deletions.
41 changes: 15 additions & 26 deletions Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -200,29 +198,17 @@ 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());
$article->setAuthorId($author->getId());
}
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());
$article->setChangerContactId($changer->getContact()->getId());
}
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->setCreatorContactId($creator->getContact()->getId());
}
$article->setType($this->getType($structureMetadata));
$article->setStructureType($document->getStructureType());
Expand All @@ -237,9 +223,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(
Expand Down
4 changes: 2 additions & 2 deletions Document/Subscriber/ArticleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/public/dist/components/articles/list/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/public/dist/services/manager.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/public/js/components/articles/list/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ define([
},

deleteItems: function(ids) {
this.sandbox.util.save('/admin/api/articles?ids=' + ids.join(','), 'DELETE').then(function() {
ArticleManager.remove(ids, this.options.locale).then(function() {
_.each(ids, function(id) {
this.sandbox.emit('husky.datagrid.articles.record.remove', id);
}.bind(this));
Expand Down
Loading

0 comments on commit 21f0e75

Please sign in to comment.