Skip to content

Commit

Permalink
Remove dimension entity
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Dec 17, 2020
1 parent 107a976 commit 219fbe7
Show file tree
Hide file tree
Showing 95 changed files with 1,498 additions and 2,934 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ jobs:
- name: Create downloads directory
run: mkdir downloads

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Get downloads path
id: php-cs-fixer-dir
run: echo "::set-output name=dir::downloads"
Expand Down
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ return PhpCsFixer\Config::create()
PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('cache')
->exclude('Tests/reports/')
->in(__DIR__)
);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;

class WorkflowDataMapper implements DataMapperInterface
Expand Down Expand Up @@ -60,7 +59,7 @@ private function setInitialPlaceToDraftDimension(WorkflowInterface $object, arra
// see: https://github.com/sulu/SuluContentBundle/issues/92

if (!$object instanceof DimensionContentInterface
|| DimensionInterface::STAGE_DRAFT !== $object->getDimension()->getStage()) {
|| DimensionContentInterface::STAGE_DRAFT !== $object->getStage()) {
return;
}

Expand All @@ -79,7 +78,7 @@ private function setPublishedToLiveDimension(WorkflowInterface $object, array $d
// therefore we only want to copy the published property from the draft to the live dimension

if (!$object instanceof DimensionContentInterface
|| DimensionInterface::STAGE_LIVE !== $object->getDimension()->getStage()) {
|| DimensionContentInterface::STAGE_LIVE !== $object->getStage()) {
return;
}

Expand Down
11 changes: 5 additions & 6 deletions Content/Application/ContentIndexer/ContentIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;

class ContentIndexer implements ContentIndexerInterface
{
Expand Down Expand Up @@ -88,7 +87,7 @@ public function deindexDimensionContent(DimensionContentInterface $dimensionCont
return;
}

$this->searchManager->deindex($dimensionContent, $dimensionContent->getDimension()->getLocale());
$this->searchManager->deindex($dimensionContent, $dimensionContent->getLocale());
}

/**
Expand All @@ -107,8 +106,8 @@ private function loadDimensionContent(

$dimensionContent = $this->contentResolver->resolve($contentRichEntity, $dimensionAttributes);

if ($locale !== $dimensionContent->getDimension()->getLocale()
|| $stage !== $dimensionContent->getDimension()->getStage()) {
if ($locale !== $dimensionContent->getLocale()
|| $stage !== $dimensionContent->getStage()) {
throw new ContentNotFoundException($contentRichEntity, $dimensionAttributes);
}

Expand All @@ -127,11 +126,11 @@ function ($indexName) use ($resourceKey, $stage) {
return $resourceKey === $indexName || $resourceKey . '_published' === $indexName;
}

if (DimensionInterface::STAGE_DRAFT === $stage) {
if (DimensionContentInterface::STAGE_DRAFT === $stage) {
return $resourceKey === $indexName;
}

if (DimensionInterface::STAGE_LIVE === $stage) {
if (DimensionContentInterface::STAGE_LIVE === $stage) {
return $resourceKey . '_published' === $indexName;
}

Expand Down
35 changes: 24 additions & 11 deletions Content/Application/ContentMerger/ContentMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\MergerInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Symfony\Component\PropertyAccess\PropertyAccessor;

class ContentMerger implements ContentMergerInterface
{
Expand All @@ -24,35 +25,47 @@ class ContentMerger implements ContentMergerInterface
*/
private $mergers;

/**
* @var PropertyAccessor
*/
private $propertyAccessor;

/**
* @param iterable<MergerInterface> $mergers
*/
public function __construct(iterable $mergers)
{
public function __construct(
iterable $mergers,
PropertyAccessor $propertyAccessor
) {
$this->mergers = $mergers;
$this->propertyAccessor = $propertyAccessor;
}

public function merge(DimensionContentCollectionInterface $dimensionContentCollection): DimensionContentInterface
{
if (!$dimensionContentCollection->count()) {
$unlocalizedDimensionContent = $dimensionContentCollection->getUnlocalizedDimensionContent();

if (!$unlocalizedDimensionContent) {
throw new \RuntimeException('Expected at least one dimensionContent given.');
}

/** @var DimensionContentInterface[] $dimensionContentCollectionArray */
$dimensionContentCollectionArray = iterator_to_array($dimensionContentCollection);
$lastKey = \count($dimensionContentCollectionArray) - 1;

$mostSpecificDimensionContent = $dimensionContentCollectionArray[$lastKey];
$mostSpecificDimension = $mostSpecificDimensionContent->getDimension();
$contentRichEntity = $mostSpecificDimensionContent->getResource();
$contentRichEntity = $unlocalizedDimensionContent->getResource();

$mergedDimensionContent = $contentRichEntity->createDimensionContent($mostSpecificDimension);
$mergedDimensionContent = $contentRichEntity->createDimensionContent();
$mergedDimensionContent->markAsMerged();

foreach ($dimensionContentCollection as $dimensionContent) {
foreach ($this->mergers as $merger) {
$merger->merge($mergedDimensionContent, $dimensionContent);
}

foreach ($dimensionContent::getDefaultAttributes() as $key => $value) {
$this->propertyAccessor->setValue(
$mergedDimensionContent,
$key,
$this->propertyAccessor->getValue($dimensionContent, $key)
);
}
}

return $mergedDimensionContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function enhance(object $object, array $normalizedData): array
}

$normalizedData['id'] = $object->getResource()->getId();
$normalizedData['locale'] = $object->getDimension()->getLocale();
$normalizedData['stage'] = $object->getDimension()->getStage();
$normalizedData['locale'] = $object->getLocale();
$normalizedData['stage'] = $object->getStage();

return $normalizedData;
}
Expand Down
11 changes: 1 addition & 10 deletions Content/Application/ContentPersister/ContentPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentPersister;

use Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\ContentMergerInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\DimensionCollectionFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\DimensionContentCollectionFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;

class ContentPersister implements ContentPersisterInterface
{
/**
* @var DimensionCollectionFactoryInterface
*/
private $dimensionCollectionFactory;

/**
* @var DimensionContentCollectionFactoryInterface
*/
Expand All @@ -37,11 +31,9 @@ class ContentPersister implements ContentPersisterInterface
private $contentMerger;

public function __construct(
DimensionCollectionFactoryInterface $dimensionCollectionFactory,
DimensionContentCollectionFactoryInterface $dimensionContentCollectionFactory,
ContentMergerInterface $contentMerger
) {
$this->dimensionCollectionFactory = $dimensionCollectionFactory;
$this->dimensionContentCollectionFactory = $dimensionContentCollectionFactory;
$this->contentMerger = $contentMerger;
}
Expand All @@ -56,10 +48,9 @@ public function persist(ContentRichEntityInterface $contentRichEntity, array $da
* TODO: maybe throw an exception here if the $dimensionAttributes contain another stage than 'STAGE_DRAFT'
*/

$dimensionCollection = $this->dimensionCollectionFactory->create($dimensionAttributes);
$dimensionContentCollection = $this->dimensionContentCollectionFactory->create(
$contentRichEntity,
$dimensionCollection,
$dimensionAttributes,
$data
);

Expand Down
16 changes: 1 addition & 15 deletions Content/Application/ContentResolver/ContentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionRepositoryInterface;

class ContentResolver implements ContentResolverInterface
{
/**
* @var DimensionRepositoryInterface
*/
private $dimensionRepository;

/**
* @var DimensionContentRepositoryInterface
*/
Expand All @@ -38,24 +32,16 @@ class ContentResolver implements ContentResolverInterface
private $contentMerger;

public function __construct(
DimensionRepositoryInterface $dimensionRepository,
DimensionContentRepositoryInterface $dimensionContentRepository,
ContentMergerInterface $contentMerger
) {
$this->dimensionRepository = $dimensionRepository;
$this->dimensionContentRepository = $dimensionContentRepository;
$this->contentMerger = $contentMerger;
}

public function resolve(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface
{
$dimensionCollection = $this->dimensionRepository->findByAttributes($dimensionAttributes);

if (0 === \count($dimensionCollection)) {
throw new ContentNotFoundException($contentRichEntity, $dimensionAttributes);
}

$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionCollection);
$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionAttributes);

if (0 === \count($dimensionContentCollection)) {
throw new ContentNotFoundException($contentRichEntity, $dimensionAttributes);
Expand Down
17 changes: 2 additions & 15 deletions Content/Application/ContentWorkflow/ContentWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionRepositoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Workflow\DefinitionBuilder;
Expand All @@ -36,11 +35,6 @@

class ContentWorkflow implements ContentWorkflowInterface
{
/**
* @var DimensionRepositoryInterface
*/
private $dimensionRepository;

/**
* @var DimensionContentRepositoryInterface
*/
Expand All @@ -62,13 +56,11 @@ class ContentWorkflow implements ContentWorkflowInterface
private $workflowRegistry;

public function __construct(
DimensionRepositoryInterface $dimensionRepository,
DimensionContentRepositoryInterface $dimensionContentRepository,
ContentMergerInterface $contentMerger,
?Registry $workflowRegistry = null,
?EventDispatcherInterface $eventDispatcher = null
) {
$this->dimensionRepository = $dimensionRepository;
$this->dimensionContentRepository = $dimensionContentRepository;
$this->contentMerger = $contentMerger;
$this->eventDispatcher = $eventDispatcher ?: new EventDispatcher();
Expand All @@ -93,13 +85,8 @@ public function apply(
* TODO: maybe throw an exception here if the $dimensionAttributes contain another stage than 'STAGE_DRAFT'
*/

$dimensionCollection = $this->dimensionRepository->findByAttributes($dimensionAttributes);

if (0 === \count($dimensionCollection)) {
throw new ContentNotFoundException($contentRichEntity, $dimensionAttributes);
}

$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionCollection);
$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionAttributes);
$dimensionAttributes = $dimensionContentCollection->getDimensionAttributes();

$localizedDimensionContent = $dimensionContentCollection->getLocalizedDimensionContent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\TransitionEvent;
Expand Down Expand Up @@ -67,7 +66,7 @@ public function onPublish(TransitionEvent $transitionEvent): void
throw new \RuntimeException('No "contentRichEntity" given.');
}

$dimensionAttributes['stage'] = DimensionInterface::STAGE_LIVE;
$dimensionAttributes['stage'] = DimensionContentInterface::STAGE_LIVE;

$this->contentCopier->copyFromDimensionContentCollection(
$dimensionContentCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\TransitionEvent;
Expand Down Expand Up @@ -52,8 +51,8 @@ public function onRemoveDraft(TransitionEvent $transitionEvent): void
throw new \RuntimeException('Transition context must contain "contentRichEntity".');
}

$draftDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionInterface::STAGE_DRAFT]);
$liveDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionInterface::STAGE_LIVE]);
$draftDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_DRAFT]);
$liveDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_LIVE]);

$this->contentCopier->copy(
$contentRichEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\TransitionEvent;

class UnpublishTransitionSubscriber implements EventSubscriberInterface
{
/**
* @var DimensionRepositoryInterface
*/
private $dimensionRepository;

/**
* @var DimensionContentRepositoryInterface
*/
Expand All @@ -43,11 +36,9 @@ class UnpublishTransitionSubscriber implements EventSubscriberInterface
protected $entityManager;

public function __construct(
DimensionRepositoryInterface $dimensionRepository,
DimensionContentRepositoryInterface $dimensionContentRepository,
EntityManagerInterface $entityManager
) {
$this->dimensionRepository = $dimensionRepository;
$this->dimensionContentRepository = $dimensionContentRepository;
$this->entityManager = $entityManager;
}
Expand Down Expand Up @@ -76,14 +67,9 @@ public function onUnpublish(TransitionEvent $transitionEvent): void
throw new \RuntimeException('Transition context must contain "contentRichEntity".');
}

$liveDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionInterface::STAGE_LIVE]);

$dimensionCollection = $this->dimensionRepository->findByAttributes($liveDimensionAttributes);
if (0 === \count($dimensionCollection)) {
throw new ContentNotFoundException($contentRichEntity, $liveDimensionAttributes);
}
$liveDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_LIVE]);

$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionCollection);
$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $liveDimensionAttributes);
$localizedDimensionContent = $dimensionContentCollection->getLocalizedDimensionContent();
if (!$localizedDimensionContent) {
throw new ContentNotFoundException($contentRichEntity, $liveDimensionAttributes);
Expand Down
Loading

0 comments on commit 219fbe7

Please sign in to comment.