Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shadow functionality to publishing process #243

Merged
merged 5 commits into from
Mar 27, 2023

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Mar 23, 2023

This implements the shadowing behaviour like discussed with @chirimoya. The data of the draft page stays as it is and when publishing a Shadow page the content from the ShadowLocale will be copied to the published page.

TODO Functional Tests

  • DE (Published: Not Shadow, Unpublished: Shadow to EN) EN Publish should change nothing
  • DE (Published: Nothing, Unpublished: Shadow to EN) EN Publish should change nothing
  • DE (Published: Shadow to EN, Unpublished: Not Shadow) EN Publish should update Live Shadow
  • DE (Published: Shadow to EN, Unpublished: Shadow to EN) DE Unpublish EN Publish should publish nothing for DE

TODO Unit Tests

  • Update PublishTransitionSubscriberTest for new cases
  • Update ContentCopierTests for new Params
  • Update UnublishTransitionSubscriberTest for new cases
  • Update ShadowDataMapperTests for new cases

@alexander-schranz alexander-schranz added the Feature New functionality not yet included in Bundle label Mar 23, 2023
@alexander-schranz alexander-schranz force-pushed the feature/shadow-handling branch 5 times, most recently from e8a891f to 9412ac3 Compare March 23, 2023 20:07
@coveralls
Copy link

coveralls commented Mar 23, 2023

Pull Request Test Coverage Report for Build 4525650416

  • 96 of 96 (100.0%) changed or added relevant lines in 10 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 4501819618: 0.0%
Covered Lines: 2503
Relevant Lines: 2503

💛 - Coveralls

@@ -60,6 +60,18 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
$this->addIndex($metadata, 'idx_stage', ['stage']);
}

if ($reflection->implementsInterface(ShadowInterface::class)) {
Copy link
Member Author

@alexander-schranz alexander-schranz Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved this to change the ordering of the columns as I think it make sense to have this columns visible first in the database table view before seo, excerpt, ...

Comment on lines +244 to +248
foreach ($views as $view) {
if ($view instanceof PreviewFormViewBuilderInterface) {
$view->setPreviewCondition('shadowOn != true');
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quickfix as the preview currently can not handle shadow feature.

@alexander-schranz alexander-schranz force-pushed the feature/shadow-handling branch 12 times, most recently from 60e7c7f to 7f12e26 Compare March 23, 2023 22:32
@alexander-schranz alexander-schranz force-pushed the feature/shadow-handling branch 2 times, most recently from 02a164e to 5d114ba Compare March 23, 2023 23:25
@alexander-schranz alexander-schranz marked this pull request as ready for review March 23, 2023 23:26
@alexander-schranz alexander-schranz force-pushed the feature/shadow-handling branch 3 times, most recently from 5a8882c to f6eefd9 Compare March 23, 2023 23:29
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is a very individual test case with different tests depending on each other I thought it most make sense to have it in an own class

Comment on lines 39 to 40
array $data = [],
array $ignoredAttributes = []
Copy link
Member Author

@alexander-schranz alexander-schranz Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While looking now again on this maybe put this together in an array $options so this interface don't is so messed up and more future proof. What do you think @Prokyonn @wachterjohannes

$contentCopier->copy(
    $contentRichEntity,
    $sourceDimensionAttributes,
    $contentRichEntity,
    $targetDimensionAttributes,
    options: [
        'data': [
            'shadowOn' => true,
            'shadowLocale' => 'de',
            'url' => '/test-de',
        ],
        'ignoredAttributes': [
            // ...
        ],
    ] 
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds okfor me 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also prefer the options parameter, the interface would be cleaner and with correct php doctypes the developer gets the same information

Copy link
Member

@wachterjohannes wachterjohannes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me the code Looks good 👍 if you want to refactor the additional arguments with options - do it! else it would be also OK for me like it is now

Comment on lines 39 to 40
array $data = [],
array $ignoredAttributes = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds okfor me 👍

@@ -26,14 +26,18 @@ interface ContentCopierInterface
* @param mixed[] $sourceDimensionAttributes
* @param ContentRichEntityInterface<T> $targetContentRichEntity
* @param mixed[] $targetDimensionAttributes
* @param mixed[] $data This data is merged with the data of the source content before set on the target content
* @param string[] $ignoredAttributes This attributes stayed untouched
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param string[] $ignoredAttributes This attributes stayed untouched
* @param string[] $ignoredAttributes These attributes stay untouched

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this to a new $options parameter as written above do you want to recheck the comment there?

@@ -42,13 +46,17 @@ public function copy(
* @param DimensionContentCollectionInterface<T> $dimensionContentCollection
* @param ContentRichEntityInterface<T> $targetContentRichEntity
* @param mixed[] $targetDimensionAttributes
* @param mixed[] $data This data is merged with the data of the source content before set on the target content
* @param string[] $ignoredAttributes This attributes stayed untouched
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param string[] $ignoredAttributes This attributes stayed untouched
* @param string[] $ignoredAttributes These attributes stay untouched

@@ -57,12 +65,16 @@ public function copyFromDimensionContentCollection(
* @param T $dimensionContent
* @param ContentRichEntityInterface<T> $targetContentRichEntity
* @param mixed[] $targetDimensionAttributes
* @param mixed[] $data This data is merged with the data of the source content before set on the target content
* @param string[] $ignoredAttributes This attributes stayed untouched
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param string[] $ignoredAttributes This attributes stayed untouched
* @param string[] $ignoredAttributes These attributes stay untouched

$name = $property->getName();

// Float are converted to ints in php array as key so we need convert it to string
if (\is_float($name)) {
$name = (string) $name;
}

if (\array_key_exists($name, $data)) {
$value = $property->isLocalized() ? $defaultLocalizedData[$name] ?? null : $defaultLocalizedData[$name] ?? null;
if (\array_key_exists($name, $data)) { // values not explicitly given need to stay untouched for e.g. for shadow pages urls
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (\array_key_exists($name, $data)) { // values not explicitly given need to stay untouched for e.g. for shadow pages urls
if (\array_key_exists($name, $data)) { // values not explicitly given need to stay untouched for e.g. shadow pages urls

Comment on lines 39 to 40
array $data = [],
array $ignoredAttributes = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also prefer the options parameter, the interface would be cleaner and with correct php doctypes the developer gets the same information

@@ -65,6 +65,7 @@
"thecodingmachine/phpstan-strict-rules": "^1.0"
},
"conflict": {
"coduo/php-matcher": "6.0.12",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conflict because of: coduo/php-matcher#463

@alexander-schranz alexander-schranz merged commit 70f3f85 into sulu:0.x Mar 27, 2023
@alexander-schranz alexander-schranz deleted the feature/shadow-handling branch March 27, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality not yet included in Bundle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants