From 9d5289ecf979708daea664917ae7d8e466d3a06c Mon Sep 17 00:00:00 2001 From: Catalina Sierra Zamudio Date: Thu, 19 Sep 2024 15:18:29 +0200 Subject: [PATCH 1/6] feat (DPLAN-11379) Make fields readable for api --- .../ResourceTypes/GlobalNewsResourceType.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php index 4a161fd776..d4acc0ad18 100644 --- a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php +++ b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php @@ -84,9 +84,9 @@ protected function getProperties(): GlobalContentResourceConfigBuilder $configBuilder->id->readable()->aliasedPath($this->ident); if ($this->currentUser->hasPermission('area_admin_globalnews')) { - $configBuilder->title->initializable(); - $configBuilder->description->initializable(); - $configBuilder->text->initializable(); + $configBuilder->title->initializable()->readable(); + $configBuilder->description->initializable()->readable(); + $configBuilder->text->initializable()->readable(); $configBuilder->roles ->setRelationshipType($this->resourceTypeStore->getRoleResourceType()) ->initializable(); @@ -94,8 +94,8 @@ protected function getProperties(): GlobalContentResourceConfigBuilder $configBuilder->categories ->setRelationshipType($this->resourceTypeStore->getGlobalNewsCategoryResourceType()) ->initializable(); - $configBuilder->pictureTitle->initializable(true)->aliasedPath(Paths::globalContent()->pictitle); - $configBuilder->pdfTitle->initializable(true)->aliasedPath(Paths::globalContent()->pdftitle); + $configBuilder->pictureTitle->initializable(true)->aliasedPath(Paths::globalContent()->pictitle)->readable(); + $configBuilder->pdfTitle->initializable(true)->aliasedPath(Paths::globalContent()->pdftitle)->readable(); $configBuilder->picture ->setRelationshipType($this->resourceTypeStore->getFileResourceType()) ->initializable(true, static function (GlobalContent $news, ?File $pictureFile): array { @@ -107,7 +107,7 @@ protected function getProperties(): GlobalContentResourceConfigBuilder } return []; - }); + })->readable(); $configBuilder->pdf ->setRelationshipType($this->resourceTypeStore->getFileResourceType()) ->initializable(true, static function (GlobalContent $news, ?File $pdfFile): array { @@ -119,7 +119,7 @@ protected function getProperties(): GlobalContentResourceConfigBuilder } return []; - }); + })->readable(); $configBuilder->addPostConstructorBehavior(new FixedSetBehavior( function (GlobalContent $news, EntityDataInterface $entityData): array { $news->setType(GlobalContent::TYPE_NEWS); From 99257b59ed6352a60153779b87992abe18f0d00a Mon Sep 17 00:00:00 2001 From: Catalina Sierra Zamudio Date: Thu, 19 Sep 2024 15:48:44 +0200 Subject: [PATCH 2/6] feat (DPLAN-11379) Enable categories and roles --- .../ResourceTypes/GlobalNewsCategoryResourceType.php | 2 ++ .../ResourceTypes/GlobalNewsResourceType.php | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsCategoryResourceType.php b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsCategoryResourceType.php index 56d7914e0c..31f9e3a4fd 100644 --- a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsCategoryResourceType.php +++ b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsCategoryResourceType.php @@ -19,6 +19,7 @@ /** * @template-extends DplanResourceType * + * @property-read End $name * @property-read End $deleted * @property-read End $enabled */ @@ -61,6 +62,7 @@ protected function getProperties(): array { return [ $this->createIdentifier()->readable(), + $this->createAttribute($this->name)->readable() ]; } } diff --git a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php index d4acc0ad18..8bb2fa68fc 100644 --- a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php +++ b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php @@ -89,11 +89,13 @@ protected function getProperties(): GlobalContentResourceConfigBuilder $configBuilder->text->initializable()->readable(); $configBuilder->roles ->setRelationshipType($this->resourceTypeStore->getRoleResourceType()) - ->initializable(); + ->initializable() + ->readable(); $configBuilder->enabled->initializable(); $configBuilder->categories ->setRelationshipType($this->resourceTypeStore->getGlobalNewsCategoryResourceType()) - ->initializable(); + ->initializable() + ->readable(); $configBuilder->pictureTitle->initializable(true)->aliasedPath(Paths::globalContent()->pictitle)->readable(); $configBuilder->pdfTitle->initializable(true)->aliasedPath(Paths::globalContent()->pdftitle)->readable(); $configBuilder->picture From e9e1c82247c19239c9efac25ae7b9dfb9d028174 Mon Sep 17 00:00:00 2001 From: Catalina Sierra Zamudio Date: Thu, 19 Sep 2024 17:49:41 +0200 Subject: [PATCH 3/6] feat (DPLAN-11379) Add pictureHash to display picture in FE. Remove picture in the meantime as there is not relationship with object File, instead picture is a string in the GlobalContent object --- .../GlobalContentResourceConfigBuilder.php | 2 +- .../ResourceTypes/GlobalNewsResourceType.php | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/demosplan/DemosPlanCoreBundle/ResourceConfigBuilder/GlobalContentResourceConfigBuilder.php b/demosplan/DemosPlanCoreBundle/ResourceConfigBuilder/GlobalContentResourceConfigBuilder.php index f25ac78d45..8ebbdf6b2d 100644 --- a/demosplan/DemosPlanCoreBundle/ResourceConfigBuilder/GlobalContentResourceConfigBuilder.php +++ b/demosplan/DemosPlanCoreBundle/ResourceConfigBuilder/GlobalContentResourceConfigBuilder.php @@ -23,7 +23,7 @@ /** * @property-read AttributeConfigBuilderInterface,GlobalContent> $pictureTitle * @property-read AttributeConfigBuilderInterface,GlobalContent> $pdfTitle - * @property-read ToOneRelationshipConfigBuilderInterface,OrderBySortMethodInterface,GlobalContent,File> $picture + * @property-read AttributeConfigBuilderInterface,GlobalContent> $pictureHash * @property-read ToOneRelationshipConfigBuilderInterface,OrderBySortMethodInterface,GlobalContent,File> $pdf */ class GlobalContentResourceConfigBuilder extends BaseGlobalContentResourceConfigBuilder diff --git a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php index 8bb2fa68fc..47b77c5ee0 100644 --- a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php +++ b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php @@ -98,18 +98,7 @@ protected function getProperties(): GlobalContentResourceConfigBuilder ->readable(); $configBuilder->pictureTitle->initializable(true)->aliasedPath(Paths::globalContent()->pictitle)->readable(); $configBuilder->pdfTitle->initializable(true)->aliasedPath(Paths::globalContent()->pdftitle)->readable(); - $configBuilder->picture - ->setRelationshipType($this->resourceTypeStore->getFileResourceType()) - ->initializable(true, static function (GlobalContent $news, ?File $pictureFile): array { - if (null === $pictureFile) { - $news->setPicture(''); - $news->setPictitle(''); - } else { - $news->setPicture($pictureFile->getFileString()); - } - - return []; - })->readable(); + $configBuilder->pictureHash->initializable(true)->aliasedPath(Paths::globalContent()->picture)->readable(); $configBuilder->pdf ->setRelationshipType($this->resourceTypeStore->getFileResourceType()) ->initializable(true, static function (GlobalContent $news, ?File $pdfFile): array { From 639870d412b21c040de8427c673d212538ce360c Mon Sep 17 00:00:00 2001 From: Demos-CI Date: Thu, 19 Sep 2024 15:58:00 +0000 Subject: [PATCH 4/6] style: Apply php-cs-fixer --- .../ResourceTypes/GlobalNewsCategoryResourceType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsCategoryResourceType.php b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsCategoryResourceType.php index 31f9e3a4fd..82ef49a101 100644 --- a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsCategoryResourceType.php +++ b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsCategoryResourceType.php @@ -62,7 +62,7 @@ protected function getProperties(): array { return [ $this->createIdentifier()->readable(), - $this->createAttribute($this->name)->readable() + $this->createAttribute($this->name)->readable(), ]; } } From ca32c53dd0197bbd2547ecf981e1dbc7fb41e50a Mon Sep 17 00:00:00 2001 From: Catalina Sierra Zamudio Date: Fri, 20 Sep 2024 12:14:50 +0200 Subject: [PATCH 5/6] feat (DPLAN-11379) Add pictureFile attribute to reference to entity File where pictures are stored for GlobalContent and expose it to API --- .../2024/09/Version20240920090238.php | 51 +++++++++++++++++++ .../Entity/GlobalContent.php | 7 +++ .../GlobalContentResourceConfigBuilder.php | 1 + .../ResourceTypes/GlobalNewsResourceType.php | 12 +++++ 4 files changed, 71 insertions(+) create mode 100644 demosplan/DemosPlanCoreBundle/DoctrineMigrations/2024/09/Version20240920090238.php diff --git a/demosplan/DemosPlanCoreBundle/DoctrineMigrations/2024/09/Version20240920090238.php b/demosplan/DemosPlanCoreBundle/DoctrineMigrations/2024/09/Version20240920090238.php new file mode 100644 index 0000000000..adafb87fef --- /dev/null +++ b/demosplan/DemosPlanCoreBundle/DoctrineMigrations/2024/09/Version20240920090238.php @@ -0,0 +1,51 @@ +abortIfNotMysql(); + + $this->addSql('ALTER TABLE _platform_content ADD picture_id CHAR(36) DEFAULT NULL COMMENT \'This id is used to reference to the file entity\''); + $this->addSql('ALTER TABLE _platform_content ADD CONSTRAINT FK_42348F4FEE45BDBF FOREIGN KEY (picture_id) REFERENCES _files (_f_ident) ON DELETE CASCADE'); + $this->addSql('CREATE INDEX IDX_42348F4FEE45BDBF ON _platform_content (picture_id)'); + } + + /** + * @throws Exception + */ + public function down(Schema $schema): void + { + $this->abortIfNotMysql(); + + $this->addSql('ALTER TABLE _platform_content DROP FOREIGN KEY FK_42348F4FEE45BDBF'); + $this->addSql('DROP INDEX IDX_42348F4FEE45BDBF ON _platform_content'); + $this->addSql('ALTER TABLE _platform_content DROP picture_id'); + } + + /** + * @throws Exception + */ + private function abortIfNotMysql(): void + { + $this->abortIf( + !$this->connection->getDatabasePlatform() instanceof MySqlPlatform, + "Migration can only be executed safely on 'mysql'." + ); + } +} diff --git a/demosplan/DemosPlanCoreBundle/Entity/GlobalContent.php b/demosplan/DemosPlanCoreBundle/Entity/GlobalContent.php index f235063628..3c7f83e6d9 100644 --- a/demosplan/DemosPlanCoreBundle/Entity/GlobalContent.php +++ b/demosplan/DemosPlanCoreBundle/Entity/GlobalContent.php @@ -195,6 +195,13 @@ class GlobalContent extends CoreEntity implements UuidEntityInterface, GlobalCon */ protected CustomerInterface $customer; + /** + * @ORM\ManyToOne(targetEntity="demosplan\DemosPlanCoreBundle\Entity\File", cascade={"persist"}) + * + * @ORM\JoinColumn(name="picture_id", referencedColumnName="_f_ident", onDelete="CASCADE") + */ + protected File $pictureFile; + public function __construct() { $this->roles = new ArrayCollection(); diff --git a/demosplan/DemosPlanCoreBundle/ResourceConfigBuilder/GlobalContentResourceConfigBuilder.php b/demosplan/DemosPlanCoreBundle/ResourceConfigBuilder/GlobalContentResourceConfigBuilder.php index 8ebbdf6b2d..af3023b0cc 100644 --- a/demosplan/DemosPlanCoreBundle/ResourceConfigBuilder/GlobalContentResourceConfigBuilder.php +++ b/demosplan/DemosPlanCoreBundle/ResourceConfigBuilder/GlobalContentResourceConfigBuilder.php @@ -24,6 +24,7 @@ * @property-read AttributeConfigBuilderInterface,GlobalContent> $pictureTitle * @property-read AttributeConfigBuilderInterface,GlobalContent> $pdfTitle * @property-read AttributeConfigBuilderInterface,GlobalContent> $pictureHash + * @property-read ToOneRelationshipConfigBuilderInterface,OrderBySortMethodInterface,GlobalContent,File> $pictureFile * @property-read ToOneRelationshipConfigBuilderInterface,OrderBySortMethodInterface,GlobalContent,File> $pdf */ class GlobalContentResourceConfigBuilder extends BaseGlobalContentResourceConfigBuilder diff --git a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php index 47b77c5ee0..78d8474c4c 100644 --- a/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php +++ b/demosplan/DemosPlanCoreBundle/ResourceTypes/GlobalNewsResourceType.php @@ -99,6 +99,18 @@ protected function getProperties(): GlobalContentResourceConfigBuilder $configBuilder->pictureTitle->initializable(true)->aliasedPath(Paths::globalContent()->pictitle)->readable(); $configBuilder->pdfTitle->initializable(true)->aliasedPath(Paths::globalContent()->pdftitle)->readable(); $configBuilder->pictureHash->initializable(true)->aliasedPath(Paths::globalContent()->picture)->readable(); + $configBuilder->pictureFile->setRelationshipType($this->resourceTypeStore->getFileResourceType()) + ->initializable(true, static function (GlobalContent $news, ?File $pictureFile): array { + if (null === $pictureFile) { + $news->setPicture(''); + $news->setPictitle(''); + } else { + $news->setPicture($pictureFile->getFileString()); + } + + return []; + })->readable(); + $configBuilder->pdf ->setRelationshipType($this->resourceTypeStore->getFileResourceType()) ->initializable(true, static function (GlobalContent $news, ?File $pdfFile): array { From 5ace93ba82e93d0c30612e8ef780b10b43866301 Mon Sep 17 00:00:00 2001 From: Demos-CI Date: Fri, 20 Sep 2024 10:15:36 +0000 Subject: [PATCH 6/6] style: Apply php-cs-fixer --- .../2024/09/Version20240920090238.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/demosplan/DemosPlanCoreBundle/DoctrineMigrations/2024/09/Version20240920090238.php b/demosplan/DemosPlanCoreBundle/DoctrineMigrations/2024/09/Version20240920090238.php index adafb87fef..eedcaa9301 100644 --- a/demosplan/DemosPlanCoreBundle/DoctrineMigrations/2024/09/Version20240920090238.php +++ b/demosplan/DemosPlanCoreBundle/DoctrineMigrations/2024/09/Version20240920090238.php @@ -1,4 +1,14 @@ -abortIf( - !$this->connection->getDatabasePlatform() instanceof MySqlPlatform, + !$this->connection->getDatabasePlatform() instanceof MySQLPlatform, "Migration can only be executed safely on 'mysql'." ); }