Skip to content

Commit

Permalink
Merge branch '0.6' of github.com:sulu/SuluContentBundle into 0.x
Browse files Browse the repository at this point in the history
 Conflicts:
	Content/Infrastructure/Doctrine/MetadataLoader.php
	UPGRADE.md
  • Loading branch information
alexander-schranz committed Mar 18, 2023
2 parents b8a51de + b7b899a commit f4dfae2
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 7 deletions.
22 changes: 21 additions & 1 deletion Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Sulu\Bundle\CategoryBundle\Entity\CategoryInterface;
use Sulu\Bundle\ContactBundle\Entity\ContactInterface;
Expand Down Expand Up @@ -50,6 +51,9 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
$this->addField($metadata, 'locale', 'string', ['length' => 7, 'nullable' => true]);
$this->addField($metadata, 'ghostLocale', 'string', ['length' => 7, 'nullable' => true]);
$this->addField($metadata, 'availableLocales', 'json', ['nullable' => true]);
$this->addIndex($metadata, 'idx_dimension', ['stage', 'locale']);
$this->addIndex($metadata, 'idx_locale', ['locale']);
$this->addIndex($metadata, 'idx_stage', ['stage']);
}

if ($reflection->implementsInterface(SeoInterface::class)) {
Expand All @@ -64,7 +68,9 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void

if ($reflection->implementsInterface(TemplateInterface::class)) {
$this->addField($metadata, 'templateKey', 'string', ['length' => 32]);
$this->addField($metadata, 'templateData', 'json', ['nullable' => false]);
$this->addField($metadata, 'templateData', 'json', ['nullable' => false, 'options' => ['jsonb' => true]]);

$this->addIndex($metadata, 'idx_template_key', ['templateKey']);
}

if ($reflection->implementsInterface(ExcerptInterface::class)) {
Expand Down Expand Up @@ -109,6 +115,9 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
if ($reflection->implementsInterface(WorkflowInterface::class)) {
$this->addField($metadata, 'workflowPlace', 'string', ['length' => 32, 'nullable' => true]);
$this->addField($metadata, 'workflowPublished', 'datetime_immutable', ['nullable' => true]);

$this->addIndex($metadata, 'idx_workflow_place', ['workflowPlace']);
$this->addIndex($metadata, 'idx_workflow_published', ['workflowPublished']);
}
}

Expand Down Expand Up @@ -213,6 +222,17 @@ private function addField(ClassMetadataInfo $metadata, string $name, string $typ
], $mapping));
}

/**
* @param ClassMetadataInfo<object> $metadata
* @param string[] $fields
*/
private function addIndex(ClassMetadataInfo $metadata, string $name, array $fields): void
{
$builder = new ClassMetadataBuilder($metadata);

$builder->addIndex($fields, $name);
}

/**
* @param ClassMetadataInfo<object> $metadata
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ContentDataProviderRepository implements DataProviderRepositoryInterface
{
public const CONTENT_RICH_ENTITY_ALIAS = 'entity';
public const LOCALIZED_DIMENSION_CONTENT_ALIAS = 'localizedContent';
public const UNLOCALIZED_DIMENSION_CONTENT_ALIAS = 'unlocalizedContent';

/**
* @var ContentManagerInterface
Expand Down Expand Up @@ -404,6 +403,8 @@ protected function setSortByJoins(QueryBuilder $queryBuilder): array
*/
protected function appendRelation(QueryBuilder $queryBuilder, string $relation, array $values, string $operator, string $alias): array
{
$queryBuilder->distinct(); // TODO remove distinct and replace joins with subselect filter see: https://github.com/sulu/SuluContentBundle/pull/226

switch ($operator) {
case 'or':
return $this->appendRelationOr($queryBuilder, $relation, $values, $alias);
Expand Down Expand Up @@ -461,15 +462,13 @@ protected function createEntityIdsQueryBuilder(string $locale): QueryBuilder
: DimensionContentInterface::STAGE_LIVE;

return $this->entityManager->createQueryBuilder()
// no distinct used here else it would hurt performance of the query: https://github.com/sulu/SuluContentBundle/pull/226
// distinct only added in `appendRelation` methods where it is required
->select(self::CONTENT_RICH_ENTITY_ALIAS . '.' . $this->getEntityIdentifierFieldName() . ' as id')
->distinct()
->from($this->contentRichEntityClass, self::CONTENT_RICH_ENTITY_ALIAS)
->innerJoin(self::CONTENT_RICH_ENTITY_ALIAS . '.dimensionContents', self::LOCALIZED_DIMENSION_CONTENT_ALIAS)
->andWhere(self::LOCALIZED_DIMENSION_CONTENT_ALIAS . '.stage = (:stage)')
->andWhere(self::LOCALIZED_DIMENSION_CONTENT_ALIAS . '.locale = (:locale)')
->innerJoin(self::CONTENT_RICH_ENTITY_ALIAS . '.dimensionContents', self::UNLOCALIZED_DIMENSION_CONTENT_ALIAS)
->andWhere(self::UNLOCALIZED_DIMENSION_CONTENT_ALIAS . '.stage = (:stage)')
->andWhere(self::UNLOCALIZED_DIMENSION_CONTENT_ALIAS . '.locale IS NULL')
->setParameter('stage', $stage)
->setParameter('locale', $locale);
}
Expand Down
17 changes: 16 additions & 1 deletion Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Sulu\Component\Content\Metadata\PropertyMetadata;
use Sulu\Component\Content\Metadata\StructureMetadata;

class ContentStructureBridge implements StructureInterface
class ContentStructureBridge implements StructureInterface, RoutableStructureInterface
{
/**
* @var StructureMetadata
Expand Down Expand Up @@ -130,6 +130,21 @@ public function getController(): ?string
return $this->structure->getController();
}

/**
* @return array{
* type: string,
* value: string,
* }
*/
public function getCacheLifeTime(): array
{
/** @var array{
* type: string,
* value: string,
* } */
return $this->structure->getCacheLifetime();
}

public function getCreator(): ?int
{
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure;

use Sulu\Component\Content\Compat\RoutableStructureInterface as SuluRoutableStructureInterface;

if (interface_exists(SuluRoutableStructureInterface::class)) {
/**
* @deprecated will be removed, as soon as the ArticleBundle rises the minimum requirement of sulu to a version,
* where this interface exists
*
* @internal
*/
interface RoutableStructureInterface extends SuluRoutableStructureInterface
{
}
} else {
/**
* @deprecated will be removed, as soon as the ArticleBundle rises the minimum requirement of sulu to a version,
* where this interface exists
*
* @internal
*/
interface RoutableStructureInterface
{
/**
* twig template of template definition.
*
* @return string
*/
public function getView();

/**
* controller which renders the twig template.
*
* @return string
*/
public function getController();

/**
* cacheLifeTime of template definition.
*
* @return array{
* type: string,
* value: string,
* }
*/
public function getCacheLifeTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ public function testGetController(): void
);
}

public function testGetCacheLifeTime(): void
{
$structure = $this->prophesize(StructureMetadata::class);

$structure->getCacheLifeTime()->willReturn(['type' => 'type', 'value' => 'value']);

$structure = $this->createStructureBridge(null, $structure->reveal());

$this->assertSame(
['type' => 'type', 'value' => 'value'],
$structure->getCacheLifeTime()
);
}

public function testGetKey(): void
{
$structure = $this->prophesize(StructureMetadata::class);
Expand Down
25 changes: 25 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ The `DataMapperInterface` was changed to make it easier to set localized and unl
): void;
```

## 0.6.x

### Use jsonb for PostgreSQL json columns

This effects only PostgreSQL databases:

```sql
ALTER TABLE <your_entity>_example_dimensions ALTER COLUMN templateData SET DATA TYPE jsonb USING templateData::jsonb;
```

## 0.6.3

### Add dimension, templateKey, workflowPublished and workflowPlace indexes

Improve performance of the `*ContentDimension` tables with additional indexes for the database:

```sql
CREATE INDEX idx_dimension ON <your_entity>_content (stage, locale);
CREATE INDEX idx_locale ON <your_entity>_content (locale);
CREATE INDEX idx_stage ON <your_entity>_content (stage);
CREATE INDEX idx_template_key ON <your_entity>_content (templateKey);
CREATE INDEX idx_workflow_place ON <your_entity>_content (workflowPlace);
CREATE INDEX idx_workflow_published ON <your_entity>_content (workflowPublished);
```

## 0.6.0

### Adjusted ContentDataMapper to accept DimensionContentCollection instead of separate objects
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<directory>Tests/</directory>
<directory>vendor/</directory>
<file>.php-cs-fixer.dist.php</file>
<file>Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php</file>
</exclude>
</whitelist>
</filter>
Expand Down

0 comments on commit f4dfae2

Please sign in to comment.