-
-
Notifications
You must be signed in to change notification settings - Fork 228
FEATURE: Enable hierarchical asset collections #4160
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
Draft
Sebobo
wants to merge
7
commits into
7.3
Choose a base branch
from
task/enable-hierarchical-collections
base: 7.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f7c552
TASK: Enable hierarchical asset collections
Sebobo 65cccfe
TASK: Check circular dependency when modifying asset collection paren…
Sebobo e2c7825
TASK: Only use parent property for manipulating and traversing asset …
Sebobo 50585d3
TASK: Explicitely remove child asset collections when their parent is…
Sebobo 3395126
TASK: Adjust migration for parent collections
Sebobo 3551a54
TASK: Simplify circularHierarchy check and improve errormessage and test
Sebobo 9c3737b
TASK: Add hasParent and unsetParent methods
Sebobo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Flow\Persistence\Doctrine\Migrations; | ||
|
||
use Doctrine\DBAL\Platforms\MySqlPlatform; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20230401055019 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Adds the parent property to the AssetCollection entity.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->abortIf(!$this->connection->getDatabasePlatform() instanceof MySqlPlatform, 'Migration can only be executed safely on "mysql".'); | ||
|
||
$this->addSql('ALTER TABLE neos_media_domain_model_assetcollection ADD parent VARCHAR(40) DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE neos_media_domain_model_assetcollection ADD CONSTRAINT FK_74C770A3D8E604F FOREIGN KEY (parent) REFERENCES neos_media_domain_model_assetcollection (persistence_object_identifier) ON DELETE SET NULL'); | ||
$this->addSql('CREATE INDEX IDX_74C770A3D8E604F ON neos_media_domain_model_assetcollection (parent)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->abortIf(!$this->connection->getDatabasePlatform() instanceof MySqlPlatform, 'Migration can only be executed safely on "mysql".'); | ||
|
||
$this->addSql('ALTER TABLE neos_media_domain_model_assetcollection DROP FOREIGN KEY FK_74C770A3D8E604F'); | ||
$this->addSql('DROP INDEX IDX_74C770A3D8E604F ON neos_media_domain_model_assetcollection'); | ||
$this->addSql('ALTER TABLE neos_media_domain_model_assetcollection DROP parent'); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Neos.Media/Migrations/Postgresql/Version20230401171612.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Flow\Persistence\Doctrine\Migrations; | ||
|
||
use Doctrine\DBAL\Platforms\PostgreSQL100Platform; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20230401171612 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Adds the parent property to AssetCollections'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->abortIf(!$this->connection->getDatabasePlatform() instanceof PostgreSQL100Platform, 'Migration can only be executed safely on "postgresql".'); | ||
|
||
$this->addSql('ALTER TABLE neos_media_domain_model_assetcollection ADD parent VARCHAR(40) DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE neos_media_domain_model_assetcollection ADD CONSTRAINT FK_74C770A3D8E604F FOREIGN KEY (parent) REFERENCES neos_media_domain_model_assetcollection (persistence_object_identifier) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('CREATE INDEX IDX_74C770A3D8E604F ON neos_media_domain_model_assetcollection (parent)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->abortIf(!$this->connection->getDatabasePlatform()->getName() instanceof PostgreSQL100Platform, 'Migration can only be executed safely on "postgresql".'); | ||
|
||
$this->addSql('ALTER TABLE neos_media_domain_model_assetcollection DROP CONSTRAINT FK_74C770A3D8E604F'); | ||
$this->addSql('DROP INDEX IDX_74C770A3D8E604F'); | ||
$this->addSql('ALTER TABLE neos_media_domain_model_assetcollection DROP parent'); | ||
} | ||
} |
177 changes: 177 additions & 0 deletions
177
Neos.Media/Tests/Functional/Domain/Model/AssetCollectionTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Media\Tests\Functional\Domain\Model; | ||
|
||
/* | ||
* This file is part of the Neos.Media package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Neos\Flow\Persistence\Doctrine\PersistenceManager; | ||
use Neos\Media\Domain\Model\AssetCollection; | ||
use Neos\Media\Domain\Repository\AssetCollectionRepository; | ||
use Neos\Media\Tests\Functional\AbstractTest; | ||
|
||
class AssetCollectionTest extends AbstractTest | ||
{ | ||
/** | ||
* @var boolean | ||
*/ | ||
protected static $testablePersistenceEnabled = true; | ||
|
||
/** | ||
* @var AssetCollectionRepository | ||
*/ | ||
protected $assetCollectionRepository; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
if (!$this->persistenceManager instanceof PersistenceManager) { | ||
static::markTestSkipped('Doctrine persistence is not enabled'); | ||
} | ||
|
||
$this->assetCollectionRepository = $this->objectManager->get(AssetCollectionRepository::class); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function parentChildrenRelation(): void | ||
{ | ||
$child1 = new AssetCollection('child1'); | ||
$child2 = new AssetCollection('child2'); | ||
$parent = new AssetCollection('parent'); | ||
|
||
$child1->setParent($parent); | ||
$child2->setParent($parent); | ||
|
||
$this->assetCollectionRepository->add($parent); | ||
$this->assetCollectionRepository->add($child1); | ||
$this->assetCollectionRepository->add($child2); | ||
|
||
$this->persistenceManager->persistAll(); | ||
$this->persistenceManager->clearState(); | ||
|
||
$persistedChild = $this->assetCollectionRepository->findOneByTitle('child1'); | ||
$persistedParent = $persistedChild->getParent(); | ||
|
||
self::assertEquals('parent', $persistedParent->getTitle()); | ||
self::assertNull($persistedParent->getParent()); | ||
|
||
$children = $this->assetCollectionRepository->findByParent($parent); | ||
self::assertEquals(2, $children->count()); | ||
self::assertEquals('child1', $children->offsetGet(0)->getTitle()); | ||
self::assertEquals('child2', $children->offsetGet(1)->getTitle()); | ||
} | ||
|
||
/** | ||
* Verifies the following hierarchie throws an error: | ||
* first -> second -> third -> first | ||
* | ||
* @test | ||
*/ | ||
public function circularParentChildrenRelationThrowsErrorWhenSettingParent(): void | ||
{ | ||
$firstCollection = new AssetCollection('first'); | ||
$secondCollection = new AssetCollection('second'); | ||
$thirdCollection = new AssetCollection('third'); | ||
|
||
$secondCollection->setParent($firstCollection); | ||
$thirdCollection->setParent($secondCollection); | ||
|
||
$this->expectException(\InvalidArgumentException::class); | ||
$firstCollection->setParent($thirdCollection); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function unsettingTheParentRemovesChildFromParent(): void | ||
{ | ||
$child = new AssetCollection('child'); | ||
$parent = new AssetCollection('parent'); | ||
|
||
$child->setParent($parent); | ||
|
||
$this->assetCollectionRepository->add($parent); | ||
$this->assetCollectionRepository->add($child); | ||
|
||
$this->persistenceManager->persistAll(); | ||
$this->persistenceManager->clearState(); | ||
|
||
$persistedChild = $this->assetCollectionRepository->findOneByTitle('child'); | ||
$persistedChild->unsetParent(null); | ||
|
||
$this->assetCollectionRepository->update($persistedChild); | ||
$this->persistenceManager->persistAll(); | ||
$this->persistenceManager->clearState(); | ||
|
||
$persistedChild = $this->assetCollectionRepository->findOneByTitle('child'); | ||
$persistedParent = $this->assetCollectionRepository->findOneByTitle('parent'); | ||
|
||
$children = $this->assetCollectionRepository->findByParent($persistedParent); | ||
|
||
self::assertNull($persistedChild->getParent()); | ||
self::assertCount(0, $children); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function deletingTheParentDeletesTheChild(): void | ||
{ | ||
$child = new AssetCollection('child'); | ||
$parent = new AssetCollection('parent'); | ||
|
||
$child->setParent($parent); | ||
|
||
$this->assetCollectionRepository->add($parent); | ||
$this->assetCollectionRepository->add($child); | ||
|
||
$this->persistenceManager->persistAll(); | ||
$this->persistenceManager->clearState(); | ||
|
||
$persistedParent = $this->assetCollectionRepository->findOneByTitle('parent'); | ||
$this->assetCollectionRepository->remove($persistedParent); | ||
|
||
$this->persistenceManager->persistAll(); | ||
$this->persistenceManager->clearState(); | ||
|
||
$persistedChild = $this->assetCollectionRepository->findOneByTitle('child'); | ||
$persistedParent = $this->assetCollectionRepository->findOneByTitle('parent'); | ||
|
||
self::assertNull($persistedChild); | ||
self::assertNull($persistedParent); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function hasParentReturnsTrueIfParentIsSet(): void | ||
{ | ||
$child = new AssetCollection('child'); | ||
$parent = new AssetCollection('parent'); | ||
|
||
$child->setParent($parent); | ||
|
||
$this->assetCollectionRepository->add($parent); | ||
$this->assetCollectionRepository->add($child); | ||
|
||
$this->persistenceManager->persistAll(); | ||
$this->persistenceManager->clearState(); | ||
|
||
$persistedChild = $this->assetCollectionRepository->findOneByTitle('child'); | ||
$persistedParent = $this->assetCollectionRepository->findOneByTitle('parent'); | ||
|
||
self::assertTrue($persistedChild->hasParent()); | ||
self::assertFalse($persistedParent->hasParent()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.