From 5245364f1142fd1c3ba6bbf363bd3130715ae4db Mon Sep 17 00:00:00 2001 From: Florian ALEXANDRE Date: Fri, 7 Apr 2023 15:47:28 +0200 Subject: [PATCH 01/36] feat: update composer php requirements --- composer.json | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 6dfa380..2910d2a 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "almaviacx" ], "homepage": "https://github.com/Novactive/AlmaviaCXCalameoBundle", - "type": "ezplatform-bundle", + "type": "ibexa-bundle", "authors": [ { "name": "AlmaviaCX", @@ -19,15 +19,8 @@ "MIT" ], "require": { - "php": "^7.2", - "ext-json": "*", - "doctrine/cache": "^1.10", - "ezsystems/ezpublish-kernel": "^7.5", - "ezsystems/repository-forms": "^2.5", - "guzzlehttp/guzzle": "^6.0", - "jms/serializer": "^1.0", - "jms/serializer-bundle": "^2.0", - "symfony/symfony": "^3.4" + "php": "^7.4 || ^8.0", + "ext-json": "*" }, "autoload": { "psr-4": { From fe223b05500067a67a40e253e9196180fb9ede0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 26 Apr 2023 17:00:02 +0200 Subject: [PATCH 02/36] try to fix [Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound (404)] Could not find 'Persistence Field Value Converter' with identifier 'calameo_publication' --- .gitignore | 1 + composer.json | 3 +- .../EzCalameoExtension.php | 4 +-- .../EzBundle/Resources/config/fieldtypes.yml | 6 +++- .../EzBundle/Resources/config/services.yml | 2 ++ .../CalameoPublication/LegacyConverter.php | 12 +++---- .../Ez/FieldType/CalameoPublication/Type.php | 25 ++++++++------- .../Ez/FieldType/CalameoPublication/Value.php | 31 +++++-------------- 8 files changed, 40 insertions(+), 44 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61ead86 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/composer.json b/composer.json index 2910d2a..09093d7 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ ], "require": { "php": "^7.4 || ^8.0", - "ext-json": "*" + "ext-json": "*", + "ibexa/core": "^4.2" }, "autoload": { "psr-4": { diff --git a/src/bundles/EzBundle/DependencyInjection/EzCalameoExtension.php b/src/bundles/EzBundle/DependencyInjection/EzCalameoExtension.php index 7b54025..827f1a8 100644 --- a/src/bundles/EzBundle/DependencyInjection/EzCalameoExtension.php +++ b/src/bundles/EzBundle/DependencyInjection/EzCalameoExtension.php @@ -35,12 +35,12 @@ public function load(array $configs, ContainerBuilder $container): void /** * Allow an extension to prepend the extension configurations. * - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container + * @param ContainerBuilder $container */ public function prepend(ContainerBuilder $container) { $configs = [ - 'field_templates.yml' => 'ezpublish', + 'field_templates.yml' => 'ibexa', 'twig.yml' => 'twig', ]; diff --git a/src/bundles/EzBundle/Resources/config/fieldtypes.yml b/src/bundles/EzBundle/Resources/config/fieldtypes.yml index e847c8b..8e9f308 100644 --- a/src/bundles/EzBundle/Resources/config/fieldtypes.yml +++ b/src/bundles/EzBundle/Resources/config/fieldtypes.yml @@ -14,17 +14,21 @@ services: AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Type: tags: - { name: ezpublish.fieldType, alias: calameo_publication } + - { name: ibexa.field_type, alias: calameo_publication } - { name: ezpublish.fieldType.nameable, alias: calameo_publication } AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\LegacyConverter: tags: - { name: ezpublish.storageEngine.legacy.converter, alias: calameo_publication } + - { name: ibexa.field_type.storage.legacy.converter, alias: calameo_publication } AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\FieldStorage: tags: - { name: ezpublish.fieldType.externalStorageHandler, alias: calameo_publication } + - { name: ibexa.field_type.storage.external.handler, alias: calameo_publication } almaviacx.calameo.fieldtype.indexable.calameo_publication: - class: "%ezpublish.fieldType.indexable.unindexed.class%" + class: Ibexa\Core\FieldType\Unindexed tags: - { name: ezpublish.fieldType.indexable, alias: calameo_publication } + - { name: ibexa.field_type.indexable, alias: calameo_publication } diff --git a/src/bundles/EzBundle/Resources/config/services.yml b/src/bundles/EzBundle/Resources/config/services.yml index b568d8d..82f2a1f 100644 --- a/src/bundles/EzBundle/Resources/config/services.yml +++ b/src/bundles/EzBundle/Resources/config/services.yml @@ -15,6 +15,8 @@ services: tags: - { name: ez.fieldFormMapper.definition, fieldType: calameo_publication } - { name: ez.fieldFormMapper.value, fieldType: calameo_publication } + - { name: ibexa.admin_ui.field_type.form.mapper.definition, fieldType: calameo_publication } + - { name: ibexa.admin_ui.field_type.form.mapper.value, fieldType: calameo_publication } AlmaviaCX\Calameo\Ez\Form\Type\FieldType\CalameoPublicationFieldType: diff --git a/src/lib/Ez/FieldType/CalameoPublication/LegacyConverter.php b/src/lib/Ez/FieldType/CalameoPublication/LegacyConverter.php index 557e4ef..145d7ac 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/LegacyConverter.php +++ b/src/lib/Ez/FieldType/CalameoPublication/LegacyConverter.php @@ -12,11 +12,11 @@ namespace AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication; -use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter; -use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition; -use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue; -use eZ\Publish\SPI\Persistence\Content\FieldValue; -use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition; +use Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter; +use Ibexa\Core\Persistence\Legacy\Content\StorageFieldDefinition; +use Ibexa\Core\Persistence\Legacy\Content\StorageFieldValue; +use Ibexa\Contracts\Core\Persistence\Content\FieldValue; +use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition; class LegacyConverter implements Converter { @@ -42,7 +42,7 @@ public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefin ]; } - public function getIndexColumn() + public function getIndexColumn(): string { return 'sort_key_string'; } diff --git a/src/lib/Ez/FieldType/CalameoPublication/Type.php b/src/lib/Ez/FieldType/CalameoPublication/Type.php index ef21dde..ee9e318 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Type.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Type.php @@ -19,8 +19,8 @@ use eZ\Publish\Core\FieldType\ValidationError; use eZ\Publish\SPI\FieldType\Nameable; use eZ\Publish\SPI\FieldType\Value as SPIValue; -use eZ\Publish\Core\FieldType\Value as BaseValue; use eZ\Publish\SPI\Persistence\Content\FieldValue as PersistenceValue; +use Ibexa\Contracts\Core\FieldType\Value as BaseValue; use RuntimeException; class Type extends FieldType @@ -35,7 +35,7 @@ class Type extends FieldType /** * @inheritDoc */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings($fieldSettings): array { $validationErrors = []; @@ -99,23 +99,26 @@ protected function checkValueStructure(BaseValue $value) } } - public function getFieldTypeIdentifier() + public function getFieldTypeIdentifier(): string { return "calameo_publication"; } /** - * @param Value $value - * @return string|void + * @param BaseValue $value + * @param FieldDefinition $fieldDefinition + * @param string $languageCode + * @return string */ - public function getName(SPIValue $value) + public function getName(BaseValue $value, FieldDefinition $fieldDefinition, string $languageCode): string { + // return (string)$value->text; throw new RuntimeException( 'Name generation provided via NameableField set via "ezpublish.fieldType.nameable" service tag' ); } - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -133,7 +136,7 @@ public function fromHash($hash) * @param Value $value * @return array */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -147,9 +150,9 @@ public function toHash(SPIValue $value) /** * @param Value $value - * @return string|null + * @return false */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(BaseValue $value): bool { return false; } @@ -183,6 +186,6 @@ public function fromPersistenceValue(PersistenceValue $fieldValue): Value return $this->getEmptyValue(); } - return new Value($fieldValue->externalData ?? []); + return new Value($fieldValue->externalData); } } diff --git a/src/lib/Ez/FieldType/CalameoPublication/Value.php b/src/lib/Ez/FieldType/CalameoPublication/Value.php index 51882e4..2e5c21b 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Value.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Value.php @@ -13,39 +13,24 @@ namespace AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication; use AlmaviaCX\Calameo\API\Value\Publication; -use eZ\Publish\Core\FieldType\Value as BaseValue; +use Closure; +use Ibexa\Core\FieldType\Value as BaseValue; class Value extends BaseValue { - /** - * @var string|null - */ - public $publicationId; - - /** - * @var int|null - */ - public $folderId; - + public ?string $publicationId; + public ?int $folderId; /** * Input file URI, as a path to a file on a disk. * * @var string|null */ - public $inputUri; - - /** - * @var \Closure - */ - public $publicationLoader; - - /** @var Publication|null */ - protected $publication; + public ?string $inputUri; + public Closure $publicationLoader; + protected ?Publication $publication; /** * Returns a string representation of the field value. - * - * @return string */ public function __toString(): string { @@ -63,6 +48,6 @@ public function __get($property) $this->publication = $loader(); } } - return parent::__get($property); // TODO: Change the autogenerated stub + return parent::__get($property); } } From 01b7fce7571b722cff01b28651ad4000187cd5a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 26 Apr 2023 17:47:16 +0200 Subject: [PATCH 03/36] try to fix [Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound (404)] Could not find 'Persistence Field Value Converter' with identifier 'calameo_publication' --- .../EzBundle/Resources/config/fieldtypes.yml | 1 - .../CalameoPublication/FieldStorage.php | 22 +++++-------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/bundles/EzBundle/Resources/config/fieldtypes.yml b/src/bundles/EzBundle/Resources/config/fieldtypes.yml index 8e9f308..b094c64 100644 --- a/src/bundles/EzBundle/Resources/config/fieldtypes.yml +++ b/src/bundles/EzBundle/Resources/config/fieldtypes.yml @@ -15,7 +15,6 @@ services: tags: - { name: ezpublish.fieldType, alias: calameo_publication } - { name: ibexa.field_type, alias: calameo_publication } - - { name: ezpublish.fieldType.nameable, alias: calameo_publication } AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\LegacyConverter: tags: diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index 60ac511..0e6401d 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -16,31 +16,21 @@ use AlmaviaCX\Calameo\API\Service\PublishingService; use AlmaviaCX\Calameo\API\Value\Publication; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; -use AlmaviaCX\Calameo\Exception\NotImplementedException; -use AlmaviaCX\Calameo\Exception\Response\ApiResponseException; use AlmaviaCX\Calameo\Exception\Response\UnknownBookIDException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Gateway\DoctrineStorage; +use eZ\Publish\SPI\FieldType\FieldStorage as FieldStorageInterface; use eZ\Publish\SPI\Persistence\Content\Field; use eZ\Publish\SPI\Persistence\Content\VersionInfo; -use eZ\Publish\SPI\FieldType\FieldStorage as FieldStorageInterface; use GuzzleHttp\Exception\GuzzleException; use Psr\Log\LoggerInterface; use SplFileInfo; -use Symfony\Component\HttpFoundation\File\UploadedFile; class FieldStorage implements FieldStorageInterface { - /** @var PublicationRepository */ - public $publicationRepository; - - /** @var PublishingService */ - public $publishingService; - - /** @var DoctrineStorage */ - public $gateway; - - /** @var LoggerInterface */ - public $logger; + public PublicationRepository $publicationRepository; + public PublishingService $publishingService; + public DoctrineStorage $gateway; + public LoggerInterface $logger; /** * @param PublicationRepository $publicationRepository @@ -68,7 +58,7 @@ public function __construct( * @throws ApiResponseErrorException * @throws GuzzleException */ - public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context) + public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context): bool { $inputUri = $field->value->externalData['inputUri'] ?? null; if ($inputUri) { From 7c314c7e326bf3bb81e8e505f2d499a5843805bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 27 Apr 2023 18:06:48 +0200 Subject: [PATCH 04/36] try to fix --- composer.json | 10 +++- .../APIBundle/Resources/config/services.yml | 8 ++- src/lib/API/Gateway/AbstractGateway.php | 27 +++------- src/lib/API/HttpClient.php | 14 ++--- src/lib/API/Repository/AccountRepository.php | 7 +-- src/lib/API/Repository/FolderRepository.php | 7 +-- .../API/Repository/PublicationRepository.php | 8 +-- src/lib/API/Serializer.php | 7 +-- src/lib/API/Service/PublishingService.php | 7 +-- src/lib/API/Value/ContentList.php | 6 +-- src/lib/API/Value/Folder.php | 18 +++---- src/lib/API/Value/FolderList.php | 2 +- src/lib/API/Value/Publication.php | 50 ++++++++--------- src/lib/API/Value/PublicationList.php | 2 +- src/lib/API/Value/Response/Error.php | 4 +- src/lib/API/Value/Response/Response.php | 12 ++--- src/lib/Exception/ExceptionThrower.php | 2 +- .../CalameoPublication/FieldStorage.php | 22 +++----- .../CalameoPublication/FormMapper.php | 22 +++----- .../Gateway/DoctrineStorage.php | 54 ++++++++++--------- .../Ez/FieldType/CalameoPublication/Type.php | 16 +++--- .../CalameoPublication/ValueTransformer.php | 24 +++------ 22 files changed, 138 insertions(+), 191 deletions(-) diff --git a/composer.json b/composer.json index 09093d7..6a7b6cc 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,12 @@ "MIT" ], "require": { + "ext-pdo": "*", "php": "^7.4 || ^8.0", "ext-json": "*", - "ibexa/core": "^4.2" + "ibexa/core": "^4.2", + "jms/serializer": "^3.5", + "jms/serializer-bundle": "^3.5" }, "autoload": { "psr-4": { @@ -40,6 +43,9 @@ "phpunit/phpunit": "^9.5" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": true + } } } diff --git a/src/bundles/APIBundle/Resources/config/services.yml b/src/bundles/APIBundle/Resources/config/services.yml index e0a1eba..a7ee9f5 100644 --- a/src/bundles/APIBundle/Resources/config/services.yml +++ b/src/bundles/APIBundle/Resources/config/services.yml @@ -21,8 +21,8 @@ services: $config: "%almaviacx.calameo.http_client.config%" AlmaviaCX\Calameo\API\Serializer: - arguments: - $baseSerializer: "@jms_serializer" +# arguments: +# $baseSerializer: "@jms_serializer" AlmaviaCX\Calameo\API\Gateway\: resource: "../../../../lib/API/Gateway/*" @@ -32,3 +32,7 @@ services: AlmaviaCX\Calameo\API\Service\: resource: "../../../../lib/API/Service/*" + + AlmaviaCX\Calameo\Exception\ExceptionThrower: + + JMS\Serializer\Serializer: diff --git a/src/lib/API/Gateway/AbstractGateway.php b/src/lib/API/Gateway/AbstractGateway.php index ae4cf31..ce61b37 100644 --- a/src/lib/API/Gateway/AbstractGateway.php +++ b/src/lib/API/Gateway/AbstractGateway.php @@ -21,23 +21,10 @@ abstract class AbstractGateway { + protected HttpClient $client; + protected Serializer $serializer; + protected ExceptionThrower $exceptionThrower; - /** @var HttpClient */ - protected $client; - - /** @var Serializer */ - protected $serializer; - - /** @var ExceptionThrower */ - protected $exceptionThrower; - - /** - * AbstractGateway constructor. - * - * @param HttpClient $client - * @param Serializer $serializer - * @param ExceptionThrower $exceptionThrower - */ public function __construct( HttpClient $client, Serializer $serializer, @@ -49,11 +36,11 @@ public function __construct( } /** - * @param string $action + * @param string $action * @param string|null $responseContentType - * @param array $requestParameters - * @param string $method - * + * @param array $requestParameters + * @param string $method + * @param array $options * @return Response * @throws ApiResponseErrorException * @throws GuzzleException diff --git a/src/lib/API/HttpClient.php b/src/lib/API/HttpClient.php index 368fbe2..11201e4 100644 --- a/src/lib/API/HttpClient.php +++ b/src/lib/API/HttpClient.php @@ -20,24 +20,20 @@ class HttpClient extends Client { /** * Calameo API Key - * - * @var string */ - protected $APIKey; + protected ?string $APIKey; /** * CalameoAPI Secret - * - * @var string */ - protected $APISecret; + protected ?string $APISecret; /** * HttpClient constructor. * - * @param string $APIKey - * @param string $APISecret - * @param array $config + * @param string|null $APIKey + * @param string|null $APISecret + * @param array $config */ public function __construct(?string $APIKey, ?string $APISecret, array $config = []) { diff --git a/src/lib/API/Repository/AccountRepository.php b/src/lib/API/Repository/AccountRepository.php index 4f193b2..f6f9c0e 100644 --- a/src/lib/API/Repository/AccountRepository.php +++ b/src/lib/API/Repository/AccountRepository.php @@ -21,13 +21,8 @@ class AccountRepository { - /** @var AccountGateway */ - protected $gateway; + protected AccountGateway $gateway; - /** - * AccountRepository constructor. - * @param AccountGateway $gateway - */ public function __construct(AccountGateway $gateway) { $this->gateway = $gateway; diff --git a/src/lib/API/Repository/FolderRepository.php b/src/lib/API/Repository/FolderRepository.php index 6ccd6d7..e31d2de 100644 --- a/src/lib/API/Repository/FolderRepository.php +++ b/src/lib/API/Repository/FolderRepository.php @@ -22,13 +22,8 @@ class FolderRepository { - /** @var FolderGateway */ - protected $gateway; + protected FolderGateway $gateway; - /** - * SubscriptionRepository constructor. - * @param FolderGateway $gateway - */ public function __construct(FolderGateway $gateway) { $this->gateway = $gateway; diff --git a/src/lib/API/Repository/PublicationRepository.php b/src/lib/API/Repository/PublicationRepository.php index d06dc09..8377375 100644 --- a/src/lib/API/Repository/PublicationRepository.php +++ b/src/lib/API/Repository/PublicationRepository.php @@ -19,14 +19,8 @@ class PublicationRepository { + protected PublicationGateway $gateway; - /** @var PublicationGateway */ - protected $gateway; - - /** - * PublicationRepository constructor. - * @param PublicationGateway $gateway - */ public function __construct(PublicationGateway $gateway) { $this->gateway = $gateway; diff --git a/src/lib/API/Serializer.php b/src/lib/API/Serializer.php index 8c07694..0e8109f 100644 --- a/src/lib/API/Serializer.php +++ b/src/lib/API/Serializer.php @@ -17,13 +17,8 @@ class Serializer { - /** @var \JMS\Serializer\Serializer */ - protected $baseSerializer; + protected \JMS\Serializer\Serializer $baseSerializer; - /** - * Serializer constructor. - * @param \JMS\Serializer\Serializer $baseSerializer - */ public function __construct(\JMS\Serializer\Serializer $baseSerializer) { $this->baseSerializer = $baseSerializer; diff --git a/src/lib/API/Service/PublishingService.php b/src/lib/API/Service/PublishingService.php index 8f05dc5..bfc6534 100644 --- a/src/lib/API/Service/PublishingService.php +++ b/src/lib/API/Service/PublishingService.php @@ -21,13 +21,8 @@ class PublishingService { - /** @var UploadGateway */ - protected $gateway; + protected UploadGateway $gateway; - /** - * PublishingService constructor. - * @param UploadGateway $gateway - */ public function __construct(UploadGateway $gateway) { $this->gateway = $gateway; diff --git a/src/lib/API/Value/ContentList.php b/src/lib/API/Value/ContentList.php index 2d91ea4..d493e1d 100644 --- a/src/lib/API/Value/ContentList.php +++ b/src/lib/API/Value/ContentList.php @@ -22,17 +22,17 @@ abstract class ContentList extends ResponseContent * @var int * @Serializer\Type("int") */ - public $total; + public int $total; /** * @var int * @Serializer\Type("int") */ - public $start; + public int $start; /** * @var int * @Serializer\Type("int") */ - public $step; + public int $step; } diff --git a/src/lib/API/Value/Folder.php b/src/lib/API/Value/Folder.php index 2cab44d..6c5d7cf 100644 --- a/src/lib/API/Value/Folder.php +++ b/src/lib/API/Value/Folder.php @@ -33,7 +33,7 @@ class Folder extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("ID") */ - public $id; + public int $id; /** * Unique identifying key for the account of the folder @@ -41,7 +41,7 @@ class Folder extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("AccountID") */ - public $accountId; + public int $accountId; /** * Title of the folder @@ -49,7 +49,7 @@ class Folder extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("Name") */ - public $name; + public string $name; /** * Description of the folder @@ -57,7 +57,7 @@ class Folder extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("Description") */ - public $description; + public string $description; /** * Available publications inside the folder @@ -65,7 +65,7 @@ class Folder extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Books") */ - public $books; + public int $books; /** * Available subscribers inside the folder (only returned for your account's folder) @@ -73,7 +73,7 @@ class Folder extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Subscribers") */ - public $subscribers; + public int $subscribers; /** * Date of the folder's creation @@ -81,7 +81,7 @@ class Folder extends ResponseContent * @Serializer\Type("DateTime<'Y-m-d H:i:s'>") * @Serializer\SerializedName("Creation") */ - public $creation; + public DateTime $creation; /** * Date of the folder's last modification @@ -89,7 +89,7 @@ class Folder extends ResponseContent * @Serializer\Type("DateTime<'Y-m-d H:i:s'>") * @Serializer\SerializedName("Modification") */ - public $modification; + public DateTime $modification; /** * Absolute URL for the folder's overview @@ -97,5 +97,5 @@ class Folder extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("PublicUrl") */ - public $publicUrl; + public string $publicUrl; } diff --git a/src/lib/API/Value/FolderList.php b/src/lib/API/Value/FolderList.php index 001442c..ae12909 100644 --- a/src/lib/API/Value/FolderList.php +++ b/src/lib/API/Value/FolderList.php @@ -20,5 +20,5 @@ class FolderList extends ContentList * @var Folder[] * @Serializer\Type("array") */ - public $items; + public array $items; } diff --git a/src/lib/API/Value/Publication.php b/src/lib/API/Value/Publication.php index fcbb876..d05df1c 100644 --- a/src/lib/API/Value/Publication.php +++ b/src/lib/API/Value/Publication.php @@ -56,7 +56,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("ID") */ - public $id; + public string $id; /** * Publication's owner account ID (should be your account ID) @@ -65,7 +65,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("AccountID") */ - public $accountId; + public int $accountId; /** * Publication's owner subscription ID @@ -74,7 +74,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("SubscriptionID") */ - public $folderId; + public int $folderId; /** * Title of the publication @@ -83,7 +83,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("Name") */ - public $name; + public string $name; /** * Description of the publication @@ -92,7 +92,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("Description") */ - public $description; + public string $description; /** * Conversion status of the publication. @@ -106,7 +106,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("Status") */ - public $status; + public string $status; /** * Sends 1 if the publication is private and 0 if not @@ -115,7 +115,7 @@ class Publication extends ResponseContent * @Serializer\Type("bool") * @Serializer\SerializedName("IsPrivate") */ - public $isPrivate; + public bool $isPrivate; /** * Authentication parameter for private URLs (authid) @@ -124,7 +124,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("AuthID") */ - public $authId; + public string $authId; /** * Sends 1 if the publication allows access to the miniCalaméo and 0 if not @@ -133,7 +133,7 @@ class Publication extends ResponseContent * @Serializer\Type("bool") * @Serializer\SerializedName("AllowMini") */ - public $allowMini; + public bool $allowMini; /** * Number of pages of the publication @@ -142,7 +142,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Pages") */ - public $pages; + public int $pages; /** * Width of a page of the publication @@ -151,7 +151,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Width") */ - public $width; + public int $width; /** * Height of a page of the publication @@ -160,7 +160,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Height") */ - public $height; + public int $height; /** * Number of views of the publication @@ -169,7 +169,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Views") */ - public $views; + public int $views; /** * Number of downloads of the publication @@ -178,7 +178,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Downloads") */ - public $downloads; + public int $downloads; /** * Number of comments of the publication @@ -187,7 +187,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Comments") */ - public $comments; + public int $comments; /** * Number of favorites from the publication @@ -196,7 +196,7 @@ class Publication extends ResponseContent * @Serializer\Type("int") * @Serializer\SerializedName("Favorites") */ - public $favorites; + public int $favorites; /** * Reference date of the publication @@ -206,7 +206,7 @@ class Publication extends ResponseContent * @Serializer\SerializedName("Date") * @Serializer\Accessor(setter="setDate") */ - public $date; + public DateTime $date; /** * Date of creation of the publication * @@ -214,7 +214,7 @@ class Publication extends ResponseContent * @Serializer\Type("DateTime<'Y-m-d H:i:s'>") * @Serializer\SerializedName("Creation") */ - public $creation; + public DateTime $creation; /** * Scheduled date of the publication (UTC) * @@ -222,7 +222,7 @@ class Publication extends ResponseContent * @Serializer\Type("DateTime<'Y-m-d H:i:s'>") * @Serializer\SerializedName("Publication") */ - public $publication; + public DateTime $publication; /** * Date of the last modification of the publication * @@ -230,7 +230,7 @@ class Publication extends ResponseContent * @Serializer\Type("DateTime<'Y-m-d H:i:s'>") * @Serializer\SerializedName("Modification") */ - public $modification; + public DateTime $modification; /** * Absolute URL for the publication's larger cover * @@ -238,7 +238,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("PosterUrl") */ - public $posterUrl; + public string $posterUrl; /** * Absolute URL for the publication's cover * @@ -246,7 +246,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("PictureUrl") */ - public $pictureUrl; + public string $pictureUrl; /** * Absolute URL for the publication's thumbnail * @@ -254,7 +254,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("ThumbUrl") */ - public $thumbUrl; + public string $thumbUrl; /** * Absolute URL for the publication's overview * @@ -262,7 +262,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("PublicUrl") */ - public $publicUrl; + public string $publicUrl; /** * Absolute URL for the publication's reading page * @@ -270,7 +270,7 @@ class Publication extends ResponseContent * @Serializer\Type("string") * @Serializer\SerializedName("ViewUrl") */ - public $viewUrl; + public string $viewUrl; /** * @param DateTime $date diff --git a/src/lib/API/Value/PublicationList.php b/src/lib/API/Value/PublicationList.php index e20d6f2..6b5ebcc 100644 --- a/src/lib/API/Value/PublicationList.php +++ b/src/lib/API/Value/PublicationList.php @@ -20,5 +20,5 @@ class PublicationList extends ContentList * @var Publication[] * @Serializer\Type("array") */ - public $items; + public array $items; } diff --git a/src/lib/API/Value/Response/Error.php b/src/lib/API/Value/Response/Error.php index 78ae266..b85686d 100644 --- a/src/lib/API/Value/Response/Error.php +++ b/src/lib/API/Value/Response/Error.php @@ -20,11 +20,11 @@ class Error * @var int * @Serializer\Type("int") */ - public $code; + public int $code; /** * @var string * @Serializer\Type("string") */ - public $message; + public string $message; } diff --git a/src/lib/API/Value/Response/Response.php b/src/lib/API/Value/Response/Response.php index dce38b0..f8baa92 100644 --- a/src/lib/API/Value/Response/Response.php +++ b/src/lib/API/Value/Response/Response.php @@ -23,35 +23,35 @@ class Response * @var string * @Serializer\Type("string") */ - public $status; + public string $status; /** * @var int * @Serializer\Type("int") */ - public $version; + public int $version; /** * @var string * @Serializer\Type("string") */ - public $requestid; + public string $requestid; /** * @var int * @Serializer\Type("int") */ - public $requests; + public int $requests; /** * @var Error|null * @Serializer\Type("AlmaviaCX\Calameo\API\Value\Response\Error") */ - public $error; + public ?Error $error; /** * @var ResponseContent * @Serializer\Type("AlmaviaCX\Calameo\API\Value\Response\ResponseContent") */ - public $content; + public ResponseContent $content; } diff --git a/src/lib/Exception/ExceptionThrower.php b/src/lib/Exception/ExceptionThrower.php index 7f64c61..e68b089 100644 --- a/src/lib/Exception/ExceptionThrower.php +++ b/src/lib/Exception/ExceptionThrower.php @@ -13,7 +13,7 @@ class ExceptionThrower { - private $exceptionsByCode = [ + private array $exceptionsByCode = [ 99 => Response\TooManyRequestsException::class, 101 => Response\InvalidSignatureException::class, 102 => Response\InvalidEndpointException::class, diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index 0e6401d..a48d796 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -18,9 +18,9 @@ use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use AlmaviaCX\Calameo\Exception\Response\UnknownBookIDException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Gateway\DoctrineStorage; -use eZ\Publish\SPI\FieldType\FieldStorage as FieldStorageInterface; -use eZ\Publish\SPI\Persistence\Content\Field; -use eZ\Publish\SPI\Persistence\Content\VersionInfo; +use Ibexa\Contracts\Core\FieldType\FieldStorage as FieldStorageInterface; +use Ibexa\Contracts\Core\Persistence\Content\Field; +use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; use GuzzleHttp\Exception\GuzzleException; use Psr\Log\LoggerInterface; use SplFileInfo; @@ -118,7 +118,8 @@ public function getFieldData(VersionInfo $versionInfo, Field $field, array $cont * @param VersionInfo $versionInfo * @param array $fieldIds * @param array $context - * @return bool|void + * @return void + * @throws GuzzleException */ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context): void { @@ -155,23 +156,14 @@ public function hasFieldData(): bool * @param VersionInfo $versionInfo * @param Field $field * @param array $context - * @return \eZ\Publish\SPI\Search\Field[]|void + * @return \Ibexa\Contracts\Core\Search\Field[]|void */ public function getIndexData(VersionInfo $versionInfo, Field $field, array $context) { } - public function copyLegacyField(VersionInfo $versionInfo, Field $field, Field $originalField, array $context) + public function copyLegacyField(VersionInfo $versionInfo, Field $field, Field $originalField, array $context): bool { -// if ($field->id !== $originalField->id) { -// var_dump([ -// $versionInfo, -// $field, -// $originalField, -// $context -// ]); -// die; -// } if ($originalField->value->externalData === null) { return false; } diff --git a/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php b/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php index 958284c..507bba1 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php @@ -15,30 +15,21 @@ use AlmaviaCX\Calameo\API\Repository\AccountRepository; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use AlmaviaCX\Calameo\Ez\Form\Type\FieldType\CalameoPublicationFieldType; -use eZ\Publish\API\Repository\FieldTypeService; -use eZ\Publish\Core\FieldType\BinaryFile\Value; +use Ibexa\Contracts\Core\Repository\FieldTypeService; +use Ibexa\AdminUi\Form\Data\FieldDefinitionData; use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface; use EzSystems\RepositoryForms\Data\Content\FieldData; -use EzSystems\RepositoryForms\Data\FieldDefinitionData; -use EzSystems\RepositoryForms\FieldType\DataTransformer\BinaryFileValueTransformer; use EzSystems\RepositoryForms\FieldType\FieldDefinitionFormMapperInterface; use EzSystems\RepositoryForms\FieldType\FieldValueFormMapperInterface; -use EzSystems\RepositoryForms\Form\Type\FieldType\BinaryFileFieldType; -use GuzzleHttp\Exception\GuzzleException; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class FormMapper implements FieldValueFormMapperInterface, FieldDefinitionFormMapperInterface { - /** @var FieldTypeService */ - protected $fieldTypeService; - - /** @var AccountRepository */ - protected $accountRepository; - - /** @var NotificationHandlerInterface */ - protected $notificationHandler; + protected FieldTypeService $fieldTypeService; + protected AccountRepository $accountRepository; + protected NotificationHandlerInterface $notificationHandler; /** * @param FieldTypeService $fieldTypeService @@ -55,7 +46,8 @@ public function __construct( $this->notificationHandler = $notificationHandler; } - public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data) + // f + public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { $folderChoices = []; $offset = 0; diff --git a/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php b/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php index a31bfe3..6668902 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php @@ -13,17 +13,17 @@ namespace AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Gateway; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Query\QueryBuilder; -use eZ\Publish\SPI\FieldType\StorageGateway; -use eZ\Publish\SPI\Persistence\Content\Field; -use eZ\Publish\SPI\Persistence\Content\VersionInfo; +use Ibexa\Contracts\Core\FieldType\StorageGateway; +use Ibexa\Contracts\Core\Persistence\Content\Field; +use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; use PDO; class DoctrineStorage extends StorageGateway { - /** @var Connection */ - protected $connection; + protected Connection $connection; /** * DoctrineStorage constructor. @@ -37,10 +37,11 @@ public function __construct(Connection $connection) /** * Store the file reference in $field for $versionNo. * - * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $versionInfo - * @param \eZ\Publish\SPI\Persistence\Content\Field $field + * @param VersionInfo $versionInfo + * @param Field $field * * @return bool + * @throws Exception */ public function storePublicationReference(VersionInfo $versionInfo, Field $field) { @@ -62,9 +63,9 @@ public function storePublicationReference(VersionInfo $versionInfo, Field $field * add additional columns to be set in the database. Please do not forget * to call the parent when overwriting this method. * - * @param \Doctrine\DBAL\Query\QueryBuilder $queryBuilder - * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $versionInfo - * @param \eZ\Publish\SPI\Persistence\Content\Field $field + * @param QueryBuilder $queryBuilder + * @param VersionInfo $versionInfo + * @param Field $field */ protected function setInsertColumns(QueryBuilder $queryBuilder, VersionInfo $versionInfo, Field $field) { @@ -81,9 +82,9 @@ protected function setInsertColumns(QueryBuilder $queryBuilder, VersionInfo $ver } /** - * @param \Doctrine\DBAL\Query\QueryBuilder $queryBuilder - * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $versionInfo - * @param \eZ\Publish\SPI\Persistence\Content\Field $field + * @param QueryBuilder $queryBuilder + * @param VersionInfo $versionInfo + * @param Field $field */ protected function setUpdateColumns(QueryBuilder $queryBuilder, VersionInfo $versionInfo, Field $field) { @@ -100,8 +101,9 @@ protected function setUpdateColumns(QueryBuilder $queryBuilder, VersionInfo $ver } /** - * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $versionInfo - * @param \eZ\Publish\SPI\Persistence\Content\Field $field + * @param VersionInfo $versionInfo + * @param Field $field + * @throws Exception */ protected function updateFieldData(VersionInfo $versionInfo, Field $field) { @@ -132,8 +134,9 @@ protected function updateFieldData(VersionInfo $versionInfo, Field $field) } /** - * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $versionInfo - * @param \eZ\Publish\SPI\Persistence\Content\Field $field + * @param VersionInfo $versionInfo + * @param Field $field + * @throws Exception */ protected function storeNewFieldData(VersionInfo $versionInfo, Field $field) { @@ -155,7 +158,7 @@ protected function storeNewFieldData(VersionInfo $versionInfo, Field $field) * * @return mixed */ - protected function castToPropertyValue($value, $columnName) + protected function castToPropertyValue($value, string $columnName) { $propertyMap = $this->getPropertyMapping(); $castFunction = $propertyMap[$columnName]['cast']; @@ -170,7 +173,7 @@ protected function castToPropertyValue($value, $columnName) * add additional columns to be fetched from the database. Please do not * forget to call the parent when overwriting this method. * - * @param \Doctrine\DBAL\Query\QueryBuilder $queryBuilder + * @param QueryBuilder $queryBuilder * @param int $fieldId * @param int $versionNo */ @@ -189,8 +192,9 @@ protected function setFetchColumns(QueryBuilder $queryBuilder, $fieldId, $versio * @param int $versionNo * * @return array|null + * @throws Exception */ - public function getPublicationReferenceData(int $fieldId, int $versionNo) + public function getPublicationReferenceData(int $fieldId, int $versionNo): ?array { $selectQuery = $this->connection->createQueryBuilder(); @@ -236,8 +240,9 @@ public function getPublicationReferenceData(int $fieldId, int $versionNo) * @param array $fieldIds * * @return array + * @throws Exception */ - public function getReferencedPublications(array $fieldIds) + public function getReferencedPublications(array $fieldIds): array { if (empty($fieldIds)) { return []; @@ -274,7 +279,7 @@ public function getReferencedPublications(array $fieldIds) * * @return string */ - protected function toPropertyName($columnName) + protected function toPropertyName(string $columnName): string { $propertyMap = $this->getPropertyMapping(); @@ -286,8 +291,9 @@ protected function toPropertyName($columnName) * * @param array $fieldIds * @param int $versionNo + * @throws Exception */ - public function removePublicationReferences(array $fieldIds, $versionNo) + public function removePublicationReferences(array $fieldIds, int $versionNo) { if (empty($fieldIds)) { return; @@ -320,7 +326,7 @@ public function removePublicationReferences(array $fieldIds, $versionNo) * * @return array */ - protected function getPropertyMapping() + protected function getPropertyMapping(): array { return [ 'publication_id' => [ diff --git a/src/lib/Ez/FieldType/CalameoPublication/Type.php b/src/lib/Ez/FieldType/CalameoPublication/Type.php index ee9e318..6be14ba 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Type.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Type.php @@ -12,17 +12,17 @@ namespace AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication; -use AlmaviaCX\Calameo\API\Value\Publication; -use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; -use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue; -use eZ\Publish\Core\FieldType\FieldType; -use eZ\Publish\Core\FieldType\ValidationError; -use eZ\Publish\SPI\FieldType\Nameable; -use eZ\Publish\SPI\FieldType\Value as SPIValue; -use eZ\Publish\SPI\Persistence\Content\FieldValue as PersistenceValue; use Ibexa\Contracts\Core\FieldType\Value as BaseValue; +use Ibexa\Contracts\Core\FieldType\Value as SPIValue; +use Ibexa\Contracts\Core\Persistence\Content\FieldValue as PersistenceValue; +use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\Base\Exceptions\InvalidArgumentValue; +use Ibexa\Core\FieldType\FieldType; +use Ibexa\Core\FieldType\ValidationError; use RuntimeException; +# TODO + class Type extends FieldType { protected $settingsSchema = [ diff --git a/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php b/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php index 718d8bf..3adb5a8 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php +++ b/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php @@ -12,25 +12,15 @@ namespace AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication; -use AlmaviaCX\Calameo\API\Value\Publication; -use eZ\Publish\API\Repository\FieldType; +use Ibexa\Contracts\Core\Repository\FieldType; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; -use Symfony\Component\HttpFoundation\File\UploadedFile; class ValueTransformer implements DataTransformerInterface { - /** @var FieldType */ - protected $fieldType; + protected FieldType $fieldType; + protected Value $initialValue; - /** @var Value */ - protected $initialValue; - - /** - * ValueTransformer constructor. - * @param FieldType $fieldType - * @param Value $initialValue - */ public function __construct(FieldType $fieldType, Value $initialValue) { $this->fieldType = $fieldType; @@ -38,10 +28,10 @@ public function __construct(FieldType $fieldType, Value $initialValue) } /** - * @param Value $value + * @param Value|null $value * @return array */ - public function transform($value): array + public function transform(?Value $value): array { if (null === $value) { $value = $this->fieldType->getEmptyValue(); @@ -56,10 +46,10 @@ public function transform($value): array } /** - * @param array $value + * @param array|null $value * @return Value */ - public function reverseTransform($value) + public function reverseTransform(?array $value): Value { if (!is_array($value)) { throw new TransformationFailedException(sprintf('Expected a array got %s', gettype($value))); From cb06bfbf70496dcf554afbb9f3af02b9c4f242e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 27 Apr 2023 18:14:05 +0200 Subject: [PATCH 05/36] try to fix --- src/bundles/APIBundle/Resources/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundles/APIBundle/Resources/config/services.yml b/src/bundles/APIBundle/Resources/config/services.yml index a7ee9f5..87a8702 100644 --- a/src/bundles/APIBundle/Resources/config/services.yml +++ b/src/bundles/APIBundle/Resources/config/services.yml @@ -35,4 +35,4 @@ services: AlmaviaCX\Calameo\Exception\ExceptionThrower: - JMS\Serializer\Serializer: + #JMS\Serializer\Serializer: From e12a0399642acf35b4f8d8571b250f539f186f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Fri, 28 Apr 2023 09:45:27 +0200 Subject: [PATCH 06/36] try to fix --- .../APIBundle/Resources/config/services.yml | 7 +++---- src/lib/API/Serializer.php | 4 ++-- .../CalameoPublication/FormMapper.php | 6 +++--- .../FieldType/CalameoPublicationFieldType.php | 19 +++++-------------- src/lib/Ez/Twig/CalameoTwigExtension.php | 10 +++------- 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/bundles/APIBundle/Resources/config/services.yml b/src/bundles/APIBundle/Resources/config/services.yml index 87a8702..b969b20 100644 --- a/src/bundles/APIBundle/Resources/config/services.yml +++ b/src/bundles/APIBundle/Resources/config/services.yml @@ -21,8 +21,9 @@ services: $config: "%almaviacx.calameo.http_client.config%" AlmaviaCX\Calameo\API\Serializer: -# arguments: -# $baseSerializer: "@jms_serializer" + arguments: + # TODO The service "AlmaviaCX\Calameo\API\Serializer" has a dependency on a non-existent service "JMS\Serializer\SerializerInterface". + $baseSerializer: '@JMS\Serializer\SerializerInterface' AlmaviaCX\Calameo\API\Gateway\: resource: "../../../../lib/API/Gateway/*" @@ -34,5 +35,3 @@ services: resource: "../../../../lib/API/Service/*" AlmaviaCX\Calameo\Exception\ExceptionThrower: - - #JMS\Serializer\Serializer: diff --git a/src/lib/API/Serializer.php b/src/lib/API/Serializer.php index 0e8109f..02e7714 100644 --- a/src/lib/API/Serializer.php +++ b/src/lib/API/Serializer.php @@ -17,9 +17,9 @@ class Serializer { - protected \JMS\Serializer\Serializer $baseSerializer; + protected \JMS\Serializer\SerializerInterface $baseSerializer; - public function __construct(\JMS\Serializer\Serializer $baseSerializer) + public function __construct(\JMS\Serializer\SerializerInterface $baseSerializer) { $this->baseSerializer = $baseSerializer; } diff --git a/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php b/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php index 507bba1..8fd6146 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php @@ -15,12 +15,12 @@ use AlmaviaCX\Calameo\API\Repository\AccountRepository; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use AlmaviaCX\Calameo\Ez\Form\Type\FieldType\CalameoPublicationFieldType; -use Ibexa\Contracts\Core\Repository\FieldTypeService; -use Ibexa\AdminUi\Form\Data\FieldDefinitionData; -use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface; use EzSystems\RepositoryForms\Data\Content\FieldData; use EzSystems\RepositoryForms\FieldType\FieldDefinitionFormMapperInterface; use EzSystems\RepositoryForms\FieldType\FieldValueFormMapperInterface; +use Ibexa\AdminUi\Form\Data\FieldDefinitionData; +use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; +use Ibexa\Contracts\Core\Repository\FieldTypeService; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; diff --git a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php index 4166a28..f7ea0f3 100644 --- a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php +++ b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php @@ -13,12 +13,10 @@ namespace AlmaviaCX\Calameo\Ez\Form\Type\FieldType; use AlmaviaCX\Calameo\API\Repository\AccountRepository; -use AlmaviaCX\Calameo\API\Repository\FolderRepository; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Value; -use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface; use EzSystems\RepositoryForms\Form\Type\FieldType\BinaryBaseFieldType; -use GuzzleHttp\Exception\GuzzleException; +use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -31,28 +29,21 @@ class CalameoPublicationFieldType extends AbstractType { - /** @var AccountRepository */ - protected $accountRepository; + protected AccountRepository $accountRepository; + protected NotificationHandlerInterface $notificationHandler; - /** @var NotificationHandlerInterface */ - protected $notificationHandler; - - /** - * @param AccountRepository $accountRepository - * @param NotificationHandlerInterface $notificationHandler - */ public function __construct(AccountRepository $accountRepository, NotificationHandlerInterface $notificationHandler) { $this->accountRepository = $accountRepository; $this->notificationHandler = $notificationHandler; } - public function getName() + public function getName(): string { return $this->getBlockPrefix(); } - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'ezplatform_fieldtype_calameo_publication'; } diff --git a/src/lib/Ez/Twig/CalameoTwigExtension.php b/src/lib/Ez/Twig/CalameoTwigExtension.php index 9147092..f6cf800 100644 --- a/src/lib/Ez/Twig/CalameoTwigExtension.php +++ b/src/lib/Ez/Twig/CalameoTwigExtension.php @@ -12,24 +12,20 @@ use AlmaviaCX\Calameo\API\Value\Publication; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Value; -use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface; +use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; class CalameoTwigExtension extends AbstractExtension { - /** @var NotificationHandlerInterface */ - protected $notificationHandler; + protected NotificationHandlerInterface $notificationHandler; - /** - * @param NotificationHandlerInterface $notificationHandler - */ public function __construct(NotificationHandlerInterface $notificationHandler) { $this->notificationHandler = $notificationHandler; } - public function getFunctions() + public function getFunctions(): array { return [ new TwigFunction('loadCalameoPublication', [$this, 'loadCalameoPublication']), From 41628ad048ed2a53409305ad0063106ced89e555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Fri, 28 Apr 2023 09:57:01 +0200 Subject: [PATCH 07/36] try to fix --- src/lib/Ez/FieldType/CalameoPublication/Type.php | 2 -- .../Ez/Form/Type/FieldType/CalameoPublicationFieldType.php | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib/Ez/FieldType/CalameoPublication/Type.php b/src/lib/Ez/FieldType/CalameoPublication/Type.php index 6be14ba..279c1b4 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Type.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Type.php @@ -21,8 +21,6 @@ use Ibexa\Core\FieldType\ValidationError; use RuntimeException; -# TODO - class Type extends FieldType { protected $settingsSchema = [ diff --git a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php index f7ea0f3..8659162 100644 --- a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php +++ b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php @@ -15,7 +15,7 @@ use AlmaviaCX\Calameo\API\Repository\AccountRepository; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Value; -use EzSystems\RepositoryForms\Form\Type\FieldType\BinaryBaseFieldType; +use Ibexa\ContentForms\Form\Type\FieldType\BinaryBaseFieldType; use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -126,7 +126,7 @@ static function (FormEvent $event) use ($folderChoices) { ); } - public function getParent() + public function getParent(): string { return BinaryBaseFieldType::class; } From 40f0c951a3e5c5c0dc4adcfdb069ee3e58a79206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Fri, 28 Apr 2023 15:06:03 +0200 Subject: [PATCH 08/36] remove TODO --- src/bundles/APIBundle/Resources/config/services.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bundles/APIBundle/Resources/config/services.yml b/src/bundles/APIBundle/Resources/config/services.yml index b969b20..81320ce 100644 --- a/src/bundles/APIBundle/Resources/config/services.yml +++ b/src/bundles/APIBundle/Resources/config/services.yml @@ -22,7 +22,6 @@ services: AlmaviaCX\Calameo\API\Serializer: arguments: - # TODO The service "AlmaviaCX\Calameo\API\Serializer" has a dependency on a non-existent service "JMS\Serializer\SerializerInterface". $baseSerializer: '@JMS\Serializer\SerializerInterface' AlmaviaCX\Calameo\API\Gateway\: From 21d29980318b659d92d0ae24021a2a34dc1771de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 4 May 2023 15:58:54 +0200 Subject: [PATCH 09/36] ibexadesign --- src/bundles/EzBundle/Resources/config/field_templates.yml | 2 +- src/bundles/EzBundle/Resources/config/twig.yml | 2 +- .../themes/admin/fieldtypes/edit/calameo_publication.html.twig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bundles/EzBundle/Resources/config/field_templates.yml b/src/bundles/EzBundle/Resources/config/field_templates.yml index fb7b361..fd19000 100644 --- a/src/bundles/EzBundle/Resources/config/field_templates.yml +++ b/src/bundles/EzBundle/Resources/config/field_templates.yml @@ -1,4 +1,4 @@ system: default: field_templates: - - { template: '@ezdesign/field/calameo_publication_field.html.twig', priority: 10 } + - { template: '@ibexadesign/field/calameo_publication_field.html.twig', priority: 10 } diff --git a/src/bundles/EzBundle/Resources/config/twig.yml b/src/bundles/EzBundle/Resources/config/twig.yml index 0ad5134..908ebd4 100644 --- a/src/bundles/EzBundle/Resources/config/twig.yml +++ b/src/bundles/EzBundle/Resources/config/twig.yml @@ -1,2 +1,2 @@ form_themes: - - '@ezdesign/fieldtypes/edit/calameo_publication.html.twig' + - '@ibexadesign/fieldtypes/edit/calameo_publication.html.twig' diff --git a/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig b/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig index 6e5c538..7977b9e 100644 --- a/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig +++ b/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig @@ -1,7 +1,7 @@ {# @var publication \AlmaviaCX\Calameo\API\Value\Publication #} {% trans_default_domain 'ezrepoforms_content' %} -{% use '@ezdesign/fieldtypes/edit/binary_base.html.twig' %} +{% use '@ibexadesign/ui/field_type/edit/binary_base.html.twig' %} {%- block ezplatform_fieldtype_calameo_publication_row -%} {% set widget_container_block_name = 'calameo_publication_widget_container' %} From d7e72591f697755d4bff8e5ed8076e4f7dd3c96e Mon Sep 17 00:00:00 2001 From: Florian ALEXANDRE Date: Fri, 26 May 2023 16:48:03 +0200 Subject: [PATCH 10/36] feat: ibx4 migration --- .../themes/admin/field/calameo_publication_field.html.twig | 2 +- .../themes/standard/field/calameo_publication_field.html.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bundles/EzBundle/Resources/views/themes/admin/field/calameo_publication_field.html.twig b/src/bundles/EzBundle/Resources/views/themes/admin/field/calameo_publication_field.html.twig index 9a34abf..b4ac90b 100644 --- a/src/bundles/EzBundle/Resources/views/themes/admin/field/calameo_publication_field.html.twig +++ b/src/bundles/EzBundle/Resources/views/themes/admin/field/calameo_publication_field.html.twig @@ -1,5 +1,5 @@ {# @var publication \AlmaviaCX\Calameo\API\Value\Publication #} -{% extends '@EzPublishCore/content_fields.html.twig' %} +{% extends '@IbexaCore/content_fields.html.twig' %} {% block calameo_publication_field %} {% set publication = loadCalameoPublication(field.value) %} diff --git a/src/bundles/EzBundle/Resources/views/themes/standard/field/calameo_publication_field.html.twig b/src/bundles/EzBundle/Resources/views/themes/standard/field/calameo_publication_field.html.twig index 7e1d9ed..b809cef 100644 --- a/src/bundles/EzBundle/Resources/views/themes/standard/field/calameo_publication_field.html.twig +++ b/src/bundles/EzBundle/Resources/views/themes/standard/field/calameo_publication_field.html.twig @@ -1,5 +1,5 @@ {# @var publication \AlmaviaCX\Calameo\API\Value\Publication #} -{% extends '@EzPublishCore/content_fields.html.twig' %} +{% extends '@IbexaCore/content_fields.html.twig' %} {% block calameo_publication_field %} {% set publicationId = field.value.publicationId %} From ccbc62af47a783a6ee71faa8f2146d83e8bf14c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 2 Nov 2023 12:34:20 +0100 Subject: [PATCH 11/36] =?UTF-8?q?#111471=20-=20[MIG-GOUV]=20Creation=20de?= =?UTF-8?q?=20contenu=20:=20dysfonctionnement=20dans=20la=20cr=C3=A9ation?= =?UTF-8?q?=20de=20certains=20contenu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EzBundle/Resources/config/services.yml | 7 +++--- .../edit/calameo_publication.html.twig | 24 ++++++++++++++++++- .../CalameoPublication/FieldStorage.php | 3 ++- .../Ez/FieldType/CalameoPublication/Value.php | 10 ++++---- .../CalameoPublication/ValueTransformer.php | 5 ++-- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/bundles/EzBundle/Resources/config/services.yml b/src/bundles/EzBundle/Resources/config/services.yml index 82f2a1f..e4bf7c6 100644 --- a/src/bundles/EzBundle/Resources/config/services.yml +++ b/src/bundles/EzBundle/Resources/config/services.yml @@ -22,13 +22,12 @@ services: AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Gateway\DoctrineStorage: + AlmaviaCX\Calameo\API\HttpClientFactory: ~ + almaviacx.calameo.httpclient.siteaccessaware: lazy: true class: AlmaviaCX\Calameo\API\HttpClient decorates: AlmaviaCX\Calameo\API\HttpClient - arguments: - $APIKey: "$calameo.api.key;almaviacx$" - $APISecret: "$calameo.api.secret;almaviacx$" - $config: "$calameo.config;almaviacx$" + factory: ['@AlmaviaCX\Calameo\API\HttpClientFactory', 'create'] AlmaviaCX\Calameo\Ez\Twig\CalameoTwigExtension: diff --git a/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig b/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig index 7977b9e..4c16891 100644 --- a/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig +++ b/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig @@ -36,12 +36,34 @@ {% block calameo_publication_widget_container %} {{- form_widget(form.publicationId) -}} {{- form_widget(form.folderId) -}} + + {% set fieldtype = form.parent %} + {% set field_type_descriptions = fieldtype.vars.value.fieldDefinition.descriptions %} + + {{ block(preview_block_name) }} + + +
+ {{ block('binary_base_widget') }} +
+ +{% endblock %} + +{# + +vendor/ibexa/admin-ui/src/bundle/Resources/views/themes/admin/ui/field_type/edit/binary_base.html.twig + +{% block binary_base_widget_container %} + {% set fieldtype = form.parent %} + {% set field_type_descriptions = fieldtype.vars.value.fieldDefinition.descriptions %} + {{ block(preview_block_name) }} -
+
{{ block('binary_base_widget') }}
{% endblock %} +#} diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index a48d796..b35aaf5 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -58,7 +58,7 @@ public function __construct( * @throws ApiResponseErrorException * @throws GuzzleException */ - public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context): bool + public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context): ?bool { $inputUri = $field->value->externalData['inputUri'] ?? null; if ($inputUri) { @@ -86,6 +86,7 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co } $this->gateway->storePublicationReference($versionInfo, $field); + return true; } /** diff --git a/src/lib/Ez/FieldType/CalameoPublication/Value.php b/src/lib/Ez/FieldType/CalameoPublication/Value.php index 2e5c21b..e814e58 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Value.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Value.php @@ -18,16 +18,16 @@ class Value extends BaseValue { - public ?string $publicationId; - public ?int $folderId; + public ?string $publicationId = null; + public ?int $folderId = null; /** * Input file URI, as a path to a file on a disk. * * @var string|null */ - public ?string $inputUri; - public Closure $publicationLoader; - protected ?Publication $publication; + public ?string $inputUri = null; // must not be accessed before initialization + public ?Closure $publicationLoader = null; + protected ?Publication $publication = null; /** * Returns a string representation of the field value. diff --git a/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php b/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php index 3adb5a8..974269a 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php +++ b/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php @@ -31,7 +31,8 @@ public function __construct(FieldType $fieldType, Value $initialValue) * @param Value|null $value * @return array */ - public function transform(?Value $value): array + public function transform($value) + // must be compatible with Symfony\Component\Form\DataTransformerInterface::transform($value) { if (null === $value) { $value = $this->fieldType->getEmptyValue(); @@ -49,7 +50,7 @@ public function transform(?Value $value): array * @param array|null $value * @return Value */ - public function reverseTransform(?array $value): Value + public function reverseTransform($value) { if (!is_array($value)) { throw new TransformationFailedException(sprintf('Expected a array got %s', gettype($value))); From 8ba5b13fc61b4cb4e508d09305efe58db7172558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 2 Nov 2023 14:36:36 +0100 Subject: [PATCH 12/36] =?UTF-8?q?#111471=20-=20[MIG-GOUV]=20Creation=20de?= =?UTF-8?q?=20contenu=20:=20dysfonctionnement=20dans=20la=20cr=C3=A9ation?= =?UTF-8?q?=20de=20certains=20contenu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edit/calameo_publication.html.twig | 4 ++- src/lib/API/HttpClientFactory.php | 26 +++++++++++++++++++ .../CalameoPublication/FieldStorage.php | 20 +++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/lib/API/HttpClientFactory.php diff --git a/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig b/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig index 4c16891..3cab4fa 100644 --- a/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig +++ b/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig @@ -37,8 +37,10 @@ {{- form_widget(form.publicationId) -}} {{- form_widget(form.folderId) -}} + {% set fieldtype = form.parent %} {% set field_type_descriptions = fieldtype.vars.value.fieldDefinition.descriptions %} + {{ block(preview_block_name) }} @@ -47,10 +49,10 @@ {{ block('binary_base_widget') }} + {% endblock %} {# - vendor/ibexa/admin-ui/src/bundle/Resources/views/themes/admin/ui/field_type/edit/binary_base.html.twig {% block binary_base_widget_container %} diff --git a/src/lib/API/HttpClientFactory.php b/src/lib/API/HttpClientFactory.php new file mode 100644 index 0000000..5b0d988 --- /dev/null +++ b/src/lib/API/HttpClientFactory.php @@ -0,0 +1,26 @@ +configResolver = $configResolver; + } + + public function create(): HttpClient + { + $key = $this->configResolver->getParameter('calameo.api.key', 'almaviacx'); + $secret = $this->configResolver->getParameter('calameo.api.secret', 'almaviacx'); + $config = $this->configResolver->getParameter('calameo.config', 'almaviacx'); + + return new HttpClient($key, $secret, $config); + } +} diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index b35aaf5..52df2e3 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -106,13 +106,25 @@ public function getFieldData(VersionInfo $versionInfo, Field $field, array $cont } $field->value->externalData = $publicationReferenceData; - $field->value->externalData['publicationLoader'] = static function () use ($repository, $field) { + // #111471 - [MIG-GOUV] Creation de contenu : dysfonctionnement dans la création de certains contenu + // https://almaviacx.easyredmine.com/issues/111471?journals=all#note-971094 + // Lors de la publication d'un contenu on a cette erreur : + // > Lors de la publication d'un contenu on a cette erreur : + // Au lieu de set le publicationLoader on set directement la publication +// $field->value->externalData['publicationLoader'] = static function () use ($repository, $field) { +// try { +// return $repository->getPublicationInfos($field->value->externalData['publicationId']); +// } catch (UnknownBookIDException $exception) { +// return; +// } +// }; + if (empty($field->value->externalData['publication'])) { try { - return $repository->getPublicationInfos($field->value->externalData['publicationId']); + $publication = $repository->getPublicationInfos($field->value->externalData['publicationId']); + $field->value->externalData['publication'] = $publication; } catch (UnknownBookIDException $exception) { - return; } - }; + } } /** From 1b8f1532819cd32d99a5055332a644ba7df63a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 2 Nov 2023 17:36:43 +0100 Subject: [PATCH 13/36] =?UTF-8?q?#111471=20-=20[MIG-GOUV]=20Creation=20de?= =?UTF-8?q?=20contenu=20:=20dysfonctionnement=20dans=20la=20cr=C3=A9ation?= =?UTF-8?q?=20de=20certains=20contenus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 +- .../scripts/fieldType/calameo_publication.js | 10 +-- .../fieldType/edit/calameo_publication.scss | 85 ++++++++++++++----- .../edit/calameo_publication.html.twig | 67 +++++++-------- src/lib/API/Value/Publication.php | 5 +- .../CalameoPublication/FieldStorage.php | 43 +++++++--- .../Ez/FieldType/CalameoPublication/Value.php | 15 ---- 7 files changed, 135 insertions(+), 93 deletions(-) diff --git a/composer.json b/composer.json index 6a7b6cc..05cce74 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "ext-json": "*", "ibexa/core": "^4.2", "jms/serializer": "^3.5", - "jms/serializer-bundle": "^3.5" + "jms/serializer-bundle": "^3.5", + "symfony/var-exporter": "^6.0" }, "autoload": { "psr-4": { diff --git a/src/bundles/EzBundle/Resources/public/js/scripts/fieldType/calameo_publication.js b/src/bundles/EzBundle/Resources/public/js/scripts/fieldType/calameo_publication.js index 38513f9..f99a288 100644 --- a/src/bundles/EzBundle/Resources/public/js/scripts/fieldType/calameo_publication.js +++ b/src/bundles/EzBundle/Resources/public/js/scripts/fieldType/calameo_publication.js @@ -1,6 +1,6 @@ (function (global) { - const SELECTOR_FIELD = '.ez-field-edit--calameo_publication'; - const SELECTOR_LABEL_WRAPPER = '.ez-field-edit__label-wrapper'; + const SELECTOR_FIELD = '.ibexa-field-edit--calameo_publication'; + const SELECTOR_LABEL_WRAPPER = '.ibexa-field-edit__label-wrapper'; class CalameoPublicationPreviewField extends global.eZ.BasePreviewField { /** @@ -9,14 +9,14 @@ * @param {Event} event */ loadDroppedFilePreview(event) { - const preview = this.fieldContainer.querySelector('.ez-field-edit__preview'); - const nameContainer = preview.querySelector('.ez-field-edit-preview__file-name'); + const preview = this.fieldContainer.querySelector('.ibexa-field-edit__preview'); + const nameContainer = preview.querySelector('.ibexa-field-edit-preview__file-name'); const files = [].slice.call(event.target.files); nameContainer.innerHTML = files[0].name; nameContainer.title = files[0].name; - preview.querySelector('.ez-field-edit-preview__action--preview').href = URL.createObjectURL(files[0]); + preview.querySelector('.ibexa-field-edit-preview__action--preview').href = URL.createObjectURL(files[0]); } } diff --git a/src/bundles/EzBundle/Resources/public/scss/fieldType/edit/calameo_publication.scss b/src/bundles/EzBundle/Resources/public/scss/fieldType/edit/calameo_publication.scss index eca4962..59f1f92 100644 --- a/src/bundles/EzBundle/Resources/public/scss/fieldType/edit/calameo_publication.scss +++ b/src/bundles/EzBundle/Resources/public/scss/fieldType/edit/calameo_publication.scss @@ -1,34 +1,73 @@ -.ez-field-edit--calameo_publication { - &.ez-field-edit--with-preview { - .ez-field-edit-preview { - width: 500px; - height: 80px; - line-height: 80px; +$ibexa-color-danger: #db0032; +$ibexa-color-danger-100: #fbe5ea; - &__visual { - display: flex; - } +$base-font-size: 16px; + +@function div($number1, $number2) { + @return $number1 / $number2; +} + +@function calculateRem($size) { + $remSize: div($size, $base-font-size); + + @return $remSize + 0rem; // + 0rem converts value to proper `rem` +} + + +@mixin area-invalid { + color: $ibexa-color-danger; + border-color: $ibexa-color-danger; + background-color: $ibexa-color-danger-100; + + .ibexa-btn { + background-color: $ibexa-color-danger-100; + } +} - &__actions { - flex: 0 0 100px; +.ibexa-field-edit--calameo_publication { + &.is-invalid { + .ibexa-data-source { + @include area-invalid(); + } + } + + &.ibexa-field-edit--with-preview { + .ibexa-field-edit-preview { + &__file-icon { + flex: 0 0 calculateRem(32px); display: flex; align-items: center; - flex-direction: row; - justify-content: space-between; + justify-content: center; } - &__action--preview { - margin-top: 0; + &__visual { + grid-template-rows: auto; } - &__file-name { - flex: 1 1 auto; - font-size: .75rem; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - display: flex; - align-items: center; + &__media-wrapper { + justify-content: start; + flex-direction: column; + align-items: flex-start; + padding: calculateRem(24px); + } + + &__file-name-wrapper, + &__file-size-wrapper { + display: inline-block; + font-size: calculateRem(16px); + margin-right: calculateRem(40px); + + .ibexa-label { + margin-bottom: 0; + } + } + + &__file-name-wrapper { + max-width: calculateRem(500px); + } + + &__file-size-wrapper { + max-width: calculateRem(150px); } } } diff --git a/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig b/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig index 3cab4fa..306073a 100644 --- a/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig +++ b/src/bundles/EzBundle/Resources/views/themes/admin/fieldtypes/edit/calameo_publication.html.twig @@ -12,23 +12,38 @@ {%- endblock -%} {% block calameo_publication_preview %} + {% set readonly = attr.readonly|default(false) %} {% set publication = loadCalameoPublication(form.parent.vars.value.value) %} -
-
-
{{ publication ? publication.name }}
-
-
- - - - - - +
+
+
+
+ +

{{ publication ? publication.name }}

+
+
+ + + + + {{ 'ezbinaryfile.action.preview'|trans|desc('Preview') }} + + +
+
{% endblock %} @@ -50,22 +65,4 @@
-{% endblock %} - -{# -vendor/ibexa/admin-ui/src/bundle/Resources/views/themes/admin/ui/field_type/edit/binary_base.html.twig - -{% block binary_base_widget_container %} - {% set fieldtype = form.parent %} - {% set field_type_descriptions = fieldtype.vars.value.fieldDefinition.descriptions %} - - - {{ block(preview_block_name) }} - - -
- {{ block('binary_base_widget') }} -
- -{% endblock %} -#} +{% endblock %} \ No newline at end of file diff --git a/src/lib/API/Value/Publication.php b/src/lib/API/Value/Publication.php index d05df1c..379bf98 100644 --- a/src/lib/API/Value/Publication.php +++ b/src/lib/API/Value/Publication.php @@ -15,11 +15,12 @@ use DateTime; use JMS\Serializer\Annotation as Serializer; use AlmaviaCX\Calameo\API\Value\Response\ResponseContent; -use SplFileInfo; -use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\VarExporter\LazyGhostTrait; class Publication extends ResponseContent { + use LazyGhostTrait; + /** @var string Title of the publication */ public const SORT_NAME = "Name"; /** @var string Number of pages of the publication */ diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index 52df2e3..f4fb76f 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -107,20 +107,39 @@ public function getFieldData(VersionInfo $versionInfo, Field $field, array $cont $field->value->externalData = $publicationReferenceData; // #111471 - [MIG-GOUV] Creation de contenu : dysfonctionnement dans la création de certains contenu - // https://almaviacx.easyredmine.com/issues/111471?journals=all#note-971094 - // Lors de la publication d'un contenu on a cette erreur : - // > Lors de la publication d'un contenu on a cette erreur : - // Au lieu de set le publicationLoader on set directement la publication -// $field->value->externalData['publicationLoader'] = static function () use ($repository, $field) { -// try { -// return $repository->getPublicationInfos($field->value->externalData['publicationId']); -// } catch (UnknownBookIDException $exception) { -// return; -// } -// }; + // https://almaviacx.easyredmine.com/issues/111471?journals=all if (empty($field->value->externalData['publication'])) { try { - $publication = $repository->getPublicationInfos($field->value->externalData['publicationId']); + $publication = Publication::createLazyGhost(function (Publication $instance) use ($field, $repository) { + // $instance est une instance "Vide" ! + $publication = $repository->getPublicationInfos($field->value->externalData['publicationId']); + + $instance->id = $publication->id; + $instance->accountId = $publication->accountId; + $instance->folderId = $publication->folderId; + $instance->name = $publication->name; + $instance->description = $publication->description; + $instance->status = $publication->status; + $instance->isPrivate = $publication->isPrivate; + $instance->authId = $publication->authId; + $instance->allowMini = $publication->allowMini; + $instance->pages = $publication->pages; + $instance->width = $publication->width; + $instance->height = $publication->height; + $instance->views = $publication->views; + $instance->downloads = $publication->downloads; + $instance->comments = $publication->comments; + $instance->favorites = $publication->favorites; + $instance->date = $publication->date; + $instance->creation = $publication->creation; + $instance->publication = $publication->publication; + $instance->modification = $publication->modification; + $instance->posterUrl = $publication->posterUrl; + $instance->pictureUrl = $publication->pictureUrl; + $instance->thumbUrl = $publication->thumbUrl; + $instance->publicUrl = $publication->publicUrl; + $instance->viewUrl = $publication->viewUrl; + }); $field->value->externalData['publication'] = $publication; } catch (UnknownBookIDException $exception) { } diff --git a/src/lib/Ez/FieldType/CalameoPublication/Value.php b/src/lib/Ez/FieldType/CalameoPublication/Value.php index e814e58..96ade51 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Value.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Value.php @@ -26,7 +26,6 @@ class Value extends BaseValue * @var string|null */ public ?string $inputUri = null; // must not be accessed before initialization - public ?Closure $publicationLoader = null; protected ?Publication $publication = null; /** @@ -36,18 +35,4 @@ public function __toString(): string { return $this->publicationId; } - - /** - * @inheritDoc - */ - public function __get($property) - { - if ($property === "publication") { - if (!$this->publication && $this->publicationLoader) { - $loader = $this->publicationLoader; - $this->publication = $loader(); - } - } - return parent::__get($property); - } } From 040fae69c38af17dd67cf392a94809404639ab2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 2 Nov 2023 17:40:11 +0100 Subject: [PATCH 14/36] =?UTF-8?q?#111471=20-=20[MIG-GOUV]=20Creation=20de?= =?UTF-8?q?=20contenu=20:=20dysfonctionnement=20dans=20la=20cr=C3=A9ation?= =?UTF-8?q?=20de=20certains=20contenus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/Ez/FieldType/CalameoPublication/Value.php | 2 +- src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/Ez/FieldType/CalameoPublication/Value.php b/src/lib/Ez/FieldType/CalameoPublication/Value.php index 96ade51..9386575 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Value.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Value.php @@ -25,7 +25,7 @@ class Value extends BaseValue * * @var string|null */ - public ?string $inputUri = null; // must not be accessed before initialization + public ?string $inputUri = null; protected ?Publication $publication = null; /** diff --git a/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php b/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php index 974269a..27c0156 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php +++ b/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php @@ -32,7 +32,6 @@ public function __construct(FieldType $fieldType, Value $initialValue) * @return array */ public function transform($value) - // must be compatible with Symfony\Component\Form\DataTransformerInterface::transform($value) { if (null === $value) { $value = $this->fieldType->getEmptyValue(); From 9481c362d16ab3b05d9735b20fa6c7663adc0e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Tue, 7 Nov 2023 16:01:55 +0100 Subject: [PATCH 15/36] =?UTF-8?q?#111471=20-=20[MIG-GOUV]=20Creation=20de?= =?UTF-8?q?=20contenu=20:=20dysfonctionnement=20dans=20la=20cr=C3=A9ation?= =?UTF-8?q?=20de=20certains=20contenus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CalameoPublication/FieldStorage.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index f4fb76f..fc163f1 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -109,10 +109,11 @@ public function getFieldData(VersionInfo $versionInfo, Field $field, array $cont // #111471 - [MIG-GOUV] Creation de contenu : dysfonctionnement dans la création de certains contenu // https://almaviacx.easyredmine.com/issues/111471?journals=all if (empty($field->value->externalData['publication'])) { - try { - $publication = Publication::createLazyGhost(function (Publication $instance) use ($field, $repository) { - // $instance est une instance "Vide" ! - $publication = $repository->getPublicationInfos($field->value->externalData['publicationId']); + $publication = Publication::createLazyGhost(function (Publication $instance) use ($field, $repository) { + // $instance est une instance "Vide". + try { + $publicationId = $field->value->externalData['publicationId']; + $publication = $repository->getPublicationInfos($publicationId); $instance->id = $publication->id; $instance->accountId = $publication->accountId; @@ -139,10 +140,14 @@ public function getFieldData(VersionInfo $versionInfo, Field $field, array $cont $instance->thumbUrl = $publication->thumbUrl; $instance->publicUrl = $publication->publicUrl; $instance->viewUrl = $publication->viewUrl; - }); - $field->value->externalData['publication'] = $publication; - } catch (UnknownBookIDException $exception) { - } + } catch (UnknownBookIDException $exception) { + $this->logger->warning('UnknownBookIDException ' . $exception->getMessage(), [ + __METHOD__ . ' ' . __LINE__, + '$publicationId' => $publicationId, + ]); + } + }); + $field->value->externalData['publication'] = $publication; } } From ad09c80a2676e85b6ae0ef953941e8dcc29c1695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Tue, 7 Nov 2023 16:14:07 +0100 Subject: [PATCH 16/36] =?UTF-8?q?#111471=20-=20[MIG-GOUV]=20Creation=20de?= =?UTF-8?q?=20contenu=20:=20dysfonctionnement=20dans=20la=20cr=C3=A9ation?= =?UTF-8?q?=20de=20certains=20contenus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ez/FieldType/CalameoPublication/FieldStorage.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index fc163f1..6984268 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -100,19 +100,20 @@ public function getFieldData(VersionInfo $versionInfo, Field $field, array $cont { $repository = $this->publicationRepository; - $publicationReferenceData = $this->gateway->getPublicationReferenceData($field->id, $versionInfo->versionNo); + $publicationReferenceData = $this->gateway->getPublicationReferenceData($field->id, $versionInfo->versionNo); if ($publicationReferenceData === null || !$publicationReferenceData['publicationId']) { return; } $field->value->externalData = $publicationReferenceData; + // #111471 - [MIG-GOUV] Creation de contenu : dysfonctionnement dans la création de certains contenu // https://almaviacx.easyredmine.com/issues/111471?journals=all - if (empty($field->value->externalData['publication'])) { - $publication = Publication::createLazyGhost(function (Publication $instance) use ($field, $repository) { - // $instance est une instance "Vide". + $publicationId = $field->value->externalData['publicationId'] ?? null; + if (empty($field->value->externalData['publication']) && $publicationId) { + $publication = Publication::createLazyGhost(function (Publication $instance) use ($publicationId, $repository) { + // $instance est une instance "Vide" de Publication. try { - $publicationId = $field->value->externalData['publicationId']; $publication = $repository->getPublicationInfos($publicationId); $instance->id = $publication->id; From b32e3258a3b3a05ffafd1c41b9e3cae8fe774a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Tue, 7 Nov 2023 16:39:14 +0100 Subject: [PATCH 17/36] Add composer.lock to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 61ead86..de4a392 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /vendor +/composer.lock From 4e0a2e95e7bfb72656358c8e483245ae056e7864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Tue, 7 Nov 2023 16:40:44 +0100 Subject: [PATCH 18/36] Add .idea to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index de4a392..0e36ec8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor /composer.lock +/.idea From df5de144c19a6f9d3d9b530464b3265b8f1b0c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= <61149932+RemyNovactive@users.noreply.github.com> Date: Fri, 1 Dec 2023 11:35:06 +0100 Subject: [PATCH 19/36] Set Calameo optional (#6) * Add lazy on services. Catch MissingOrIncorrectParameterException --------- Co-authored-by: Florian ALEXANDRE --- src/bundles/APIBundle/Resources/config/services.yml | 1 + src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/bundles/APIBundle/Resources/config/services.yml b/src/bundles/APIBundle/Resources/config/services.yml index 81320ce..18bd789 100644 --- a/src/bundles/APIBundle/Resources/config/services.yml +++ b/src/bundles/APIBundle/Resources/config/services.yml @@ -15,6 +15,7 @@ services: public: false AlmaviaCX\Calameo\API\HttpClient: + lazy: true arguments: $APIKey: "%almaviacx.calameo.api.key%" $APISecret: "%almaviacx.calameo.api.secret%" diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index 6984268..8b3ca65 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -16,6 +16,7 @@ use AlmaviaCX\Calameo\API\Service\PublishingService; use AlmaviaCX\Calameo\API\Value\Publication; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; +use AlmaviaCX\Calameo\Exception\Response\MissingOrIncorrectParameterException; use AlmaviaCX\Calameo\Exception\Response\UnknownBookIDException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Gateway\DoctrineStorage; use Ibexa\Contracts\Core\FieldType\FieldStorage as FieldStorageInterface; @@ -146,6 +147,11 @@ public function getFieldData(VersionInfo $versionInfo, Field $field, array $cont __METHOD__ . ' ' . __LINE__, '$publicationId' => $publicationId, ]); + } catch (MissingOrIncorrectParameterException $exception) { + $this->logger->warning('MissingOrIncorrectParameterException ' . $exception->getMessage(), [ + __METHOD__ . ' ' . __LINE__, + '$publicationId' => $publicationId, + ]); } }); $field->value->externalData['publication'] = $publication; From 0c25e3fee2c5a3b064947b3b7fcf8a71dc81589c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Tue, 3 Dec 2024 17:38:48 +0100 Subject: [PATCH 20/36] Remove lazy --- .../APIBundle/Resources/config/services.yml | 1 + .../field/calameo_publication_field.html.twig | 6 ++ .../CalameoPublication/FieldStorage.php | 100 ++++++------------ src/lib/Ez/Twig/CalameoTwigExtension.php | 28 +++-- 4 files changed, 62 insertions(+), 73 deletions(-) diff --git a/src/bundles/APIBundle/Resources/config/services.yml b/src/bundles/APIBundle/Resources/config/services.yml index 81320ce..18bd789 100644 --- a/src/bundles/APIBundle/Resources/config/services.yml +++ b/src/bundles/APIBundle/Resources/config/services.yml @@ -15,6 +15,7 @@ services: public: false AlmaviaCX\Calameo\API\HttpClient: + lazy: true arguments: $APIKey: "%almaviacx.calameo.api.key%" $APISecret: "%almaviacx.calameo.api.secret%" diff --git a/src/bundles/EzBundle/Resources/views/themes/admin/field/calameo_publication_field.html.twig b/src/bundles/EzBundle/Resources/views/themes/admin/field/calameo_publication_field.html.twig index b4ac90b..d54d89c 100644 --- a/src/bundles/EzBundle/Resources/views/themes/admin/field/calameo_publication_field.html.twig +++ b/src/bundles/EzBundle/Resources/views/themes/admin/field/calameo_publication_field.html.twig @@ -9,5 +9,11 @@ {% else %} {{ publication.name }} ({{ publication.id }}) {% endif %} + {% else %} +

ERREUR CALAMEO

+
+            publicationId : {{ field.value.publicationId|default }}
+            folderId : {{ field.value.folderId|default }}
+        
{% endif %} {% endblock %} diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index 6984268..ad7a1b5 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -18,10 +18,11 @@ use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use AlmaviaCX\Calameo\Exception\Response\UnknownBookIDException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Gateway\DoctrineStorage; +use Doctrine\DBAL\Exception; +use GuzzleHttp\Exception\GuzzleException; use Ibexa\Contracts\Core\FieldType\FieldStorage as FieldStorageInterface; use Ibexa\Contracts\Core\Persistence\Content\Field; use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; -use GuzzleHttp\Exception\GuzzleException; use Psr\Log\LoggerInterface; use SplFileInfo; @@ -53,35 +54,50 @@ public function __construct( /** * @param VersionInfo $versionInfo * @param Field $field - * @param array $context + * @param array $context ["identifier" => "LegacyStorage"] * @return bool * @throws ApiResponseErrorException * @throws GuzzleException + * @throws Exception */ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context): ?bool { $inputUri = $field->value->externalData['inputUri'] ?? null; if ($inputUri) { $file = new SplFileInfo($inputUri); - try { - if ($field->value->externalData['publicationId'] === null) { - throw new UnknownBookIDException(); + if ($field->value->externalData['publicationId'] === null) { + $folderId = $field->value->externalData['folderId']; + if (!$folderId) { // null ou 0 + // Est-ce possible ? + $this->logger->error(sprintf('[Calameo] FolderId is %s', + $folderId === null ? 'null' : $folderId + )); } - $publication = $this->publishingService->revise( - $field->value->externalData['publicationId'], - $file - ); - } catch (UnknownBookIDException $exception) { + + $name = $versionInfo->contentInfo->name; + // $name === '' car le contenu n'est pas encore enregistré. + // Du coup calaméo va mettre : "Custom Filename" + if (!$name) { + $name = 'c' . $versionInfo->contentInfo->id; // + } + + // Création $publication = $this->publishingService->publish( - $field->value->externalData['folderId'], + $folderId, $file, [ - 'name' => $versionInfo->contentInfo->name, + 'name' => $name, // expected to be of type "string" 'is_published' => 1, 'publishing_mode' => Publication::PUBLISHING_MODE_PUBLIC, ] ); $field->value->externalData['publicationId'] = $publication->id; + } else { + // Modification + $this->publishingService->revise( + $field->value->externalData['publicationId'], + $file + ); } } @@ -93,62 +109,16 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co * @param VersionInfo $versionInfo * @param Field $field * @param array $context - * @throws ApiResponseErrorException - * @throws GuzzleException + * @throws Exception */ public function getFieldData(VersionInfo $versionInfo, Field $field, array $context): void { - $repository = $this->publicationRepository; - $publicationReferenceData = $this->gateway->getPublicationReferenceData($field->id, $versionInfo->versionNo); - if ($publicationReferenceData === null || !$publicationReferenceData['publicationId']) { - return; - } - - $field->value->externalData = $publicationReferenceData; - - // #111471 - [MIG-GOUV] Creation de contenu : dysfonctionnement dans la création de certains contenu - // https://almaviacx.easyredmine.com/issues/111471?journals=all - $publicationId = $field->value->externalData['publicationId'] ?? null; - if (empty($field->value->externalData['publication']) && $publicationId) { - $publication = Publication::createLazyGhost(function (Publication $instance) use ($publicationId, $repository) { - // $instance est une instance "Vide" de Publication. - try { - $publication = $repository->getPublicationInfos($publicationId); - - $instance->id = $publication->id; - $instance->accountId = $publication->accountId; - $instance->folderId = $publication->folderId; - $instance->name = $publication->name; - $instance->description = $publication->description; - $instance->status = $publication->status; - $instance->isPrivate = $publication->isPrivate; - $instance->authId = $publication->authId; - $instance->allowMini = $publication->allowMini; - $instance->pages = $publication->pages; - $instance->width = $publication->width; - $instance->height = $publication->height; - $instance->views = $publication->views; - $instance->downloads = $publication->downloads; - $instance->comments = $publication->comments; - $instance->favorites = $publication->favorites; - $instance->date = $publication->date; - $instance->creation = $publication->creation; - $instance->publication = $publication->publication; - $instance->modification = $publication->modification; - $instance->posterUrl = $publication->posterUrl; - $instance->pictureUrl = $publication->pictureUrl; - $instance->thumbUrl = $publication->thumbUrl; - $instance->publicUrl = $publication->publicUrl; - $instance->viewUrl = $publication->viewUrl; - } catch (UnknownBookIDException $exception) { - $this->logger->warning('UnknownBookIDException ' . $exception->getMessage(), [ - __METHOD__ . ' ' . __LINE__, - '$publicationId' => $publicationId, - ]); - } - }); - $field->value->externalData['publication'] = $publication; + if ($publicationReferenceData + && !empty($publicationReferenceData['publicationId']) + && !empty($publicationReferenceData['folderId']) + ) { + $field->value->externalData = $publicationReferenceData; } } @@ -165,7 +135,7 @@ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array return; } - $publicationIds = $this->gateway->getReferencedPublications($fieldIds, $versionInfo->versionNo); + $publicationIds = $this->gateway->getReferencedPublications($fieldIds); $versionPublicationId = $publicationIds[$versionInfo->versionNo] ?? null; $this->gateway->removePublicationReferences($fieldIds, $versionInfo->versionNo); diff --git a/src/lib/Ez/Twig/CalameoTwigExtension.php b/src/lib/Ez/Twig/CalameoTwigExtension.php index f6cf800..b5fa992 100644 --- a/src/lib/Ez/Twig/CalameoTwigExtension.php +++ b/src/lib/Ez/Twig/CalameoTwigExtension.php @@ -9,8 +9,10 @@ namespace AlmaviaCX\Calameo\Ez\Twig; +use AlmaviaCX\Calameo\API\Repository\PublicationRepository; use AlmaviaCX\Calameo\API\Value\Publication; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; +use AlmaviaCX\Calameo\Exception\Response\UnknownBookIDException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Value; use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; use Twig\Extension\AbstractExtension; @@ -19,9 +21,13 @@ class CalameoTwigExtension extends AbstractExtension { protected NotificationHandlerInterface $notificationHandler; + protected PublicationRepository $publicationRepository; - public function __construct(NotificationHandlerInterface $notificationHandler) - { + public function __construct( + NotificationHandlerInterface $notificationHandler, + PublicationRepository $publicationRepository + ) { + $this->publicationRepository = $publicationRepository; $this->notificationHandler = $notificationHandler; } @@ -34,12 +40,18 @@ public function getFunctions(): array public function loadCalameoPublication(Value $value): ?Publication { - try { - return $value->publication; - } catch (ApiResponseErrorException $exception) { - $this->notificationHandler->error( - sprintf("[Calameo] %s", $exception->getMessage()) - ); + if ($value->folderId && $value->publicationId) { + try { + return $this->publicationRepository->getPublicationInfos($value->publicationId); + } catch (UnknownBookIDException $unknownBookIDException) { + $this->notificationHandler->warning( + sprintf("[Calameo] %s", $unknownBookIDException->getMessage()) // Unknown book + ); + } catch (ApiResponseErrorException $exception) { + $this->notificationHandler->error( + sprintf("[Calameo] %s", $exception->getMessage()) + ); + } } return null; } From e545a498ae4229e644fe5ad12695d09f687acd7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Tue, 10 Feb 2026 16:53:16 +0100 Subject: [PATCH 21/36] Ibexa5 --- composer.json | 22 +++++++++++++--------- src/lib/API/Value/Publication.php | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 05cce74..9de99aa 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { "name": "almaviacx/calameobundle", - "description": "AlmaviaCX Calaméo Bundle provide a client for the Rest API and a new field type for eZPlatform.", + "description": "AlmaviaCX Calaméo Bundle provide a client for the Rest API and a new field type for Ibexa.", "keywords": [ "calameo", - "ezplatform", + "ibexa", "almaviacx" ], "homepage": "https://github.com/Novactive/AlmaviaCXCalameoBundle", @@ -19,13 +19,15 @@ "MIT" ], "require": { - "ext-pdo": "*", - "php": "^7.4 || ^8.0", + "php": ">=8.3", "ext-json": "*", - "ibexa/core": "^4.2", - "jms/serializer": "^3.5", - "jms/serializer-bundle": "^3.5", - "symfony/var-exporter": "^6.0" + "ext-pdo": "*", + "guzzlehttp/guzzle": "^7.10", + "guzzlehttp/promises": "^2.3", + "ibexa/oss": "^5", + "jms/serializer-bundle": "^5.5", + "nyholm/psr7": "^1.8", + "symfony/var-exporter": "^8.0" }, "autoload": { "psr-4": { @@ -46,7 +48,9 @@ "config": { "sort-packages": true, "allow-plugins": { - "php-http/discovery": true + "php-http/discovery": true, + "symfony/flex": true, + "ibexa/post-install": true } } } diff --git a/src/lib/API/Value/Publication.php b/src/lib/API/Value/Publication.php index 379bf98..76dc295 100644 --- a/src/lib/API/Value/Publication.php +++ b/src/lib/API/Value/Publication.php @@ -15,11 +15,11 @@ use DateTime; use JMS\Serializer\Annotation as Serializer; use AlmaviaCX\Calameo\API\Value\Response\ResponseContent; -use Symfony\Component\VarExporter\LazyGhostTrait; +use Symfony\Component\DependencyInjection\Loader\Configurator\Traits\LazyTrait; class Publication extends ResponseContent { - use LazyGhostTrait; + use LazyTrait; /** @var string Title of the publication */ public const SORT_NAME = "Name"; From 9a86ce60e0277c90fd7b6d0cb8c3c336e6fb82b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 11 Feb 2026 09:44:31 +0100 Subject: [PATCH 22/36] symfony/var-exporter --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9de99aa..d50006e 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "ibexa/oss": "^5", "jms/serializer-bundle": "^5.5", "nyholm/psr7": "^1.8", - "symfony/var-exporter": "^8.0" + "symfony/var-exporter": "|^6.0|^7.0|^8.0" }, "autoload": { "psr-4": { From 15dfccd7e336ae4998f3585b8d0dcfb004da009a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 11 Feb 2026 09:46:30 +0100 Subject: [PATCH 23/36] symfony/var-exporter --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d50006e..baa566c 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "ibexa/oss": "^5", "jms/serializer-bundle": "^5.5", "nyholm/psr7": "^1.8", - "symfony/var-exporter": "|^6.0|^7.0|^8.0" + "symfony/var-exporter": "^6.0|^7.0|^8.0" }, "autoload": { "psr-4": { From f960d420b7eff74163803b85e476c6a4e51bbb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 19 Feb 2026 17:04:25 +0100 Subject: [PATCH 24/36] Ibexa 5 --- src/lib/API/Gateway/GenericGateway.php | 2 +- src/lib/API/Gateway/UploadGateway.php | 2 +- src/lib/API/Service/PublishingService.php | 26 ++++- src/lib/API/Value/Folder.php | 6 +- src/lib/API/Value/Publication.php | 28 ++--- src/lib/API/Value/Request/SortOrder.php | 4 +- src/lib/API/Value/Response/Response.php | 4 +- ...alameoResponseContentMustBePublication.php | 15 +++ .../CalameoPublication/FieldStorage.php | 108 +++++++++--------- 9 files changed, 112 insertions(+), 83 deletions(-) create mode 100644 src/lib/Exception/CalameoResponseContentMustBePublication.php diff --git a/src/lib/API/Gateway/GenericGateway.php b/src/lib/API/Gateway/GenericGateway.php index 5cfa066..fb686f8 100644 --- a/src/lib/API/Gateway/GenericGateway.php +++ b/src/lib/API/Gateway/GenericGateway.php @@ -14,7 +14,7 @@ abstract class GenericGateway extends AbstractGateway { - public const ENDPOINT = 'http://api.calameo.com/1.0'; + public const string ENDPOINT = 'http://api.calameo.com/1.0'; protected function getEndpoint(): string { diff --git a/src/lib/API/Gateway/UploadGateway.php b/src/lib/API/Gateway/UploadGateway.php index 24a9924..2408991 100644 --- a/src/lib/API/Gateway/UploadGateway.php +++ b/src/lib/API/Gateway/UploadGateway.php @@ -21,7 +21,7 @@ class UploadGateway extends AbstractGateway { - public const ENDPOINT = 'http://upload.calameo.com/1.0'; + public const string ENDPOINT = 'http://upload.calameo.com/1.0'; /** * @param int $subscriptionId diff --git a/src/lib/API/Service/PublishingService.php b/src/lib/API/Service/PublishingService.php index bfc6534..6e926c4 100644 --- a/src/lib/API/Service/PublishingService.php +++ b/src/lib/API/Service/PublishingService.php @@ -15,6 +15,7 @@ use AlmaviaCX\Calameo\API\Gateway\UploadGateway; use AlmaviaCX\Calameo\API\Value\Publication; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; +use AlmaviaCX\Calameo\Exception\CalameoResponseContentMustBePublication; use AlmaviaCX\Calameo\Exception\NotImplementedException; use GuzzleHttp\Exception\GuzzleException; use SplFileInfo; @@ -34,6 +35,7 @@ public function __construct(UploadGateway $gateway) * @return Publication * @throws ApiResponseErrorException * @throws GuzzleException + * @throws CalameoResponseContentMustBePublication */ public function publish( int $folderId, @@ -45,7 +47,10 @@ public function publish( $file, $options ); - return $response->content; + if ($response->content instanceof Publication) { + return $response->content; + } + throw new CalameoResponseContentMustBePublication(); } /** @@ -55,6 +60,7 @@ public function publish( * @return Publication * @throws ApiResponseErrorException * @throws GuzzleException + * @throws CalameoResponseContentMustBePublication */ public function publishFromUrl(int $folderId, string $url, array $options = []): Publication { @@ -63,7 +69,10 @@ public function publishFromUrl(int $folderId, string $url, array $options = []): $url, $options ); - return $response->content; + if ($response->content instanceof Publication) { + return $response->content; + } + throw new CalameoResponseContentMustBePublication(); } /** @@ -83,6 +92,7 @@ public function publishFromText(int $folderId, string $text): Publication * @return Publication * @throws ApiResponseErrorException * @throws GuzzleException + * @throws CalameoResponseContentMustBePublication */ public function revise(string $publicationId, SplFileInfo $file): Publication { @@ -90,7 +100,10 @@ public function revise(string $publicationId, SplFileInfo $file): Publication $publicationId, $file ); - return $response->content; + if ($response->content instanceof Publication) { + return $response->content; + } + throw new CalameoResponseContentMustBePublication(); } /** @@ -99,7 +112,7 @@ public function revise(string $publicationId, SplFileInfo $file): Publication * @param int $folderId * @return Publication * @throws ApiResponseErrorException - * @throws GuzzleException + * @throws GuzzleException|CalameoResponseContentMustBePublication */ public function reviseFromUrl(string $publicationId, string $url, int $folderId): Publication { @@ -108,7 +121,10 @@ public function reviseFromUrl(string $publicationId, string $url, int $folderId) $url, $folderId ); - return $response->content; + if ($response->content instanceof Publication) { + return $response->content; + } + throw new CalameoResponseContentMustBePublication(); } /** diff --git a/src/lib/API/Value/Folder.php b/src/lib/API/Value/Folder.php index 6c5d7cf..decdd38 100644 --- a/src/lib/API/Value/Folder.php +++ b/src/lib/API/Value/Folder.php @@ -19,13 +19,13 @@ class Folder extends ResponseContent { /** @var string Title of the publication */ - public const SORT_NAME = 'Name'; + public const string SORT_NAME = 'Name'; /** @var string Date of creation */ - public const SORT_CREATION = 'Creation'; + public const string SORT_CREATION = 'Creation'; /** @var string Date the folder was last modified */ - public const SORT_MODIFICATION = 'Modification'; + public const string SORT_MODIFICATION = 'Modification'; /** * Unique identifying key for the folder diff --git a/src/lib/API/Value/Publication.php b/src/lib/API/Value/Publication.php index 76dc295..876cad0 100644 --- a/src/lib/API/Value/Publication.php +++ b/src/lib/API/Value/Publication.php @@ -22,33 +22,33 @@ class Publication extends ResponseContent use LazyTrait; /** @var string Title of the publication */ - public const SORT_NAME = "Name"; + public const string SORT_NAME = "Name"; /** @var string Number of pages of the publication */ - public const SORT_PAGES = "Pages"; + public const string SORT_PAGES = "Pages"; /** @var string Number of comments on the publication */ - public const SORT_COMMENTS = "Comments"; + public const string SORT_COMMENTS = "Comments"; /** @var string Number of times the publication was read */ - public const SORT_VIEWS = "Views"; + public const string SORT_VIEWS = "Views"; /** @var string Date of publication */ - public const SORT_DATE = "Date"; + public const string SORT_DATE = "Date"; /** @var string Date of creation */ - public const SORT_CREATION = "Creation"; + public const string SORT_CREATION = "Creation"; /** @var string Date the publication was last modified */ - public const SORT_MODIFICATION = "Modification"; + public const string SORT_MODIFICATION = "Modification"; /** @var string waiting to be converted */ - public const STATUS_QUEUE = 'QUEUE'; + public const string STATUS_QUEUE = 'QUEUE'; /** @var string processing document */ - public const STATUS_PROCESS = 'PROCESS'; + public const string STATUS_PROCESS = 'PROCESS'; /** @var string converting document */ - public const STATUS_STORE = 'STORE'; + public const string STATUS_STORE = 'STORE'; /** @var string error during conversion */ - public const STATUS_ERROR = 'ERROR'; + public const string STATUS_ERROR = 'ERROR'; /** @var string publication ready */ - public const STATUS_DONE = 'DONE'; + public const string STATUS_DONE = 'DONE'; - public const PUBLISHING_MODE_PUBLIC = 1; - public const PUBLISHING_MODE_PRIVATE = 2; + public const int PUBLISHING_MODE_PUBLIC = 1; + public const int PUBLISHING_MODE_PRIVATE = 2; /** * ID of the publication diff --git a/src/lib/API/Value/Request/SortOrder.php b/src/lib/API/Value/Request/SortOrder.php index 3ea15bb..d8694b9 100644 --- a/src/lib/API/Value/Request/SortOrder.php +++ b/src/lib/API/Value/Request/SortOrder.php @@ -14,6 +14,6 @@ class SortOrder { - public const UP = "UP"; - public const DOWN = "DOWN"; + public const string UP = "UP"; + public const string DOWN = "DOWN"; } diff --git a/src/lib/API/Value/Response/Response.php b/src/lib/API/Value/Response/Response.php index f8baa92..af8df9b 100644 --- a/src/lib/API/Value/Response/Response.php +++ b/src/lib/API/Value/Response/Response.php @@ -16,8 +16,8 @@ class Response { - public const TYPE_OK ="ok"; - public const TYPE_ERROR ="error"; + public const string TYPE_OK ="ok"; + public const string TYPE_ERROR ="error"; /** * @var string diff --git a/src/lib/Exception/CalameoResponseContentMustBePublication.php b/src/lib/Exception/CalameoResponseContentMustBePublication.php new file mode 100644 index 0000000..7b0fa05 --- /dev/null +++ b/src/lib/Exception/CalameoResponseContentMustBePublication.php @@ -0,0 +1,15 @@ +value->externalData['inputUri'] ?? null; if ($inputUri) { @@ -93,11 +93,10 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co /** * @param VersionInfo $versionInfo * @param Field $field - * @param array $context * @throws ApiResponseErrorException - * @throws GuzzleException + * @throws GuzzleException|\Doctrine\DBAL\Exception */ - public function getFieldData(VersionInfo $versionInfo, Field $field, array $context): void + public function getFieldData(VersionInfo $versionInfo, Field $field,): void { $repository = $this->publicationRepository; @@ -107,65 +106,64 @@ public function getFieldData(VersionInfo $versionInfo, Field $field, array $cont } $field->value->externalData = $publicationReferenceData; - + // #111471 - [MIG-GOUV] Creation de contenu : dysfonctionnement dans la création de certains contenu // https://almaviacx.easyredmine.com/issues/111471?journals=all $publicationId = $field->value->externalData['publicationId'] ?? null; - if (empty($field->value->externalData['publication']) && $publicationId) { - $publication = Publication::createLazyGhost(function (Publication $instance) use ($publicationId, $repository) { - // $instance est une instance "Vide" de Publication. - try { - $publication = $repository->getPublicationInfos($publicationId); - - $instance->id = $publication->id; - $instance->accountId = $publication->accountId; - $instance->folderId = $publication->folderId; - $instance->name = $publication->name; - $instance->description = $publication->description; - $instance->status = $publication->status; - $instance->isPrivate = $publication->isPrivate; - $instance->authId = $publication->authId; - $instance->allowMini = $publication->allowMini; - $instance->pages = $publication->pages; - $instance->width = $publication->width; - $instance->height = $publication->height; - $instance->views = $publication->views; - $instance->downloads = $publication->downloads; - $instance->comments = $publication->comments; - $instance->favorites = $publication->favorites; - $instance->date = $publication->date; - $instance->creation = $publication->creation; - $instance->publication = $publication->publication; - $instance->modification = $publication->modification; - $instance->posterUrl = $publication->posterUrl; - $instance->pictureUrl = $publication->pictureUrl; - $instance->thumbUrl = $publication->thumbUrl; - $instance->publicUrl = $publication->publicUrl; - $instance->viewUrl = $publication->viewUrl; - } catch (UnknownBookIDException $exception) { - $this->logger->warning('UnknownBookIDException ' . $exception->getMessage(), [ - __METHOD__ . ' ' . __LINE__, - '$publicationId' => $publicationId, - ]); - } catch (MissingOrIncorrectParameterException $exception) { - $this->logger->warning('MissingOrIncorrectParameterException ' . $exception->getMessage(), [ - __METHOD__ . ' ' . __LINE__, - '$publicationId' => $publicationId, - ]); - } - }); - $field->value->externalData['publication'] = $publication; - } +// if (empty($field->value->externalData['publication']) && $publicationId) { +// $publication = Publication::(function (Publication $instance) use ($publicationId, $repository) { +// // $instance est une instance "Vide" de Publication. +// try { +// $publication = $repository->getPublicationInfos($publicationId); +// +// $instance->id = $publication->id; +// $instance->accountId = $publication->accountId; +// $instance->folderId = $publication->folderId; +// $instance->name = $publication->name; +// $instance->description = $publication->description; +// $instance->status = $publication->status; +// $instance->isPrivate = $publication->isPrivate; +// $instance->authId = $publication->authId; +// $instance->allowMini = $publication->allowMini; +// $instance->pages = $publication->pages; +// $instance->width = $publication->width; +// $instance->height = $publication->height; +// $instance->views = $publication->views; +// $instance->downloads = $publication->downloads; +// $instance->comments = $publication->comments; +// $instance->favorites = $publication->favorites; +// $instance->date = $publication->date; +// $instance->creation = $publication->creation; +// $instance->publication = $publication->publication; +// $instance->modification = $publication->modification; +// $instance->posterUrl = $publication->posterUrl; +// $instance->pictureUrl = $publication->pictureUrl; +// $instance->thumbUrl = $publication->thumbUrl; +// $instance->publicUrl = $publication->publicUrl; +// $instance->viewUrl = $publication->viewUrl; +// } catch (UnknownBookIDException $exception) { +// $this->logger->warning('UnknownBookIDException ' . $exception->getMessage(), [ +// __METHOD__ . ' ' . __LINE__, +// '$publicationId' => $publicationId, +// ]); +// } catch (MissingOrIncorrectParameterException $exception) { +// $this->logger->warning('MissingOrIncorrectParameterException ' . $exception->getMessage(), [ +// __METHOD__ . ' ' . __LINE__, +// '$publicationId' => $publicationId, +// ]); +// } +// }); +// $field->value->externalData['publication'] = $publication; +// } } /** * @param VersionInfo $versionInfo * @param array $fieldIds - * @param array $context * @return void - * @throws GuzzleException + * @throws GuzzleException|\Doctrine\DBAL\Exception */ - public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context): void + public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void { if (empty($fieldIds)) { return; From 68d3e58398350b9596bc96958ba3f2cc77b521c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Fri, 6 Mar 2026 15:30:31 +0100 Subject: [PATCH 25/36] Catch all exception in CalameoTwigExtension --- src/lib/Ez/Twig/CalameoTwigExtension.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/Ez/Twig/CalameoTwigExtension.php b/src/lib/Ez/Twig/CalameoTwigExtension.php index b5fa992..a42e1f3 100644 --- a/src/lib/Ez/Twig/CalameoTwigExtension.php +++ b/src/lib/Ez/Twig/CalameoTwigExtension.php @@ -45,9 +45,13 @@ public function loadCalameoPublication(Value $value): ?Publication return $this->publicationRepository->getPublicationInfos($value->publicationId); } catch (UnknownBookIDException $unknownBookIDException) { $this->notificationHandler->warning( - sprintf("[Calameo] %s", $unknownBookIDException->getMessage()) // Unknown book + sprintf("[Calameo][UnknownBookIDException] %s", $unknownBookIDException->getMessage()) // Unknown book ); } catch (ApiResponseErrorException $exception) { + $this->notificationHandler->error( + sprintf("[Calameo][ApiResponseErrorException] %s", $exception->getMessage()) + ); + } catch (\Exception $exception) { $this->notificationHandler->error( sprintf("[Calameo] %s", $exception->getMessage()) ); From 9b882f2ff78e61ba93afebcb73eb17a40086fec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 2 Apr 2026 16:26:38 +0200 Subject: [PATCH 26/36] Fix Client error: `GET http://api.calameo.com/1.0?order=Name&way=UP&start=0&step=20&action=API.fetchAccountSubscriptions&output=JSON&apikey=&signature=xxx` resulted in a `400 Bad Request` response: --- src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php index 8659162..6a3e028 100644 --- a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php +++ b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php @@ -57,7 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) do { try { $availableFolders = $this->accountRepository->fetchAccountFolders($limit, $offset); - } catch (ApiResponseErrorException $exception) { + } catch (\GuzzleHttp\Exception\ClientException|ApiResponseErrorException $exception) { $this->notificationHandler->error( sprintf("[Calameo] %s", $exception->getMessage()) ); From 65346811c82e117b7ea4d850cfd94581a8150785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 2 Apr 2026 16:27:21 +0200 Subject: [PATCH 27/36] Gestion d'exception --- .../Ez/FieldType/CalameoPublication/FieldStorage.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index c3250d5..08bea75 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -16,7 +16,7 @@ use AlmaviaCX\Calameo\API\Service\PublishingService; use AlmaviaCX\Calameo\API\Value\Publication; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; -use AlmaviaCX\Calameo\Exception\Response\MissingOrIncorrectParameterException; +use AlmaviaCX\Calameo\Exception\CalameoResponseContentMustBePublication; use AlmaviaCX\Calameo\Exception\Response\UnknownBookIDException; use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Gateway\DoctrineStorage; use Doctrine\DBAL\Exception; @@ -55,15 +55,10 @@ public function __construct( /** * @param VersionInfo $versionInfo * @param Field $field - * @param array $context ["identifier" => "LegacyStorage"] * @return bool - * @throws ApiResponseErrorException - * @throws GuzzleException - * @throws Exception - * @throws GuzzleException|\Doctrine\DBAL\Exception + * @throws ApiResponseErrorException|GuzzleException|Exception|CalameoResponseContentMustBePublication */ public function storeFieldData(VersionInfo $versionInfo, Field $field): bool -// public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context): ?bool { $inputUri = $field->value->externalData['inputUri'] ?? null; if ($inputUri) { @@ -129,7 +124,7 @@ public function getFieldData(VersionInfo $versionInfo, Field $field,): void * @param VersionInfo $versionInfo * @param array $fieldIds * @return void - * @throws GuzzleException|\Doctrine\DBAL\Exception + * @throws GuzzleException|Exception */ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void { From e892121f4dc97c7272d736ca59edd425e81ca8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 3 Jun 2026 16:27:31 +0200 Subject: [PATCH 28/36] Fix AlmaviaCX\Calameo\API\HttpClient --- src/bundles/EzBundle/Resources/config/services.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bundles/EzBundle/Resources/config/services.yml b/src/bundles/EzBundle/Resources/config/services.yml index e4bf7c6..8a965e2 100644 --- a/src/bundles/EzBundle/Resources/config/services.yml +++ b/src/bundles/EzBundle/Resources/config/services.yml @@ -24,10 +24,8 @@ services: AlmaviaCX\Calameo\API\HttpClientFactory: ~ - almaviacx.calameo.httpclient.siteaccessaware: + AlmaviaCX\Calameo\API\HttpClient: lazy: true - class: AlmaviaCX\Calameo\API\HttpClient - decorates: AlmaviaCX\Calameo\API\HttpClient factory: ['@AlmaviaCX\Calameo\API\HttpClientFactory', 'create'] AlmaviaCX\Calameo\Ez\Twig\CalameoTwigExtension: From cae533c1a3a5c702e10774b6b750088d1dd4e1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 3 Jun 2026 16:44:54 +0200 Subject: [PATCH 29/36] services.yml --- src/bundles/EzBundle/Resources/config/services.yml | 11 +++++++++++ .../Type/FieldType/CalameoPublicationFieldType.php | 13 ++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/bundles/EzBundle/Resources/config/services.yml b/src/bundles/EzBundle/Resources/config/services.yml index 8a965e2..5ff8d54 100644 --- a/src/bundles/EzBundle/Resources/config/services.yml +++ b/src/bundles/EzBundle/Resources/config/services.yml @@ -11,6 +11,17 @@ services: # if you need to do this, you can override this setting on individual services public: false + AlmaviaCX\Calameo\: + # * AlmaviaCXCalameoBundle/src/ + # ** bundles/EzBundle/Resources/config/services.yml + # ** lib + # + # namespace AlmaviaCX\Calameo\Ez\Form\Type\FieldType; + resource: '../../../../lib/*' + exclude: + - '../../../../lib/**/Value/' + - '../../../../lib/**/Exception/' + AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\FormMapper: tags: - { name: ez.fieldFormMapper.definition, fieldType: calameo_publication } diff --git a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php index 6a3e028..86c50b5 100644 --- a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php +++ b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php @@ -17,6 +17,7 @@ use AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\Value; use Ibexa\ContentForms\Form\Type\FieldType\BinaryBaseFieldType; use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; +use JMS\TranslationBundle\Annotation\Desc; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -29,13 +30,11 @@ class CalameoPublicationFieldType extends AbstractType { - protected AccountRepository $accountRepository; - protected NotificationHandlerInterface $notificationHandler; - - public function __construct(AccountRepository $accountRepository, NotificationHandlerInterface $notificationHandler) + public function __construct( + protected readonly AccountRepository $accountRepository, + protected readonly NotificationHandlerInterface $notificationHandler + ) { - $this->accountRepository = $accountRepository; - $this->notificationHandler = $notificationHandler; } public function getName(): string @@ -48,7 +47,7 @@ public function getBlockPrefix(): string return 'ezplatform_fieldtype_calameo_publication'; } - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $folderChoices = []; $filteredFolderChoices = []; From f78edbba53b487ebbb768df37399501f87779f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 3 Jun 2026 16:53:29 +0200 Subject: [PATCH 30/36] code --- src/lib/API/Serializer.php | 8 ++--- .../CalameoPublication/FieldStorage.php | 26 ++++------------ .../CalameoPublication/FormMapper.php | 30 ++++++------------- .../Gateway/DoctrineStorage.php | 16 +++++----- .../CalameoPublication/LegacyConverter.php | 4 +-- .../Ez/FieldType/CalameoPublication/Value.php | 1 - .../CalameoPublication/ValueTransformer.php | 4 +-- .../FieldType/CalameoPublicationFieldType.php | 2 +- 8 files changed, 30 insertions(+), 61 deletions(-) diff --git a/src/lib/API/Serializer.php b/src/lib/API/Serializer.php index 02e7714..b86c919 100644 --- a/src/lib/API/Serializer.php +++ b/src/lib/API/Serializer.php @@ -13,15 +13,13 @@ namespace AlmaviaCX\Calameo\API; use AlmaviaCX\Calameo\API\Value\Response\Response; +use JMS\Serializer\SerializerInterface; use Psr\Http\Message\ResponseInterface; -class Serializer +readonly class Serializer { - protected \JMS\Serializer\SerializerInterface $baseSerializer; - - public function __construct(\JMS\Serializer\SerializerInterface $baseSerializer) + public function __construct(protected SerializerInterface $baseSerializer) { - $this->baseSerializer = $baseSerializer; } public function deserializeResponse( diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index 08bea75..c3bbc24 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -27,29 +27,14 @@ use Psr\Log\LoggerInterface; use SplFileInfo; -class FieldStorage implements FieldStorageInterface +readonly class FieldStorage implements FieldStorageInterface { - public PublicationRepository $publicationRepository; - public PublishingService $publishingService; - public DoctrineStorage $gateway; - public LoggerInterface $logger; - - /** - * @param PublicationRepository $publicationRepository - * @param PublishingService $publishingService - * @param DoctrineStorage $gateway - * @param LoggerInterface $logger - */ public function __construct( - PublicationRepository $publicationRepository, - PublishingService $publishingService, - DoctrineStorage $gateway, - LoggerInterface $logger + protected PublicationRepository $publicationRepository, + protected PublishingService $publishingService, + protected DoctrineStorage $gateway, + protected LoggerInterface $logger ) { - $this->publicationRepository = $publicationRepository; - $this->publishingService = $publishingService; - $this->gateway = $gateway; - $this->logger = $logger; } /** @@ -106,7 +91,6 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field): bool /** * @param VersionInfo $versionInfo * @param Field $field - * @param array $context * @throws Exception */ public function getFieldData(VersionInfo $versionInfo, Field $field,): void diff --git a/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php b/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php index 8fd6146..bfa72e6 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FormMapper.php @@ -15,11 +15,11 @@ use AlmaviaCX\Calameo\API\Repository\AccountRepository; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use AlmaviaCX\Calameo\Ez\Form\Type\FieldType\CalameoPublicationFieldType; -use EzSystems\RepositoryForms\Data\Content\FieldData; -use EzSystems\RepositoryForms\FieldType\FieldDefinitionFormMapperInterface; -use EzSystems\RepositoryForms\FieldType\FieldValueFormMapperInterface; +use Ibexa\AdminUi\FieldType\FieldDefinitionFormMapperInterface; use Ibexa\AdminUi\Form\Data\FieldDefinitionData; use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; +use Ibexa\Contracts\ContentForms\Data\Content\FieldData; +use Ibexa\Contracts\ContentForms\FieldType\FieldValueFormMapperInterface; use Ibexa\Contracts\Core\Repository\FieldTypeService; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormInterface; @@ -27,23 +27,11 @@ class FormMapper implements FieldValueFormMapperInterface, FieldDefinitionFormMapperInterface { - protected FieldTypeService $fieldTypeService; - protected AccountRepository $accountRepository; - protected NotificationHandlerInterface $notificationHandler; - - /** - * @param FieldTypeService $fieldTypeService - * @param AccountRepository $accountRepository - * @param NotificationHandlerInterface $notificationHandler - */ public function __construct( - FieldTypeService $fieldTypeService, - AccountRepository $accountRepository, - NotificationHandlerInterface $notificationHandler + protected readonly FieldTypeService $fieldTypeService, + protected readonly AccountRepository $accountRepository, + protected readonly NotificationHandlerInterface $notificationHandler ) { - $this->fieldTypeService = $fieldTypeService; - $this->accountRepository = $accountRepository; - $this->notificationHandler = $notificationHandler; } // f @@ -82,9 +70,9 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field ); } - public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data) + public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data): void { - $fieldDefinition = $data->fieldDefinition; + $fieldDefinition = $data->getFieldDefinition(); $formConfig = $fieldForm->getConfig(); $fieldType = $this->fieldTypeService->getFieldType($fieldDefinition->fieldTypeIdentifier); @@ -111,7 +99,7 @@ public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data) ); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver ->setDefaults( diff --git a/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php b/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php index 6668902..4ae889d 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php @@ -43,7 +43,7 @@ public function __construct(Connection $connection) * @return bool * @throws Exception */ - public function storePublicationReference(VersionInfo $versionInfo, Field $field) + public function storePublicationReference(VersionInfo $versionInfo, Field $field): bool { $referencedData = $this->getPublicationReferenceData($field->id, $versionInfo->versionNo); @@ -67,7 +67,7 @@ public function storePublicationReference(VersionInfo $versionInfo, Field $field * @param VersionInfo $versionInfo * @param Field $field */ - protected function setInsertColumns(QueryBuilder $queryBuilder, VersionInfo $versionInfo, Field $field) + protected function setInsertColumns(QueryBuilder $queryBuilder, VersionInfo $versionInfo, Field $field): void { $queryBuilder ->setValue('contentobject_attribute_id', ':fieldId') @@ -86,7 +86,7 @@ protected function setInsertColumns(QueryBuilder $queryBuilder, VersionInfo $ver * @param VersionInfo $versionInfo * @param Field $field */ - protected function setUpdateColumns(QueryBuilder $queryBuilder, VersionInfo $versionInfo, Field $field) + protected function setUpdateColumns(QueryBuilder $queryBuilder, VersionInfo $versionInfo, Field $field): void { $queryBuilder ->set('contentobject_attribute_id', ':fieldId') @@ -105,7 +105,7 @@ protected function setUpdateColumns(QueryBuilder $queryBuilder, VersionInfo $ver * @param Field $field * @throws Exception */ - protected function updateFieldData(VersionInfo $versionInfo, Field $field) + protected function updateFieldData(VersionInfo $versionInfo, Field $field): void { $updateQuery = $this->connection->createQueryBuilder(); $updateQuery->update( @@ -138,7 +138,7 @@ protected function updateFieldData(VersionInfo $versionInfo, Field $field) * @param Field $field * @throws Exception */ - protected function storeNewFieldData(VersionInfo $versionInfo, Field $field) + protected function storeNewFieldData(VersionInfo $versionInfo, Field $field): void { $insertQuery = $this->connection->createQueryBuilder(); $insertQuery->insert( @@ -158,7 +158,7 @@ protected function storeNewFieldData(VersionInfo $versionInfo, Field $field) * * @return mixed */ - protected function castToPropertyValue($value, string $columnName) + protected function castToPropertyValue(mixed $value, string $columnName): mixed { $propertyMap = $this->getPropertyMapping(); $castFunction = $propertyMap[$columnName]['cast']; @@ -177,7 +177,7 @@ protected function castToPropertyValue($value, string $columnName) * @param int $fieldId * @param int $versionNo */ - protected function setFetchColumns(QueryBuilder $queryBuilder, $fieldId, $versionNo) + protected function setFetchColumns(QueryBuilder $queryBuilder, $fieldId, $versionNo): void { $queryBuilder->select( $this->connection->quoteIdentifier('publication_id'), @@ -293,7 +293,7 @@ protected function toPropertyName(string $columnName): string * @param int $versionNo * @throws Exception */ - public function removePublicationReferences(array $fieldIds, int $versionNo) + public function removePublicationReferences(array $fieldIds, int $versionNo): void { if (empty($fieldIds)) { return; diff --git a/src/lib/Ez/FieldType/CalameoPublication/LegacyConverter.php b/src/lib/Ez/FieldType/CalameoPublication/LegacyConverter.php index 145d7ac..2190fa3 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/LegacyConverter.php +++ b/src/lib/Ez/FieldType/CalameoPublication/LegacyConverter.php @@ -29,13 +29,13 @@ public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue) { } - public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef) + public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef): void { $fieldSettings = $fieldDef->fieldTypeConstraints->fieldSettings; $storageDef->dataText1 = implode('|', $fieldSettings['availableFolderIds'] ?? []); } - public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef) + public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef): void { $fieldDef->fieldTypeConstraints->fieldSettings = [ 'availableFolderIds' => explode('|', $storageDef->dataText1 ?? "") diff --git a/src/lib/Ez/FieldType/CalameoPublication/Value.php b/src/lib/Ez/FieldType/CalameoPublication/Value.php index 9386575..4603e08 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Value.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Value.php @@ -13,7 +13,6 @@ namespace AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication; use AlmaviaCX\Calameo\API\Value\Publication; -use Closure; use Ibexa\Core\FieldType\Value as BaseValue; class Value extends BaseValue diff --git a/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php b/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php index 27c0156..ad86521 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php +++ b/src/lib/Ez/FieldType/CalameoPublication/ValueTransformer.php @@ -31,7 +31,7 @@ public function __construct(FieldType $fieldType, Value $initialValue) * @param Value|null $value * @return array */ - public function transform($value) + public function transform($value): array { if (null === $value) { $value = $this->fieldType->getEmptyValue(); @@ -49,7 +49,7 @@ public function transform($value) * @param array|null $value * @return Value */ - public function reverseTransform($value) + public function reverseTransform($value): mixed { if (!is_array($value)) { throw new TransformationFailedException(sprintf('Expected a array got %s', gettype($value))); diff --git a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php index 86c50b5..5f578f9 100644 --- a/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php +++ b/src/lib/Ez/Form/Type/FieldType/CalameoPublicationFieldType.php @@ -130,7 +130,7 @@ public function getParent(): string return BinaryBaseFieldType::class; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults( [ From 5d3e318ed6d9f0526762ae5c677ff82933673927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 3 Jun 2026 16:54:59 +0200 Subject: [PATCH 31/36] services.yml --- src/bundles/EzBundle/Resources/config/services.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bundles/EzBundle/Resources/config/services.yml b/src/bundles/EzBundle/Resources/config/services.yml index 5ff8d54..5660e83 100644 --- a/src/bundles/EzBundle/Resources/config/services.yml +++ b/src/bundles/EzBundle/Resources/config/services.yml @@ -18,9 +18,9 @@ services: # # namespace AlmaviaCX\Calameo\Ez\Form\Type\FieldType; resource: '../../../../lib/*' - exclude: - - '../../../../lib/**/Value/' - - '../../../../lib/**/Exception/' +# exclude: +# - '../../../../lib/**/Value/' +# - '../../../../lib/**/Exception/' AlmaviaCX\Calameo\Ez\FieldType\CalameoPublication\FormMapper: tags: From 243923025721e23652445bad5ae0fa6ddf1a7d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Mon, 8 Jun 2026 15:58:56 +0200 Subject: [PATCH 32/36] Fix ->setParameter(': --- .../Gateway/DoctrineStorage.php | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php b/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php index 4ae889d..532d7ce 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/Gateway/DoctrineStorage.php @@ -74,10 +74,10 @@ protected function setInsertColumns(QueryBuilder $queryBuilder, VersionInfo $ver ->setValue('publication_id', ':publicationId') ->setValue('folder_id', ':folderId') ->setValue('version', ':versionNo') - ->setParameter(':fieldId', $field->id, PDO::PARAM_INT) - ->setParameter(':publicationId', $field->value->externalData['publicationId'], PDO::PARAM_STR) - ->setParameter(':folderId', $field->value->externalData['folderId'], PDO::PARAM_INT) - ->setParameter(':versionNo', $versionInfo->versionNo, PDO::PARAM_INT) + ->setParameter('fieldId', $field->id, PDO::PARAM_INT) + ->setParameter('publicationId', $field->value->externalData['publicationId'], PDO::PARAM_STR) + ->setParameter('folderId', $field->value->externalData['folderId'], PDO::PARAM_INT) + ->setParameter('versionNo', $versionInfo->versionNo, PDO::PARAM_INT) ; } @@ -93,10 +93,10 @@ protected function setUpdateColumns(QueryBuilder $queryBuilder, VersionInfo $ver ->set('publication_id', ':publicationId') ->set('folder_id', ':folderId') ->set('version', ':versionNo') - ->setParameter(':fieldId', $field->id, PDO::PARAM_INT) - ->setParameter(':publicationId', $field->value->externalData['publicationId'], PDO::PARAM_STR) - ->setParameter(':folderId', $field->value->externalData['folderId'], PDO::PARAM_INT) - ->setParameter(':versionNo', $versionInfo->versionNo, PDO::PARAM_INT) + ->setParameter('fieldId', $field->id, PDO::PARAM_INT) + ->setParameter('publicationId', $field->value->externalData['publicationId'], PDO::PARAM_STR) + ->setParameter('folderId', $field->value->externalData['folderId'], PDO::PARAM_INT) + ->setParameter('versionNo', $versionInfo->versionNo, PDO::PARAM_INT) ; } @@ -126,8 +126,8 @@ protected function updateFieldData(VersionInfo $versionInfo, Field $field): void ) ) ) - ->setParameter(':fieldId', $field->id, PDO::PARAM_INT) - ->setParameter(':versionNo', $versionInfo->versionNo, PDO::PARAM_INT) + ->setParameter('fieldId', $field->id, PDO::PARAM_INT) + ->setParameter('versionNo', $versionInfo->versionNo, PDO::PARAM_INT) ; $updateQuery->execute(); @@ -214,8 +214,8 @@ public function getPublicationReferenceData(int $fieldId, int $versionNo): ?arra ) ) ) - ->setParameter(':fieldId', $fieldId, PDO::PARAM_INT) - ->setParameter(':versionNo', $versionNo, PDO::PARAM_INT) + ->setParameter('fieldId', $fieldId, PDO::PARAM_INT) + ->setParameter('versionNo', $versionNo, PDO::PARAM_INT) ; $statement = $selectQuery->execute(); @@ -261,7 +261,7 @@ public function getReferencedPublications(array $fieldIds): array ':fieldIds' ) ) - ->setParameter(':fieldIds', $fieldIds, Connection::PARAM_INT_ARRAY); + ->setParameter('fieldIds', $fieldIds, Connection::PARAM_INT_ARRAY); $statement = $selectQuery->execute(); $publicationIds = []; @@ -314,8 +314,8 @@ public function removePublicationReferences(array $fieldIds, int $versionNo): vo ) ) ) - ->setParameter(':fieldIds', $fieldIds, Connection::PARAM_INT_ARRAY) - ->setParameter(':versionNo', $versionNo, PDO::PARAM_INT) + ->setParameter('fieldIds', $fieldIds, Connection::PARAM_INT_ARRAY) + ->setParameter('versionNo', $versionNo, PDO::PARAM_INT) ; $deleteQuery->execute(); From c1e708773b3dc477cd7cb9f1c8b6422711e7f83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 1 Jul 2026 16:50:37 +0200 Subject: [PATCH 33/36] add CalameoController.php --- .../Controller/Admin/CalameoController.php | 272 ++++++++++++++++++ .../EzBundle/Resources/config/routes.yaml | 3 + .../EzBundle/Resources/config/services.yml | 8 + .../admin/calameo/content_list.html.twig | 97 +++++++ .../views/admin/calameo/index.html.twig | 51 ++++ .../admin/calameo/publication_list.html.twig | 45 +++ 6 files changed, 476 insertions(+) create mode 100644 src/bundles/EzBundle/Controller/Admin/CalameoController.php create mode 100644 src/bundles/EzBundle/Resources/config/routes.yaml create mode 100644 src/bundles/EzBundle/Resources/views/admin/calameo/content_list.html.twig create mode 100644 src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig create mode 100644 src/bundles/EzBundle/Resources/views/admin/calameo/publication_list.html.twig diff --git a/src/bundles/EzBundle/Controller/Admin/CalameoController.php b/src/bundles/EzBundle/Controller/Admin/CalameoController.php new file mode 100644 index 0000000..a429d0c --- /dev/null +++ b/src/bundles/EzBundle/Controller/Admin/CalameoController.php @@ -0,0 +1,272 @@ +tableExists(self::TABLE_NAME); + + return $this->render('@EzCalameo/admin/calameo/index.html.twig', [ + 'field_type_identifier' => self::FIELD_TYPE_IDENTIFIER, + 'table_name' => self::TABLE_NAME, + 'table_exists' => $tableExists, + 'configuration' => [ + 'almaviacx.calameo.api.key' => $this->APIKey, + 'almaviacx.calameo.api.secret' => str_repeat('*', strlen($this->APISecret)), + 'almaviacx.calameo.http_client.config' => $this->config, + ], + 'stats' => [ + 'field_definitions' => $this->countCalameoFieldDefinitions(), + 'contents' => $this->countContentsWithCalameoField(), + 'publications' => $tableExists ? $this->countCalameoPublications() : null, + ], + ]); + } + + #[Route('/contents', name: 'content_list', methods: ['GET'])] + public function contentList(Request $request): Response + { + $page = max(1, $request->query->getInt('page', 1)); + $limit = min(100, max(1, $request->query->getInt('limit', 25))); + $offset = ($page - 1) * $limit; + + $calameoContentTypes = $this->getContentTypesWithCalameoPublicationField(); + + if ($calameoContentTypes === []) { + return $this->render('@EzCalameo/admin/calameo/content_list.html.twig', [ + 'items' => [], + 'table_exists' => $this->tableExists(self::TABLE_NAME), + 'pagination' => [ + 'page' => $page, + 'limit' => $limit, + 'total' => 0, + 'pages' => 0, + 'has_previous' => false, + 'has_next' => false, + ], + ]); + } + + $query = new Query([ + 'filter' => new Criterion\ContentTypeIdentifier( + array_column($calameoContentTypes, 'identifier') + ), + 'limit' => $limit, + 'offset' => $offset, + ]); + $query->sortClauses = [new Query\SortClause\ContentId()]; + + $searchResult = $this->searchService->findContent($query); + + $items = []; + $tableExists = $this->tableExists(self::TABLE_NAME); + + foreach ($searchResult->searchHits as $searchHit) { + $content = $searchHit->valueObject; + $contentTypeId = $content->contentInfo->contentTypeId; + + if (!isset($calameoContentTypes[$contentTypeId])) { + continue; + } + + foreach ($calameoContentTypes[$contentTypeId]['fields'] as $fieldIdentifier) { + $field = $content->getField($fieldIdentifier); + + $publicationReference = null; + + if ($field !== null && $tableExists) { + $publicationReference = $this->getCalameoPublicationReference( + (int) $field->id, + (int) $content->versionInfo->versionNo, + ); + } + + $items[] = [ + 'content_id' => $content->contentInfo->id, + 'content_name' => $content->contentInfo->name, + 'content_type_identifier' => $calameoContentTypes[$contentTypeId]['identifier'], + 'field_identifier' => $fieldIdentifier, + 'field_id' => $field?->id, + 'version' => $content->versionInfo->versionNo, + 'publication_id' => $publicationReference['publication_id'] ?? null, + 'folder_id' => $publicationReference['folder_id'] ?? null, + 'content_view_url' => sprintf('/view/content/%d', $content->contentInfo->id), + ]; + } + } + + $total = $searchResult->totalCount; + $pages = (int) ceil($total / $limit); + + return $this->render('@EzCalameo/admin/calameo/content_list.html.twig', [ + 'items' => $items, + 'table_exists' => $tableExists, + 'pagination' => [ + 'page' => $page, + 'limit' => $limit, + 'total' => $total, + 'pages' => $pages, + 'has_previous' => $page > 1, + 'has_next' => $page < $pages, + ], + ]); + } + + #[Route('/publications', name: 'publication_list', methods: ['GET'])] + public function calameoPublicationList(): Response + { + if (!$this->tableExists(self::TABLE_NAME)) { + return $this->render('@EzCalameo/admin/calameo/publication_list.html.twig', [ + 'items' => [], + 'table_exists' => false, + ]); + } + + $items = $this->connection->fetchAllAssociative( + <<render('@EzCalameo/admin/calameo/publication_list.html.twig', [ + 'items' => $items, + 'table_exists' => true, + ]); + } + + private function countCalameoPublications(): int + { + return (int) $this->connection->fetchOne( + 'SELECT COUNT(*) FROM calameo_publication', + ); + } + + private function tableExists(string $tableName): bool + { + try { + return $this->connection + ->createSchemaManager() + ->tablesExist([$tableName]); + } catch (\Throwable) { + return false; + } + } + + private function getContentTypesWithCalameoPublicationField(): array + { + $result = []; + + foreach ($this->contentTypeService->loadContentTypeGroups() as $contentTypeGroup) { + foreach ($this->contentTypeService->loadContentTypes($contentTypeGroup) as $contentType) { + $fieldIdentifiers = []; + + foreach ($contentType->getFieldDefinitions() as $fieldDefinition) { + if ($fieldDefinition->fieldTypeIdentifier !== self::FIELD_TYPE_IDENTIFIER) { + continue; + } + + $fieldIdentifiers[] = $fieldDefinition->identifier; + } + + if ($fieldIdentifiers === []) { + continue; + } + + $result[$contentType->id] = [ + 'id' => $contentType->id, + 'identifier' => $contentType->identifier, + 'fields' => $fieldIdentifiers, + ]; + } + } + + return $result; + } + + private function getCalameoPublicationReference(int $fieldId, int $version): ?array + { + return $this->connection->fetchAssociative( + << $fieldId, + 'version' => $version, + ], + ) ?: null; + } + + private function countCalameoFieldDefinitions(): int + { + $count = 0; + + foreach ($this->getContentTypesWithCalameoPublicationField() as $contentTypeData) { + $count += count($contentTypeData['fields']); + } + + return $count; + } + + private function countContentsWithCalameoField(): int + { + $calameoContentTypes = $this->getContentTypesWithCalameoPublicationField(); + + if ($calameoContentTypes === []) { + return 0; + } + + $query = new Query([ + 'filter' => new Criterion\ContentTypeIdentifier( + array_column($calameoContentTypes, 'identifier') + ), + 'limit' => 0, + ]); + + return $this->searchService->findContent($query)->totalCount; + } +} diff --git a/src/bundles/EzBundle/Resources/config/routes.yaml b/src/bundles/EzBundle/Resources/config/routes.yaml new file mode 100644 index 0000000..1356293 --- /dev/null +++ b/src/bundles/EzBundle/Resources/config/routes.yaml @@ -0,0 +1,3 @@ +almaviacx_calameo_admin: + resource: '../../Controller/Admin/' + type: attribute diff --git a/src/bundles/EzBundle/Resources/config/services.yml b/src/bundles/EzBundle/Resources/config/services.yml index 5660e83..185f5ab 100644 --- a/src/bundles/EzBundle/Resources/config/services.yml +++ b/src/bundles/EzBundle/Resources/config/services.yml @@ -40,3 +40,11 @@ services: factory: ['@AlmaviaCX\Calameo\API\HttpClientFactory', 'create'] AlmaviaCX\Calameo\Ez\Twig\CalameoTwigExtension: + + AlmaviaCX\Bundle\Calameo\EzBundle\Controller\: + resource: '../../Controller/' + arguments: + $APIKey: "%almaviacx.calameo.api.key%" + $APISecret: "%almaviacx.calameo.api.secret%" + $config: "%almaviacx.calameo.http_client.config%" + tags: ['controller.service_arguments'] diff --git a/src/bundles/EzBundle/Resources/views/admin/calameo/content_list.html.twig b/src/bundles/EzBundle/Resources/views/admin/calameo/content_list.html.twig new file mode 100644 index 0000000..f75ab8d --- /dev/null +++ b/src/bundles/EzBundle/Resources/views/admin/calameo/content_list.html.twig @@ -0,0 +1,97 @@ +{# Resources/views/admin/calameo/content_list.html.twig #} + +

Contenus avec champ Calaméo

+ + + +

+ {{ pagination.total }} contenu{{ pagination.total > 1 ? 's' : '' }} trouvé{{ pagination.total > 1 ? 's' : '' }}. + Page {{ pagination.page }}{% if pagination.pages > 0 %} / {{ pagination.pages }}{% endif %}. +

+ + + + + + + + + + + + + + + + {% for item in items %} + + + + + + + + + + + {% else %} + + + + {% endfor %} + +
Content IDNomTypeChampField IDVersionPublication IDFolder ID
+ + {{ item.content_id }} + + {{ item.content_name }}{{ item.content_type_identifier }}{{ item.field_identifier }}{{ item.field_id }}{{ item.version }} + {% if item.publication_id %} + + {% endif %} + {{ item.folder_id }}
Aucun contenu trouvé.
+ +{% if pagination.pages > 1 %} + +{% endif %} diff --git a/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig b/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig new file mode 100644 index 0000000..fb0ac13 --- /dev/null +++ b/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig @@ -0,0 +1,51 @@ +{# Resources/views/admin/calameo/index.html.twig #} + +

Calaméo

+ + + +

Configuration

+ + + + + + + + + + + + + + + + + {% for key, value in configuration %} + + + + + {% endfor %} + +
FieldType{{ field_type_identifier }}
Table{{ table_name }}
Table présente{{ table_exists ? 'oui' : 'non' }}
{{ key }} + {% if value is iterable %} +
{{ value|json_encode(constant('JSON_PRETTY_PRINT')) }}
+ {% else %} + {{ value ?? 'non configuré' }} + {% endif %} +
+ +

Statistiques

+ +
    +
  • Définitions de champ Calaméo : {{ stats.field_definitions }}
  • +
  • Contenus avec champ Calaméo : {{ stats.contents }}
  • +
  • Entrées dans calameo_publication : {{ stats.publications ?? 'table absente' }}
  • +
diff --git a/src/bundles/EzBundle/Resources/views/admin/calameo/publication_list.html.twig b/src/bundles/EzBundle/Resources/views/admin/calameo/publication_list.html.twig new file mode 100644 index 0000000..d246fdb --- /dev/null +++ b/src/bundles/EzBundle/Resources/views/admin/calameo/publication_list.html.twig @@ -0,0 +1,45 @@ +{# Resources/views/admin/calameo/publication_list.html.twig #} + +

Table calameo_publication

+ + + +{% if not table_exists %} +

La table calameo_publication n’existe pas.

+{% else %} + + + + + + + + + + + {% for item in items %} + + + + + + + {% else %} + + + + {% endfor %} + +
Attribute IDVersionPublication IDFolder ID
{{ item.contentobject_attribute_id }}{{ item.version }} + {% if item.publication_id %} + + {% endif %} + {{ item.folder_id }}
Aucune entrée trouvée.
+{% endif %} From fdfed5754d4fbc434fe8b3b7d8cfa2a00719868e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 1 Jul 2026 17:00:15 +0200 Subject: [PATCH 34/36] add link to https://www.calameo.com/account/dashboard --- .../EzBundle/Resources/views/admin/calameo/index.html.twig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig b/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig index fb0ac13..af59c72 100644 --- a/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig +++ b/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig @@ -12,6 +12,8 @@

Configuration

+https://www.calameo.com/account/dashboard + From 9a5c7c019c1f1e0898f7525e480b1903e5a0b2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Wed, 1 Jul 2026 18:04:57 +0200 Subject: [PATCH 35/36] Fix JS Fix Delete Fix copyLegacyField --- .../Resources/encore/ez.config.manager.js | 29 ------ .../encore/{ez.config.js => ibexa.config.js} | 0 .../Resources/encore/ibexa.config.manager.js | 19 ++++ .../scripts/fieldType/calameo_publication.js | 52 ++++++---- .../CalameoPublication/FieldStorage.php | 95 +++++++++++++++---- 5 files changed, 131 insertions(+), 64 deletions(-) delete mode 100644 src/bundles/EzBundle/Resources/encore/ez.config.manager.js rename src/bundles/EzBundle/Resources/encore/{ez.config.js => ibexa.config.js} (100%) create mode 100644 src/bundles/EzBundle/Resources/encore/ibexa.config.manager.js diff --git a/src/bundles/EzBundle/Resources/encore/ez.config.manager.js b/src/bundles/EzBundle/Resources/encore/ez.config.manager.js deleted file mode 100644 index 5688f8b..0000000 --- a/src/bundles/EzBundle/Resources/encore/ez.config.manager.js +++ /dev/null @@ -1,29 +0,0 @@ -/* - * NovaeZMenuManagerBundle. - * - * @package NovaeZMenuManagerBundle - * - * @author florian - * @copyright 2019 Novactive - * @license https://github.com/Novactive/NovaeZMenuManagerBundle/blob/master/LICENSE - * - */ - -const path = require('path') - -module.exports = (eZConfig, eZConfigManager) => { - eZConfigManager.add({ - eZConfig, - entryName: 'ezplatform-admin-ui-content-edit-parts-css', - newItems: [ - path.resolve(__dirname, '../public/scss/fieldType/edit/calameo_publication.scss') - ] - }) - eZConfigManager.add({ - eZConfig, - entryName: 'ezplatform-admin-ui-content-edit-parts-js', - newItems: [ - path.resolve(__dirname, '../public/js/scripts/fieldType/calameo_publication.js') - ] - }) -} diff --git a/src/bundles/EzBundle/Resources/encore/ez.config.js b/src/bundles/EzBundle/Resources/encore/ibexa.config.js similarity index 100% rename from src/bundles/EzBundle/Resources/encore/ez.config.js rename to src/bundles/EzBundle/Resources/encore/ibexa.config.js diff --git a/src/bundles/EzBundle/Resources/encore/ibexa.config.manager.js b/src/bundles/EzBundle/Resources/encore/ibexa.config.manager.js new file mode 100644 index 0000000..723ce0f --- /dev/null +++ b/src/bundles/EzBundle/Resources/encore/ibexa.config.manager.js @@ -0,0 +1,19 @@ +const path = require('path'); + +module.exports = (ibexaConfig, ibexaConfigManager) => { + ibexaConfigManager.add({ + ibexaConfig, + entryName: 'ibexa-admin-ui-content-edit-parts-css', + newItems: [ + path.resolve(__dirname, '../public/scss/fieldType/edit/calameo_publication.scss'), + ], + }); + + ibexaConfigManager.add({ + ibexaConfig, + entryName: 'ibexa-admin-ui-content-edit-parts-js', + newItems: [ + path.resolve(__dirname, '../public/js/scripts/fieldType/calameo_publication.js'), + ], + }); +}; diff --git a/src/bundles/EzBundle/Resources/public/js/scripts/fieldType/calameo_publication.js b/src/bundles/EzBundle/Resources/public/js/scripts/fieldType/calameo_publication.js index f99a288..a9e2f3e 100644 --- a/src/bundles/EzBundle/Resources/public/js/scripts/fieldType/calameo_publication.js +++ b/src/bundles/EzBundle/Resources/public/js/scripts/fieldType/calameo_publication.js @@ -1,54 +1,68 @@ (function (global) { + console.log('calameo_publication.js') + const ibexa = global.ibexa || global.eZ; + + if (!ibexa || !ibexa.BasePreviewField || !ibexa.BaseFileFieldValidator) { + console.warn('[Calameo] Ibexa file field helpers are not available.'); + return; + } + const SELECTOR_FIELD = '.ibexa-field-edit--calameo_publication'; const SELECTOR_LABEL_WRAPPER = '.ibexa-field-edit__label-wrapper'; - class CalameoPublicationPreviewField extends global.eZ.BasePreviewField { - /** - * Loads dropped file preview - * - * @param {Event} event - */ + class CalameoPublicationPreviewField extends ibexa.BasePreviewField { loadDroppedFilePreview(event) { const preview = this.fieldContainer.querySelector('.ibexa-field-edit__preview'); + + if (!preview || !event.target.files || !event.target.files.length) { + return; + } + + const file = event.target.files[0]; const nameContainer = preview.querySelector('.ibexa-field-edit-preview__file-name'); - const files = [].slice.call(event.target.files); + const previewLink = preview.querySelector('.ibexa-field-edit-preview__action--preview'); - nameContainer.innerHTML = files[0].name; - nameContainer.title = files[0].name; + if (nameContainer) { + nameContainer.innerHTML = file.name; + nameContainer.title = file.name; + } - preview.querySelector('.ibexa-field-edit-preview__action--preview').href = URL.createObjectURL(files[0]); + if (previewLink) { + previewLink.href = URL.createObjectURL(file); + } } } - [...document.querySelectorAll(SELECTOR_FIELD)].forEach(fieldContainer => { - const validator = new global.eZ.BaseFileFieldValidator({ + [...document.querySelectorAll(SELECTOR_FIELD)].forEach((fieldContainer) => { + const validator = new ibexa.BaseFileFieldValidator({ classInvalid: 'is-invalid', fieldContainer, eventsMap: [ { - selector: `input[type="file"]`, + selector: 'input[type="file"]', eventName: 'change', callback: 'validateInput', errorNodeSelectors: [SELECTOR_LABEL_WRAPPER], }, { isValueValidator: false, - selector: `input[type="file"]`, + selector: 'input[type="file"]', eventName: 'invalidFileSize', callback: 'showFileSizeError', errorNodeSelectors: [SELECTOR_LABEL_WRAPPER], }, ], }); + const previewField = new CalameoPublicationPreviewField({ validator, - fieldContainer + fieldContainer, }); previewField.init(); - global.eZ.fieldTypeValidators = global.eZ.fieldTypeValidators ? - [...global.eZ.fieldTypeValidators, validator] : - [validator]; - }) + ibexa.fieldTypeValidators = ibexa.fieldTypeValidators + ? [...ibexa.fieldTypeValidators, validator] + : [validator]; + }); })(window); diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index c3bbc24..fe695b5 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -26,14 +26,16 @@ use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; use Psr\Log\LoggerInterface; use SplFileInfo; +use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; readonly class FieldStorage implements FieldStorageInterface { public function __construct( protected PublicationRepository $publicationRepository, - protected PublishingService $publishingService, - protected DoctrineStorage $gateway, - protected LoggerInterface $logger + protected PublishingService $publishingService, + protected DoctrineStorage $gateway, + protected LoggerInterface $logger, + protected ConfigResolverInterface $configResolver, ) { } @@ -118,18 +120,38 @@ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void $publicationIds = $this->gateway->getReferencedPublications($fieldIds); $versionPublicationId = $publicationIds[$versionInfo->versionNo] ?? null; + + // On supprime toujours la référence locale. + // La suppression dans Ibexa ne doit pas être bloquée par une config API Calaméo absente. $this->gateway->removePublicationReferences($fieldIds, $versionInfo->versionNo); $versionWithPublication = array_keys($publicationIds, $versionPublicationId); - if (count($versionWithPublication) <= 1 && $versionPublicationId) { - try { - $this->publicationRepository->deletePublication($versionPublicationId); - } catch (UnknownBookIDException $exception) { - return ; - } catch (ApiResponseErrorException $exception) { - $this->logger->error($exception->getMessage()); - return ; - } + + if (count($versionWithPublication) > 1 || !$versionPublicationId) { + return; + } + + if (!$this->isCalameoApiConfigured()) { + $this->logger->warning(sprintf( + '[Calameo] Suppression distante ignorée pour la publication "%s" : API key/secret non configurés.', + $versionPublicationId + )); + + return; + } + + try { + $this->publicationRepository->deletePublication($versionPublicationId); + } catch (UnknownBookIDException) { + return; + } catch (ApiResponseErrorException|GuzzleException $exception) { + $this->logger->error(sprintf( + '[Calameo] Impossible de supprimer la publication distante "%s" : %s', + $versionPublicationId, + $exception->getMessage() + )); + + return; } } @@ -151,12 +173,53 @@ public function getIndexData(VersionInfo $versionInfo, Field $field, array $cont { } - public function copyLegacyField(VersionInfo $versionInfo, Field $field, Field $originalField, array $context): bool - { - if ($originalField->value->externalData === null) { + public function copyLegacyField( + VersionInfo $versionInfo, + Field $field, + Field $originalField, + array $context = [] + ): bool { + $externalData = $originalField->value->externalData ?? null; + + if (!is_array($externalData)) { + return false; + } + + if (empty($externalData['publicationId']) || empty($externalData['folderId'])) { return false; } - return $this->gateway->storePublicationReference($versionInfo, $field); + $field->value->externalData = [ + 'publicationId' => $externalData['publicationId'], + 'folderId' => $externalData['folderId'], + ]; + + $this->gateway->storePublicationReference($versionInfo, $field); + + return true; + } + + private function isCalameoApiConfigured(): bool + { + return $this->getCalameoConfigString('api.key') !== '' + && $this->getCalameoConfigString('api.secret') !== ''; + } + + private function getCalameoConfigString(string $name): string + { + try { + $value = $this->configResolver->getParameter( + sprintf('calameo.%s', $name), + 'almaviacx' + ); + } catch (\Throwable) { + return ''; + } + + if (!is_scalar($value)) { + return ''; + } + + return trim((string) $value); } } From 87cd5e29ba58e9ef372ce7a8b42ee1a2eb4f01e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Thu, 2 Jul 2026 12:12:22 +0200 Subject: [PATCH 36/36] Add almaviacx.calameo.delete_book_enable --- .../APIBundle/Resources/config/services.yml | 9 ++++- .../Controller/Admin/CalameoController.php | 28 +++++++------- .../EzBundle/Resources/config/services.yml | 1 + .../admin/calameo/content_list.html.twig | 37 +++++++++++++++---- .../views/admin/calameo/index.html.twig | 26 ++++++++++++- .../admin/calameo/publication_list.html.twig | 37 +++++++++++++++---- .../API/Repository/PublicationRepository.php | 22 ++++++++--- .../CalameoPublication/FieldStorage.php | 16 +++++++- 8 files changed, 137 insertions(+), 39 deletions(-) diff --git a/src/bundles/APIBundle/Resources/config/services.yml b/src/bundles/APIBundle/Resources/config/services.yml index 18bd789..0a46a7d 100644 --- a/src/bundles/APIBundle/Resources/config/services.yml +++ b/src/bundles/APIBundle/Resources/config/services.yml @@ -1,7 +1,8 @@ parameters: - almaviacx.calameo.api.key: ~ - almaviacx.calameo.api.secret: ~ + almaviacx.calameo.api.key: '' + almaviacx.calameo.api.secret: '' almaviacx.calameo.http_client.config: [] + almaviacx.calameo.delete_book_enable: false services: # default configuration for services in *this* file @@ -35,3 +36,7 @@ services: resource: "../../../../lib/API/Service/*" AlmaviaCX\Calameo\Exception\ExceptionThrower: + + AlmaviaCX\Calameo\API\Repository\PublicationRepository: + arguments: + $deleteBookEnable: "%almaviacx.calameo.delete_book_enable%" diff --git a/src/bundles/EzBundle/Controller/Admin/CalameoController.php b/src/bundles/EzBundle/Controller/Admin/CalameoController.php index a429d0c..2988a82 100644 --- a/src/bundles/EzBundle/Controller/Admin/CalameoController.php +++ b/src/bundles/EzBundle/Controller/Admin/CalameoController.php @@ -6,32 +6,31 @@ use Doctrine\DBAL\Connection; use Ibexa\ActivityLog\REST\Input\Parser\SortClause\SortClause; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Attribute\Route; -use Symfony\Component\Security\Http\Attribute\IsGranted; use Ibexa\Contracts\Core\Repository\ContentTypeService; use Ibexa\Contracts\Core\Repository\SearchService; use Ibexa\Contracts\Core\Repository\Values\Content\Query; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/admin/calameo', name: 'almaviacx_calameo_admin_')] #[IsGranted('IS_AUTHENTICATED_FULLY')] final class CalameoController extends AbstractController { - private const FIELD_TYPE_IDENTIFIER = 'calameo_publication'; - private const TABLE_NAME = 'calameo_publication'; + private const string FIELD_TYPE_IDENTIFIER = 'calameo_publication'; + private const string TABLE_NAME = 'calameo_publication'; public function __construct( - private readonly Connection $connection, - private readonly ParameterBagInterface $parameterBag, + private readonly Connection $connection, private readonly ContentTypeService $contentTypeService, - private readonly SearchService $searchService, - private string $APIKey, - private string $APISecret, - private array $config, + private readonly SearchService $searchService, + private readonly string $APIKey, + private readonly string $APISecret, + private readonly array $config, + private readonly bool $deleteBookEnable, ) { } @@ -48,6 +47,7 @@ public function index(): Response 'almaviacx.calameo.api.key' => $this->APIKey, 'almaviacx.calameo.api.secret' => str_repeat('*', strlen($this->APISecret)), 'almaviacx.calameo.http_client.config' => $this->config, + 'almaviacx.calameo.delete_book_enable' => $this->deleteBookEnable, ], 'stats' => [ 'field_definitions' => $this->countCalameoFieldDefinitions(), @@ -88,7 +88,7 @@ public function contentList(Request $request): Response 'limit' => $limit, 'offset' => $offset, ]); - $query->sortClauses = [new Query\SortClause\ContentId()]; + $query->sortClauses = [new Query\SortClause\ContentId(Query::SORT_DESC)]; $searchResult = $this->searchService->findContent($query); diff --git a/src/bundles/EzBundle/Resources/config/services.yml b/src/bundles/EzBundle/Resources/config/services.yml index 185f5ab..c4a8e06 100644 --- a/src/bundles/EzBundle/Resources/config/services.yml +++ b/src/bundles/EzBundle/Resources/config/services.yml @@ -47,4 +47,5 @@ services: $APIKey: "%almaviacx.calameo.api.key%" $APISecret: "%almaviacx.calameo.api.secret%" $config: "%almaviacx.calameo.http_client.config%" + $deleteBookEnable: "%almaviacx.calameo.delete_book_enable%" tags: ['controller.service_arguments'] diff --git a/src/bundles/EzBundle/Resources/views/admin/calameo/content_list.html.twig b/src/bundles/EzBundle/Resources/views/admin/calameo/content_list.html.twig index f75ab8d..087429f 100644 --- a/src/bundles/EzBundle/Resources/views/admin/calameo/content_list.html.twig +++ b/src/bundles/EzBundle/Resources/views/admin/calameo/content_list.html.twig @@ -1,13 +1,32 @@ {# Resources/views/admin/calameo/content_list.html.twig #} +{% extends '@ibexadesign/ui/layout.html.twig' %} -

Contenus avec champ Calaméo

+{% block title %}Contenus avec champ Calaméo{% endblock %} - +{% block page_title %} + {% include '@ibexadesign/ui/page_title.html.twig' with { + title: 'Contenus avec champ Calaméo', + icon_name: 'catalog' + } %} +{% endblock %} +{% block breadcrumbs %} + {% include '@ibexadesign/ui/breadcrumbs.html.twig' with { + items: [ + { + value: 'Configuration CALAMEO', + url: path('almaviacx_calameo_admin_index') + }, + { + value: 'Contenus avec champ Calaméo', + url: path('almaviacx_calameo_admin_publication_list') + }, + ] + } %} +{% endblock %} + + +{% block content %}

{{ pagination.total }} contenu{{ pagination.total > 1 ? 's' : '' }} trouvé{{ pagination.total > 1 ? 's' : '' }}. Page {{ pagination.page }}{% if pagination.pages > 0 %} / {{ pagination.pages }}{% endif %}. @@ -42,8 +61,8 @@

@@ -95,3 +114,5 @@ {% endif %} {% endif %} + +{% endblock %} diff --git a/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig b/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig index af59c72..309675f 100644 --- a/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig +++ b/src/bundles/EzBundle/Resources/views/admin/calameo/index.html.twig @@ -1,7 +1,29 @@ {# Resources/views/admin/calameo/index.html.twig #} -

Calaméo

+{% extends '@ibexadesign/ui/layout.html.twig' %} +{% block title %}Calaméo{% endblock %} + +{% block page_title %} + {% include '@ibexadesign/ui/page_title.html.twig' with { + title: 'Calaméo', + icon_name: 'catalog' + } %} +{% endblock %} + +{% block breadcrumbs %} + {% include '@ibexadesign/ui/breadcrumbs.html.twig' with { + items: [ + { + value: 'Calaméo', + url: path('almaviacx_calameo_admin_index') + }, + ] + } %} +{% endblock %} + + +{% block content %} @@ -43,3 +62,5 @@
{% if item.publication_id %} {% endif %} {% if item.publication_id %} {% endif %}
{% endif %} + +{% endblock %} diff --git a/src/lib/API/Repository/PublicationRepository.php b/src/lib/API/Repository/PublicationRepository.php index 8377375..af51628 100644 --- a/src/lib/API/Repository/PublicationRepository.php +++ b/src/lib/API/Repository/PublicationRepository.php @@ -16,14 +16,16 @@ use AlmaviaCX\Calameo\API\Value\Publication; use AlmaviaCX\Calameo\Exception\ApiResponseErrorException; use GuzzleHttp\Exception\GuzzleException; +use Psr\Log\LoggerInterface; class PublicationRepository { - protected PublicationGateway $gateway; - - public function __construct(PublicationGateway $gateway) + public function __construct( + protected PublicationGateway $gateway, + protected bool $deleteBookEnable = false, + private readonly ?LoggerInterface $logger = null, + ) { - $this->gateway = $gateway; } /** @@ -39,13 +41,23 @@ public function getPublicationInfos(string $publicationId): Publication /** * @param string $publicationId - * @return bool + * @return bool Return false if deleteBookEnable is false * @throws ApiResponseErrorException * @throws GuzzleException */ public function deletePublication(string $publicationId): bool { + if (!$this->deleteBookEnable) { + $this->logger?->info(sprintf( + '[Calameo] Suppression distante ignorée pour la publication "%s" : almaviacx.calameo.delete_book_enable=false.', + $publicationId + )); + + return false; + } + $this->gateway->deleteBook($publicationId); + return true; } } diff --git a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php index fe695b5..c97881a 100644 --- a/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php +++ b/src/lib/Ez/FieldType/CalameoPublication/FieldStorage.php @@ -24,9 +24,9 @@ use Ibexa\Contracts\Core\FieldType\FieldStorage as FieldStorageInterface; use Ibexa\Contracts\Core\Persistence\Content\Field; use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; +use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Psr\Log\LoggerInterface; use SplFileInfo; -use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; readonly class FieldStorage implements FieldStorageInterface { @@ -140,6 +140,15 @@ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void return; } + if (!$this->isCalameoDeleteBookEnable()) { + $this->logger->warning(sprintf( + '[Calameo] Suppression distante ignorée pour la publication "%s" : delete_book_enable=false.', + $versionPublicationId + )); + + return; + } + try { $this->publicationRepository->deletePublication($versionPublicationId); } catch (UnknownBookIDException) { @@ -205,6 +214,11 @@ private function isCalameoApiConfigured(): bool && $this->getCalameoConfigString('api.secret') !== ''; } + private function isCalameoDeleteBookEnable(): bool + { + return $this->getCalameoConfigString('delete_book_enable') === '1'; + } + private function getCalameoConfigString(string $name): string { try {