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

F dplan 11379 use jsonapi global contents #3698

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/**
* This file is part of the package demosplan.
*
* (c) 2010-present DEMOS plan GmbH, for more information see the license file.
*
* All rights reserved
*/

namespace Application\Migrations;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

class Version20240920090238 extends AbstractMigration
{
public function getDescription(): string
{
return 'refs DPLAN-11379: Adjust _platform_content to use file entity';
}

/**
* @throws Exception
*/
public function up(Schema $schema): void
{
$this->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'."
);
}
}
7 changes: 7 additions & 0 deletions demosplan/DemosPlanCoreBundle/Entity/GlobalContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
/**
* @property-read AttributeConfigBuilderInterface<ClauseFunctionInterface<bool>,GlobalContent> $pictureTitle
* @property-read AttributeConfigBuilderInterface<ClauseFunctionInterface<bool>,GlobalContent> $pdfTitle
* @property-read ToOneRelationshipConfigBuilderInterface<ClauseFunctionInterface<bool>,OrderBySortMethodInterface,GlobalContent,File> $picture
* @property-read AttributeConfigBuilderInterface<ClauseFunctionInterface<bool>,GlobalContent> $pictureHash
* @property-read ToOneRelationshipConfigBuilderInterface<ClauseFunctionInterface<bool>,OrderBySortMethodInterface,GlobalContent,File> $pictureFile
* @property-read ToOneRelationshipConfigBuilderInterface<ClauseFunctionInterface<bool>,OrderBySortMethodInterface,GlobalContent,File> $pdf
*/
class GlobalContentResourceConfigBuilder extends BaseGlobalContentResourceConfigBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/**
* @template-extends DplanResourceType<Category>
*
* @property-read End $name
* @property-read End $deleted
* @property-read End $enabled
*/
Expand Down Expand Up @@ -61,6 +62,7 @@ protected function getProperties(): array
{
return [
$this->createIdentifier()->readable(),
$this->createAttribute($this->name)->readable(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,22 @@ 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();
->initializable()
->readable();
$configBuilder->enabled->initializable();
$configBuilder->categories
->setRelationshipType($this->resourceTypeStore->getGlobalNewsCategoryResourceType())
->initializable();
$configBuilder->pictureTitle->initializable(true)->aliasedPath(Paths::globalContent()->pictitle);
$configBuilder->pdfTitle->initializable(true)->aliasedPath(Paths::globalContent()->pdftitle);
$configBuilder->picture
->setRelationshipType($this->resourceTypeStore->getFileResourceType())
->initializable()
->readable();
$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('');
Expand All @@ -107,7 +109,8 @@ protected function getProperties(): GlobalContentResourceConfigBuilder
}

return [];
});
})->readable();

$configBuilder->pdf
->setRelationshipType($this->resourceTypeStore->getFileResourceType())
->initializable(true, static function (GlobalContent $news, ?File $pdfFile): array {
Expand All @@ -119,7 +122,7 @@ protected function getProperties(): GlobalContentResourceConfigBuilder
}

return [];
});
})->readable();
$configBuilder->addPostConstructorBehavior(new FixedSetBehavior(
function (GlobalContent $news, EntityDataInterface $entityData): array {
$news->setType(GlobalContent::TYPE_NEWS);
Expand Down