From 23bb5382465bca368eee9f6de54909ee7c6d176f Mon Sep 17 00:00:00 2001 From: Aina Sitraka <35221835+aynsix@users.noreply.github.com> Date: Mon, 30 Oct 2023 23:14:07 +0300 Subject: [PATCH] PHRAS-3935 : phraseanet_local_id became instance_id (#4396) * phraseanet_local_id patch * display phraseanet_local_id * phraseanet_local_id to instance_id * update embed bumdle --- composer.json | 2 +- composer.lock | 14 +-- .../Controller/PSAdminController.php | 9 -- .../Controller/PSExposeController.php | 4 +- lib/Alchemy/Phrasea/Setup/Installer.php | 3 + .../Worker/ExposeUploadWorker.php | 10 +-- lib/classes/patch/418RC7PHRAS3935.php | 85 +++++++++++++++++++ .../admin/phraseanet-service/index.html.twig | 4 + 8 files changed, 107 insertions(+), 24 deletions(-) create mode 100644 lib/classes/patch/418RC7PHRAS3935.php diff --git a/composer.json b/composer.json index cbfd54d9b0..4908038d4e 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ "php": ">=7.0 <7.1", "ext-intl": "*", "alchemy-fr/tcpdf-clone": "~6.0", - "alchemy/embed-bundle": "^2.0.15", + "alchemy/embed-bundle": "^2.0.16", "alchemy/geonames-api-consumer": "~0.1.0", "alchemy/mediavorus": "^0.4.4", "alchemy/oauth2php": "1.1.0", diff --git a/composer.lock b/composer.lock index 3e813cdb76..38a205b024 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9e7490439544a7184da9a64bd9f3012f", + "content-hash": "08ce5acbe4eab8cb20d1881545d60071", "packages": [ { "name": "alchemy-fr/tcpdf-clone", @@ -131,16 +131,16 @@ }, { "name": "alchemy/embed-bundle", - "version": "2.0.15", + "version": "2.0.16", "source": { "type": "git", "url": "https://github.com/alchemy-fr/embed-bundle.git", - "reference": "835a6b0cfce6b966df1b73c3a651a742ebe9449a" + "reference": "81b67d90d1720f9ff49ee4033f6d1b61b56e4809" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alchemy-fr/embed-bundle/zipball/835a6b0cfce6b966df1b73c3a651a742ebe9449a", - "reference": "835a6b0cfce6b966df1b73c3a651a742ebe9449a", + "url": "https://api.github.com/repos/alchemy-fr/embed-bundle/zipball/81b67d90d1720f9ff49ee4033f6d1b61b56e4809", + "reference": "81b67d90d1720f9ff49ee4033f6d1b61b56e4809", "shasum": "" }, "require-dev": { @@ -178,10 +178,10 @@ ], "description": "Embed resources bundle", "support": { - "source": "https://github.com/alchemy-fr/embed-bundle/tree/2.0.15", + "source": "https://github.com/alchemy-fr/embed-bundle/tree/2.0.16", "issues": "https://github.com/alchemy-fr/embed-bundle/issues" }, - "time": "2023-10-14T10:42:19+00:00" + "time": "2023-10-19T11:28:29+00:00" }, { "name": "alchemy/geonames-api-consumer", diff --git a/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSAdminController.php b/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSAdminController.php index 1220c8f14a..7188fb8d24 100644 --- a/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSAdminController.php +++ b/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSAdminController.php @@ -35,15 +35,6 @@ public function exposeAction(PhraseaApplication $app, Request $request) if ($form->isValid()) { $app['conf']->set(['phraseanet-service', 'expose-service'], $form->getData()); - // generate a uniq key between phraseanet service and the phraseanet instance if not exist - if(!$app['conf']->has(['phraseanet-service', 'phraseanet_local_id'])) { - $instanceKey = $this->app['conf']->get(['main', 'key']); - - $phraseanetLocalId = md5($instanceKey); - - $app['conf']->set(['phraseanet-service', 'phraseanet_local_id'], $phraseanetLocalId); - } - return $app->redirectPath('ps_admin', ['_fragment'=>'expose']); } diff --git a/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php b/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php index 63f4d25cac..7da8e5e3cf 100644 --- a/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php +++ b/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php @@ -1195,9 +1195,9 @@ private function getClientAnnotationProfile(Client $exposeClient, $exposeName, $ */ private function getExposeMappingName($mappingContext) { - $phraseanetLocalId = $this->app['conf']->get(['phraseanet-service', 'phraseanet_local_id']); + $instanceId = $this->app['conf']->get(['main', 'instance_id']); - return $phraseanetLocalId.'_'. $mappingContext . '_mapping'; + return $instanceId . '_' . $mappingContext . '_mapping'; } /** diff --git a/lib/Alchemy/Phrasea/Setup/Installer.php b/lib/Alchemy/Phrasea/Setup/Installer.php index a26cc9d3cc..be17854cc1 100644 --- a/lib/Alchemy/Phrasea/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Setup/Installer.php @@ -192,6 +192,9 @@ private function createConfigFile(Connection $abConn, $serverName, $binaryData, $config['servername'] = $serverName; $config['main']['key'] = $this->app['random.medium']->generateString(16); + // generate from the random instance key + $config['main']['instance_id'] = md5($config['main']['key']); + // define storage config $defaultStoragePaths = [ 'subdefs' => __DIR__ . '/../../../../datas', diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php index bd72160259..5d417cff42 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php @@ -106,12 +106,12 @@ public function process(array $payload) $helpers = new PhraseanetExtension($this->app); // the identification of phraseanet instance in expose - $phraseanetLocalId = $this->app['conf']->get(['phraseanet-service', 'phraseanet_local_id']); + $instanceId = $this->app['conf']->get(['main', 'instance_id']); // get mapping if exist $clientAnnotationProfile = $this->getClientAnnotationProfile($exposeClient, $payload['publicationId']); - $exposeFieldMappingName = $phraseanetLocalId . '_field_mapping'; + $exposeFieldMappingName = $instanceId . '_field_mapping'; $fieldMapping = !empty($clientAnnotationProfile[$exposeFieldMappingName]) ? $clientAnnotationProfile[$exposeFieldMappingName] : []; $fieldListToUpload = !empty($fieldMapping['fields']) ? $fieldMapping['fields'] : []; @@ -199,7 +199,7 @@ public function process(array $payload) } } - $exposeSubdefMappingName = $phraseanetLocalId . '_subdef_mapping'; + $exposeSubdefMappingName = $instanceId . '_subdef_mapping'; $actualSubdefMapping = !empty($clientAnnotationProfile[$exposeSubdefMappingName]) ? $clientAnnotationProfile[$exposeSubdefMappingName] : []; $documentType = $record->getType(); @@ -217,8 +217,8 @@ public function process(array $payload) unset($mapping[$phraseanetSubdefAsDocument]); // this is the unique reference for record in phraseanet and assets in expose - // phraseanetLocalKey_basedID_record_id - $assetId = $phraseanetLocalId.'_'.$record->getId(); + // instanceId_basedID_record_id + $assetId = $instanceId . '_' . $record->getId(); if ($record->has_subdef($phraseanetSubdefAsDocument) && $record->get_subdef($phraseanetSubdefAsDocument)->is_physically_present()) { $requestBody = [ diff --git a/lib/classes/patch/418RC7PHRAS3935.php b/lib/classes/patch/418RC7PHRAS3935.php new file mode 100644 index 0000000000..03e35445ed --- /dev/null +++ b/lib/classes/patch/418RC7PHRAS3935.php @@ -0,0 +1,85 @@ +release; + } + + /** + * {@inheritdoc} + */ + public function getDoctrineMigrations() + { + return []; + } + + /** + * {@inheritdoc} + */ + public function require_all_upgrades() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function concern() + { + return $this->concern; + } + + /** + * {@inheritdoc} + */ + public function apply(base $base, Application $app) + { + if ($base->get_base_type() === base::DATA_BOX) { + $this->patch_databox($base, $app); + } elseif ($base->get_base_type() === base::APPLICATION_BOX) { + $this->patch_appbox($base, $app); + } + + return true; + } + + private function patch_databox(databox $databox, Application $app) + { + } + + private function patch_appbox(base $appbox, Application $app) + { + /** @var PropertyAccess $conf */ + $conf = $app['conf']; + + if (!$conf->has(['main', 'instance_id'])) { + if ($conf->has(['phraseanet-service', 'phraseanet_local_id'])) { + // get phraseanet_local_id if exist + $conf->set(['main', 'instance_id'], $conf->get(['phraseanet-service', 'phraseanet_local_id'])); + $conf->remove(['phraseanet-service', 'phraseanet_local_id']); + } else { + // instance key is already a random value + $instanceKey = $conf->get(['main', 'key']); + + $instanceId = md5($instanceKey); + + $conf->set(['main', 'instance_id'], $instanceId); + } + } + } +} diff --git a/templates/web/admin/phraseanet-service/index.html.twig b/templates/web/admin/phraseanet-service/index.html.twig index 4aa829dea3..dc98032498 100644 --- a/templates/web/admin/phraseanet-service/index.html.twig +++ b/templates/web/admin/phraseanet-service/index.html.twig @@ -1,5 +1,9 @@