Skip to content

Commit

Permalink
PHRAS-3935 : phraseanet_local_id became instance_id (#4396)
Browse files Browse the repository at this point in the history
* phraseanet_local_id patch

* display phraseanet_local_id

* phraseanet_local_id to instance_id

* update embed bumdle
  • Loading branch information
aynsix authored Oct 30, 2023
1 parent bf76b30 commit 23bb538
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 24 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/Alchemy/Phrasea/Setup/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : [];

Expand Down Expand Up @@ -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();

Expand All @@ -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 = [
Expand Down
85 changes: 85 additions & 0 deletions lib/classes/patch/418RC7PHRAS3935.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php


use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;

class patch_418RC7PHRAS3935 implements patchInterface
{
/** @var string */
private $release = '4.1.8-rc7';

/** @var array */
private $concern = [base::APPLICATION_BOX];

/**
* {@inheritdoc}
*/
public function get_release()
{
return $this->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);
}
}
}
}
4 changes: 4 additions & 0 deletions templates/web/admin/phraseanet-service/index.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<h1>{{ 'admin:phrasea-service-setting:tab-title:: Page title' | trans }}</h1>

<div style="margin-bottom:20px;">
<label>instance_id: <code style="padding:10px 15px;">{{ app['conf'].get(['main', 'instance_id'], '') }}</code></label>
</div>

<div class="phraseanet-service-setting-tabs">
<ul class="nav nav-tabs">
<li role="presentation" class="auth"><a aria-controls="auth" href="#auth" role="tab" data-toggle="tab" data-url="/admin/phraseanet-service/auth">{{ 'admin:phrasea-service-setting:tab:: Auth' | trans }}</a></li>
Expand Down

0 comments on commit 23bb538

Please sign in to comment.