WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 834f29e

Browse files
committed
Rebase 0.x
1 parent 0b31497 commit 834f29e

File tree

26 files changed

+133
-46
lines changed

26 files changed

+133
-46
lines changed

.github/workflows/test-application.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ jobs:
5252
env:
5353
SYMFONY_DEPRECATIONS_HELPER: weak
5454

55-
- php-version: '8.3'
56-
coverage: false
57-
dependency-versions: 'highest'
58-
env:
59-
SYMFONY_DEPRECATIONS_HELPER: weak
60-
6155
services:
6256
mysql:
6357
image: mysql:5.7
@@ -119,7 +113,7 @@ jobs:
119113
- name: Install and configure PHP
120114
uses: shivammathur/setup-php@v2
121115
with:
122-
php-version: 8.3
116+
php-version: 8.0
123117
extensions: ctype, iconv, mysql
124118

125119
- name: Install composer dependencies

Content/Application/ContentMerger/ContentMerger.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
1818
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
1919
use Symfony\Component\PropertyAccess\PropertyAccessor;
20-
use Webmozart\Assert\Assert;
2120

2221
class ContentMerger implements ContentMergerInterface
2322
{
@@ -42,13 +41,6 @@ public function __construct(
4241
$this->propertyAccessor = $propertyAccessor;
4342
}
4443

45-
/**
46-
* @template T of DimensionContentInterface
47-
*
48-
* @param DimensionContentCollectionInterface<T> $dimensionContentCollection
49-
*
50-
* @return T
51-
*/
5244
public function merge(DimensionContentCollectionInterface $dimensionContentCollection): DimensionContentInterface
5345
{
5446
if (!$dimensionContentCollection->count()) {
@@ -60,7 +52,6 @@ public function merge(DimensionContentCollectionInterface $dimensionContentColle
6052
foreach ($dimensionContentCollection as $dimensionContent) {
6153
if (!$mergedDimensionContent) {
6254
$contentRichEntity = $dimensionContent->getResource();
63-
/** @var T $mergedDimensionContent */
6455
$mergedDimensionContent = $contentRichEntity->createDimensionContent();
6556
$mergedDimensionContent->markAsMerged();
6657
}
@@ -78,8 +69,6 @@ public function merge(DimensionContentCollectionInterface $dimensionContentColle
7869
}
7970
}
8071

81-
Assert::notNull($mergedDimensionContent);
82-
8372
return $mergedDimensionContent;
8473
}
8574
}

Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getIgnoredAttributes(object $object): array
2828
'merged',
2929
'dimension',
3030
'resource',
31+
'version',
3132
];
3233
}
3334

@@ -40,6 +41,7 @@ public function enhance(object $object, array $normalizedData): array
4041
$normalizedData['id'] = $object->getResource()->getId();
4142
$normalizedData['locale'] = $object->getLocale();
4243
$normalizedData['stage'] = $object->getStage();
44+
$normalizedData['version'] = $object->getVersion();
4345

4446
return $normalizedData;
4547
}

Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ShadowInterface;
2222
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
2323
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;
24+
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface;
2425
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2526
use Symfony\Component\Workflow\Event\TransitionEvent;
2627

@@ -36,9 +37,17 @@ class PublishTransitionSubscriber implements EventSubscriberInterface
3637
*/
3738
private $contentCopier;
3839

39-
public function __construct(ContentCopierInterface $contentCopier)
40-
{
40+
/**
41+
* @var DimensionContentRepositoryInterface
42+
*/
43+
private $dimensionContentRepository;
44+
45+
public function __construct(
46+
ContentCopierInterface $contentCopier,
47+
DimensionContentRepositoryInterface $dimensionContentRepository
48+
) {
4149
$this->contentCopier = $contentCopier;
50+
$this->dimensionContentRepository = $dimensionContentRepository;
4251
}
4352

4453
public function onPublish(TransitionEvent $transitionEvent): void
@@ -77,6 +86,17 @@ public function onPublish(TransitionEvent $transitionEvent): void
7786
$targetDimensionAttributes = $dimensionAttributes;
7887
$targetDimensionAttributes['stage'] = DimensionContentInterface::STAGE_LIVE;
7988

89+
$publishLocales = $this->dimensionContentRepository->getLocales($contentRichEntity, $dimensionAttributes);
90+
91+
foreach ($publishLocales as $publishLocale) {
92+
$this->contentCopier->copy(
93+
$contentRichEntity,
94+
\array_merge($dimensionAttributes, ['locale' => $publishLocale]),
95+
$contentRichEntity,
96+
\array_merge($dimensionAttributes, ['locale' => $publishLocale, 'version' => time()])
97+
);
98+
}
99+
80100
$shadowLocale = $dimensionContent instanceof ShadowInterface
81101
? $dimensionContent->getShadowLocale()
82102
: null;

Content/Domain/Model/DimensionContentInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ interface DimensionContentInterface
2121
public const STAGE_DRAFT = 'draft';
2222
public const STAGE_LIVE = 'live';
2323

24+
public const DEFAULT_VERSION = 0;
25+
2426
public static function getResourceKey(): string;
2527

2628
public function getLocale(): ?string;
@@ -59,6 +61,10 @@ public function getStage(): string;
5961
*/
6062
public function setStage(string $stage): void;
6163

64+
public function setVersion(int $version): void;
65+
66+
public function getVersion(): int;
67+
6268
/**
6369
* @return T
6470
*/

Content/Domain/Model/DimensionContentTrait.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ trait DimensionContentTrait
3535
*/
3636
protected $stage = DimensionContentInterface::STAGE_DRAFT;
3737

38+
/**
39+
* @var int
40+
*/
41+
protected $version = DimensionContentInterface::DEFAULT_VERSION;
42+
3843
/**
3944
* @var bool
4045
*/
@@ -114,6 +119,16 @@ public function getStage(): string
114119
return $this->stage;
115120
}
116121

122+
public function setVersion(int $version): void
123+
{
124+
$this->version = $version;
125+
}
126+
127+
public function getVersion(): int
128+
{
129+
return $this->version;
130+
}
131+
117132
public function isMerged(): bool
118133
{
119134
return $this->isMerged;
@@ -132,6 +147,7 @@ public static function getDefaultDimensionAttributes(): array
132147
return [
133148
'locale' => null,
134149
'stage' => DimensionContentInterface::STAGE_DRAFT,
150+
'version' => DimensionContentInterface::DEFAULT_VERSION,
135151
];
136152
}
137153

Content/Domain/Model/TemplateInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public function getTemplateKey(): ?string;
2222
public function setTemplateKey(string $templateKey): void;
2323

2424
/**
25-
* @return array<string, mixed>
25+
* @return mixed[]
2626
*/
2727
public function getTemplateData(): array;
2828

2929
/**
30-
* @param array<string, mixed> $templateData
30+
* @param mixed[] $templateData
3131
*/
3232
public function setTemplateData(array $templateData): void;
3333
}

Content/Domain/Model/TemplateTrait.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait TemplateTrait
2424
private $templateKey;
2525

2626
/**
27-
* @var array<string, mixed>
27+
* @var mixed[]
2828
*/
2929
private $templateData = [];
3030

@@ -43,9 +43,6 @@ public function getTemplateData(): array
4343
return $this->templateData;
4444
}
4545

46-
/**
47-
* @param array<string, mixed> $templateData
48-
*/
4946
public function setTemplateData(array $templateData): void
5047
{
5148
$this->templateData = $templateData;

Content/Domain/Repository/DimensionContentRepositoryInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,14 @@ public function load(
3131
ContentRichEntityInterface $contentRichEntity,
3232
array $dimensionAttributes
3333
): DimensionContentCollectionInterface;
34+
35+
/**
36+
* @param mixed[] $dimensionAttributes
37+
*
38+
* @return string[]
39+
*/
40+
public function getLocales(
41+
ContentRichEntityInterface $contentRichEntity,
42+
array $dimensionAttributes
43+
): array;
3444
}

Content/Infrastructure/Doctrine/DimensionContentRepository.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function load(
6666
$queryBuilder = $this->entityManager->createQueryBuilder()
6767
->from($dimensionContentClass, 'dimensionContent')
6868
->where('dimensionContent.' . $mappingProperty . ' = :id')
69+
->andWhere('dimensionContent.version = 0')
6970
->setParameter('id', $contentRichEntity->getId());
7071

7172
$this->dimensionContentQueryEnhancer->addSelects(
@@ -84,4 +85,29 @@ public function load(
8485
$dimensionContentClass
8586
);
8687
}
88+
89+
public function getLocales(
90+
ContentRichEntityInterface $contentRichEntity,
91+
array $dimensionAttributes
92+
): array {
93+
$dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass(\get_class($contentRichEntity));
94+
$mappingProperty = $this->contentMetadataInspector->getDimensionContentPropertyName(\get_class($contentRichEntity));
95+
96+
$queryBuilder = $this->entityManager->createQueryBuilder()
97+
->from($dimensionContentClass, 'dimensionContent')
98+
->select('dimensionContent.locale')
99+
->where('IDENTITY(dimensionContent.' . $mappingProperty . ') = :id')
100+
->andWhere('dimensionContent.locale IS NOT NULL')
101+
->setParameter('id', $contentRichEntity->getId());
102+
103+
unset($dimensionAttributes['locale']);
104+
foreach ($dimensionAttributes as $key => $value) {
105+
$queryBuilder->andWhere('dimensionContent.' . $key . ' = :' . $key)
106+
->setParameter(':' . $key, $value);
107+
}
108+
109+
return \array_map(function($row) {
110+
return $row['locale'];
111+
}, $queryBuilder->getQuery()->getArrayResult());
112+
}
87113
}

0 commit comments

Comments
 (0)