Skip to content

Commit

Permalink
[WIP] Shadow Feature (#329)
Browse files Browse the repository at this point in the history
* Shadow PHPCR Implementation (sulu#1)

* Shadow PHPCR Implementation

* Show correct save buttons

* Shadow Elasticsearch (sulu#2)

* First init

* Second

* Finished

* Fixed bug

* Fixed bug

* Use correct locale

* Reload document

* Use of rehydrate

* Load correct route for shadows

* Use of originalLocale

* Reload document when indexing shadow

* Add functional controller tests

* Add ArticleIndexerTest

* Fix test

* Shadow multi pages (sulu#3)

* Fixed bug

* Use correct locale

* Reload document

* Use of rehydrate

* Load correct route for shadows

* 1

* Remove not needed function

* Add test skeletion

* Finished implementation

* Load correct pageData

* Fix StyleCI

* added nl translations

* added fr translations

* Fix test

* More ram for es
  • Loading branch information
trickreich authored and wachterjohannes committed Jul 3, 2018
1 parent 3024bb0 commit 2377385
Show file tree
Hide file tree
Showing 39 changed files with 1,224 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- run:
name: Run Elasticsearch
command: |
./elasticsearch-${ES_VERSION}/bin/elasticsearch
ES_JAVA_OPTS="-Xms512m -Xmx1024m" ./elasticsearch-${ES_VERSION}/bin/elasticsearch
background: true
- run:
name: Test Elasticsearch
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PHPUnit
/app/config/parameters.yml
/Tests/app/config/parameters.yml
/app/phpunit.xml
/phpunit.xml

Expand Down
7 changes: 7 additions & 0 deletions Admin/ArticleContentNavigationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function getNavigationItems(array $options = [])
$tabs['details']->setAction($action);
$tabs['details']->setPosition(10);
$tabs['details']->setComponent('articles/edit/details@suluarticle');
$tabs['details']->setDisplayConditions(
[
new DisplayCondition('shadowOn', DisplayCondition::OPERATOR_EQUAL, false),
]
);

if ($page < 2) {
$tabs['seo'] = new ContentNavigationItem('content-navigation.contents.seo');
Expand All @@ -49,6 +54,7 @@ public function getNavigationItems(array $options = [])
$tabs['seo']->setDisplayConditions(
[
new DisplayCondition('type', DisplayCondition::OPERATOR_EQUAL, null),
new DisplayCondition('shadowOn', DisplayCondition::OPERATOR_EQUAL, false),
]
);

Expand All @@ -61,6 +67,7 @@ public function getNavigationItems(array $options = [])
$tabs['excerpt']->setDisplayConditions(
[
new DisplayCondition('type', DisplayCondition::OPERATOR_EQUAL, null),
new DisplayCondition('shadowOn', DisplayCondition::OPERATOR_EQUAL, false),
]
);

Expand Down
6 changes: 1 addition & 5 deletions Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,7 @@ public function getAction($uuid, Request $request)
$locale = $this->getRequestParameter($request, 'locale', true);
$document = $this->getDocumentManager()->find(
$uuid,
$locale,
[
'load_ghost_content' => true,
'load_shadow_content' => false,
]
$locale
);

return $this->handleView(
Expand Down
2 changes: 1 addition & 1 deletion Controller/ArticlePageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getAction($articleUuid, $uuid, Request $request)
$locale,
[
'load_ghost_content' => true,
'load_shadow_content' => false,
'load_shadow_content' => true,
]
);

Expand Down
50 changes: 49 additions & 1 deletion Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sulu\Component\Content\Document\Behavior\LocalizedAuditableBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedAuthorBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedStructureBehavior;
use Sulu\Component\Content\Document\Behavior\ShadowLocaleBehavior;
use Sulu\Component\Content\Document\Behavior\StructureBehavior;
use Sulu\Component\Content\Document\Behavior\WorkflowStageBehavior;
use Sulu\Component\Content\Document\Extension\ExtensionContainer;
Expand Down Expand Up @@ -52,7 +53,8 @@ class ArticleDocument implements
VersionBehavior,
LocalizedAuthorBehavior,
ChildrenBehavior,
ArticleInterface
ArticleInterface,
ShadowLocaleBehavior
{
/**
* @var string
Expand Down Expand Up @@ -182,6 +184,20 @@ class ArticleDocument implements
*/
protected $children;

/**
* Shadow locale is enabled.
*
* @var bool
*/
protected $shadowLocaleEnabled = false;

/**
* Shadow locale.
*
* @var string
*/
protected $shadowLocale;

public function __construct()
{
$this->structure = new Structure();
Expand Down Expand Up @@ -575,4 +591,36 @@ public function setPages($pages)

return $this;
}

/**
* {@inheritdoc}
*/
public function getShadowLocale()
{
return $this->shadowLocale;
}

/**
* {@inheritdoc}
*/
public function setShadowLocale($shadowLocale)
{
$this->shadowLocale = $shadowLocale;
}

/**
* {@inheritdoc}
*/
public function isShadowLocaleEnabled()
{
return $this->shadowLocaleEnabled;
}

/**
* {@inheritdoc}
*/
public function setShadowLocaleEnabled($shadowLocaleEnabled)
{
$this->shadowLocaleEnabled = $shadowLocaleEnabled;
}
}
50 changes: 49 additions & 1 deletion Document/ArticlePageDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Sulu\Bundle\ArticleBundle\Document\Behavior\RoutablePageBehavior;
use Sulu\Bundle\RouteBundle\Model\RouteInterface;
use Sulu\Component\Content\Document\Behavior\LocalizedStructureBehavior;
use Sulu\Component\Content\Document\Behavior\ShadowLocaleBehavior;
use Sulu\Component\Content\Document\Behavior\StructureBehavior;
use Sulu\Component\Content\Document\Structure\Structure;
use Sulu\Component\Content\Document\Structure\StructureInterface;
Expand All @@ -37,7 +38,8 @@ class ArticlePageDocument implements
LocalizedStructureBehavior,
RoutablePageBehavior,
PageBehavior,
ArticleInterface
ArticleInterface,
ShadowLocaleBehavior
{
/**
* @var string
Expand Down Expand Up @@ -99,6 +101,20 @@ class ArticlePageDocument implements
*/
protected $pageNumber;

/**
* Shadow locale is enabled.
*
* @var bool
*/
protected $shadowLocaleEnabled = false;

/**
* Shadow locale.
*
* @var string
*/
protected $shadowLocale;

public function __construct()
{
$this->structure = new Structure();
Expand Down Expand Up @@ -360,4 +376,36 @@ public function getExtensionsData()
{
return $this->getParent()->getExtensionsData();
}

/**
* {@inheritdoc}
*/
public function getShadowLocale()
{
return $this->shadowLocale;
}

/**
* {@inheritdoc}
*/
public function setShadowLocale($shadowLocale)
{
$this->shadowLocale = $shadowLocale;
}

/**
* {@inheritdoc}
*/
public function isShadowLocaleEnabled()
{
return $this->shadowLocaleEnabled;
}

/**
* {@inheritdoc}
*/
public function setShadowLocaleEnabled($shadowLocaleEnabled)
{
$this->shadowLocaleEnabled = $shadowLocaleEnabled;
}
}
3 changes: 3 additions & 0 deletions Document/Form/ArticleDocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Sulu\Bundle\ArticleBundle\Document\Form;

use Sulu\Bundle\ContentBundle\Form\Type\AbstractStructureBehaviorType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
Expand All @@ -31,6 +32,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)

// extensions
$builder->add('extensions', TextType::class, ['property_path' => 'extensionsData']);
$builder->add('shadowLocaleEnabled', CheckboxType::class);
$builder->add('shadowLocale', TextType::class);

$builder->add('author', TextType::class);
$builder->add(
Expand Down
14 changes: 14 additions & 0 deletions Document/Form/ArticlePageDocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@
namespace Sulu\Bundle\ArticleBundle\Document\Form;

use Sulu\Bundle\ContentBundle\Form\Type\AbstractStructureBehaviorType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Form-type for article-page mapping.
*/
class ArticlePageDocumentType extends AbstractStructureBehaviorType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);

$builder->add('shadowLocaleEnabled', CheckboxType::class);
$builder->add('shadowLocale', TextType::class);
}

/**
* {@inheritdoc}
*/
Expand Down
39 changes: 29 additions & 10 deletions Document/Index/ArticleGhostIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sulu\Bundle\ArticleBundle\Document\Index\Factory\ExcerptFactory;
use Sulu\Bundle\ArticleBundle\Document\Index\Factory\SeoFactory;
use Sulu\Bundle\ContactBundle\Entity\ContactRepository;
use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector;
use Sulu\Bundle\SecurityBundle\UserManager\UserManager;
use Sulu\Component\Content\Document\LocalizationState;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;
Expand Down Expand Up @@ -50,9 +51,10 @@ class ArticleGhostIndexer extends ArticleIndexer
* @param SeoFactory $seoFactory
* @param EventDispatcherInterface $eventDispatcher
* @param TranslatorInterface $translator
* @param DocumentManagerInterface $documentManager
* @param DocumentInspector $inspector
* @param array $typeConfiguration
* @param WebspaceManagerInterface $webspaceManager
* @param DocumentManagerInterface $documentManager
*/
public function __construct(
StructureMetadataFactoryInterface $structureMetadataFactory,
Expand All @@ -64,9 +66,10 @@ public function __construct(
SeoFactory $seoFactory,
EventDispatcherInterface $eventDispatcher,
TranslatorInterface $translator,
DocumentManagerInterface $documentManager,
DocumentInspector $inspector,
array $typeConfiguration,
WebspaceManagerInterface $webspaceManager,
DocumentManagerInterface $documentManager
WebspaceManagerInterface $webspaceManager
) {
parent::__construct(
$structureMetadataFactory,
Expand All @@ -78,6 +81,8 @@ public function __construct(
$seoFactory,
$eventDispatcher,
$translator,
$documentManager,
$inspector,
$typeConfiguration
);

Expand All @@ -90,7 +95,14 @@ public function __construct(
*/
public function index(ArticleDocument $document)
{
if ($document->isShadowLocaleEnabled()) {
$this->indexShadow($document);

return;
}

$article = $this->createOrUpdateArticle($document, $document->getLocale());
$this->createOrUpdateShadows($document);
$this->createOrUpdateGhosts($document);
$this->dispatchIndexEvent($document, $article);
$this->manager->persist($article);
Expand All @@ -109,15 +121,22 @@ private function createOrUpdateGhosts(ArticleDocument $document)
continue;
}

/** @var ArticleDocument $ghostDocument */
$ghostDocument = $this->documentManager->find(
$document->getUuid(),
$locale
);

$localizationState = $this->inspector->getLocalizationState($ghostDocument);

// Only index ghosts
if (LocalizationState::GHOST !== $localizationState) {
continue;
}

// Try index the article ghosts.
$article = $this->createOrUpdateArticle(
$this->documentManager->find(
$document->getUuid(),
$locale,
[
'load_ghost_content' => true,
]
),
$ghostDocument,
$localization->getLocale(),
LocalizationState::GHOST
);
Expand Down
Loading

0 comments on commit 2377385

Please sign in to comment.