Skip to content

Commit

Permalink
PHRAS-3918_subdef-substituable-setting (#4381)
Browse files Browse the repository at this point in the history
* add checkbox "substituable" to admin/subdef ; bump to 4.1.8-rc7 and bump production-client ; migrate and remove conf 'registry/modules/thumb-substitution'

* bump production-client to 94

* fix test ; add test ; move "substituable" node to all subdefs (attribute)

* fix test

* fix test

* set "flatten layers"=true for new subdefs (PHRAS-3852 fix it)
  • Loading branch information
jygaulier authored Oct 31, 2023
1 parent 23bb538 commit 6573234
Show file tree
Hide file tree
Showing 19 changed files with 406 additions and 239 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ PHRASEANET_DOCKER_REGISTRY=local

# Docker images tag.
# @run
PHRASEANET_DOCKER_TAG=4.1.8-rc6
PHRASEANET_DOCKER_TAG=4.1.8-rc7

# Stack Name
# An optionnal Name for the stack
Expand Down
1 change: 1 addition & 0 deletions Phraseanet-production-client/dist/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -62775,6 +62775,7 @@ var recordToolsModal = function recordToolsModal(services, datas) {
(0, _jquery2.default)('.iframe_submiter', $scope).bind('click', function () {
var form = (0, _jquery2.default)(this).closest('form');
form.submit();
form.find('.resultAction').empty();
form.find('.load').empty().html(localeService.t('loading') + ' ...');
(0, _jquery2.default)('#uploadHdsub').contents().find('.content').empty();
(0, _jquery2.default)('#uploadHdsub').load(function () {
Expand Down
1 change: 1 addition & 0 deletions Phraseanet-production-client/dist/production.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -62775,6 +62775,7 @@ var recordToolsModal = function recordToolsModal(services, datas) {
(0, _jquery2.default)('.iframe_submiter', $scope).bind('click', function () {
var form = (0, _jquery2.default)(this).closest('form');
form.submit();
form.find('.resultAction').empty();
form.find('.load').empty().html(localeService.t('loading') + ' ...');
(0, _jquery2.default)('#uploadHdsub').contents().find('.content').empty();
(0, _jquery2.default)('#uploadHdsub').load(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const recordToolsModal = (services, datas, activeTab = false) => {
$('.iframe_submiter', $scope).bind('click', function () {
var form = $(this).closest('form');
form.submit();
form.find('.resultAction').empty();
form.find('.load').empty().html(localeService.t('loading') + ' ...');
$('#uploadHdsub').contents().find('.content').empty();
$('#uploadHdsub').load(function () {
Expand Down
Empty file modified cache/.gitkeep
100644 → 100755
Empty file.
10 changes: 7 additions & 3 deletions lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
use Alchemy\Phrasea\Databox\SubdefGroup;
use Alchemy\Phrasea\Media\Subdef\Subdef;
use Alchemy\Phrasea\Media\Type\Type;
use Exception;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Alchemy\Phrasea\Media\Subdef\Image;
use Alchemy\Phrasea\Media\Subdef\Video;
use Alchemy\Phrasea\Media\Subdef\Audio;
use Alchemy\Phrasea\Media\Subdef\Gif;
use unicode;

class SubdefsController extends Controller
{
Expand All @@ -44,7 +46,7 @@ function indexAction($sbas_id) {
* @param Request $request
* @param int $sbas_id
* @return Response
* @throws \Exception
* @throws Exception
*/
function changeSubdefsAction(Request $request, $sbas_id) {
$delete_subdef = $request->request->get('delete_subdef');
Expand Down Expand Up @@ -84,7 +86,7 @@ function changeSubdefsAction(Request $request, $sbas_id) {
$subdefs = $databox->get_subdef_structure();

$group = $add_subdef['group'];
/** @var \unicode $unicode */
/** @var unicode $unicode */
$unicode = $this->app['unicode'];
$name = $unicode->remove_nonazAZ09($add_subdef['name'], false);
$class = $add_subdef['class'];
Expand All @@ -111,6 +113,7 @@ function changeSubdefsAction(Request $request, $sbas_id) {
$options[Image::OPTION_FLATTEN] = $config["image"]["definitions"][$preset][Image::OPTION_FLATTEN];
$options[Image::OPTION_QUALITY] = $config["image"]["definitions"][$preset][Image::OPTION_QUALITY];
$options[Image::OPTION_ICODEC] = $config["image"]["definitions"][$preset][Image::OPTION_ICODEC];
$options[Image::OPTION_BACKGROUNDCOLOR] = $config["image"]["definitions"][$preset][Image::OPTION_BACKGROUNDCOLOR];
foreach ($config["image"]["definitions"][$preset][Subdef::OPTION_DEVICE] as $devices) {
$options[Subdef::OPTION_DEVICE][] = $devices;
}
Expand Down Expand Up @@ -182,6 +185,7 @@ function changeSubdefsAction(Request $request, $sbas_id) {
$class = $request->request->get($post_sub . '_class');
$downloadable = $request->request->get($post_sub . '_downloadable');
$orderable = $request->request->get($post_sub . '_orderable');
$substituable = $request->request->get($post_sub . '_substituable');
$toBuild = $request->request->get($post_sub . '_tobuild');

$defaults = ['path', 'meta', 'mediatype'];
Expand All @@ -208,7 +212,7 @@ function changeSubdefsAction(Request $request, $sbas_id) {
}

$labels = $request->request->get($post_sub . '_label', []);
$subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable, $preset, $toBuild);
$subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable, $preset, $toBuild, $substituable);
}
}

Expand Down
128 changes: 79 additions & 49 deletions lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public function indexAction(Request $request)

$metadatas = false;
$record = null;
$recordAccessibleSubdefs = array();
$listsubdef= null;
$recordAccessibleSubdefs = [];
$listsubdef = null;
if (count($records) == 1) {
/** @var record_adapter $record */
$record = $records->first();

/**Array list of subdefs**/
$listsubdef = array_keys($record-> get_subdefs());
$listsubdef = array_keys($record->get_subdefs());
// fetch subdef list:
$subdefs = $record->get_subdefs();

Expand All @@ -73,18 +73,19 @@ public function indexAction(Request $request)
continue;
}
$label = $this->app->trans('prod::tools: document');
} elseif ($databoxSubdefs !== null && $databoxSubdefs->hasSubdef($subdefName)) {
}
elseif ($databoxSubdefs !== null && $databoxSubdefs->hasSubdef($subdefName)) {
if (!$acl->has_access_to_subdef($record, $subdefName)) {
continue;
}

$label = $databoxSubdefs->getSubdef($subdefName)->get_label($this->app['locale']);
}
$recordAccessibleSubdefs[] = array(
'name' => $subdef->get_name(),
$recordAccessibleSubdefs[] = [
'name' => $subdef->get_name(),
'state' => $permalink->get_is_activated(),
'label' => $label,
);
];
}
}
if (!$record->isStory()) {
Expand All @@ -95,38 +96,52 @@ public function indexAction(Request $request)
$availableSubdefLabel = [];
$countSubdefTodo = [];

$substituables = [];
if ($this->getConf()->get(['registry', 'modules', 'doc-substitution'])) {
$substituables[] = 'document';
}
/** @var record_adapter $rec */
foreach ($records as $rec) {

$databoxSubdefs = $rec->getDatabox()->get_subdef_structure()->getSubdefGroup($rec->getType());
if ($databoxSubdefs !== null) {
foreach ($databoxSubdefs as $sub) {
if ($sub->isTobuild()) {
$label = trim($sub->get_label($this->app['locale']));
$availableSubdefLabel[] = $label;
if (isset($countSubdefTodo[$label])) {
$countSubdefTodo[$label] ++;
} else {
$countSubdefTodo[$label]++;
}
else {
$countSubdefTodo[$label] = 1;
}
}
if ($sub->isSubstituable()) {
$substituables[] = $sub->get_name();
}
}
}
}

if (count($records) > 1) {
$substituables = [];
}

$this->setSessionFormToken('prodToolsSubdef');
$this->setSessionFormToken('prodToolsRotate');
$this->setSessionFormToken('prodToolsHDSubstitution');
$this->setSessionFormToken('prodToolsThumbSubstitution');

return $this->render('prod/actions/Tools/index.html.twig', [
'records' => $records,
'record' => $record,
'recordSubdefs' => $recordAccessibleSubdefs,
'metadatas' => $metadatas,
'listsubdef' => $listsubdef,
'records' => $records,
'record' => $record,
'recordSubdefs' => $recordAccessibleSubdefs,
'metadatas' => $metadatas,
'listsubdef' => $listsubdef,
'availableSubdefLabel' => array_unique($availableSubdefLabel),
'nbRecords' => count($records),
'countSubdefTodo' => $countSubdefTodo
'nbRecords' => count($records),
'countSubdefTodo' => $countSubdefTodo,
'substituables' => $substituables,
]);
}

Expand Down Expand Up @@ -161,7 +176,8 @@ public function rotateAction(Request $request)

try {
$subdef->rotate($rotation, $this->getMediaAlchemyst(), $this->getMediaVorus());
} catch (\Exception $e) {
}
catch (\Exception $e) {
// ignore exception
}
}
Expand Down Expand Up @@ -256,31 +272,34 @@ public function hddocAction(Request $request)

$this->getSubDefinitionSubstituer()->substituteDocument($record, $media);
$record->insertTechnicalDatas($this->getMediaVorus());
$this->getMetadataSetter()->replaceMetadata($this->getMetadataReader() ->read($media), $record);
$this->getMetadataSetter()->replaceMetadata($this->getMetadataReader()->read($media), $record);

$this->getDataboxLogger($record->getDatabox())
->log($record, \Session_Logger::EVENT_SUBSTITUTE, 'HD', '' );
->log($record, \Session_Logger::EVENT_SUBSTITUTE, 'HD', '');

if ((int) $request->request->get('ccfilename') === 1) {
if ((int)$request->request->get('ccfilename') === 1) {
$record->set_original_name($fileName);
}
unlink($tempoFile);
rmdir($tempoDir);
$success = true;
$message = $this->app->trans('Document has been successfully substitued');
} catch (\Exception $e) {
}
catch (\Exception $e) {
$message = $this->app->trans('file is not valid');
}
} else {
}
else {
$message = $this->app->trans('file is not valid');
}
} else {
}
else {
$this->app->abort(400, 'Missing file parameter');
}

return $this->render('prod/actions/Tools/iframeUpload.html.twig', [
'success' => $success,
'message' => $message,
'success' => $success,
'message' => $message,
]);
}

Expand All @@ -296,10 +315,10 @@ public function changeThumbnailAction(Request $request)
$this->app->abort(400, 'Missing file parameter');
}

if (! $file->isValid()) {
if (!$file->isValid()) {
return $this->render('prod/actions/Tools/iframeUpload.html.twig', [
'success' => false,
'message' => $this->app->trans('file is not valid'),
'success' => false,
'message' => $this->app->trans('file is not valid'),
]);
}

Expand All @@ -318,22 +337,28 @@ public function changeThumbnailAction(Request $request)

$media = $this->app->getMediaFromUri($tempoFile);

$this->getSubDefinitionSubstituer()->substituteSubdef($record, 'thumbnail', $media);
// no BC break before PHRAS-3918 when only "thumbnail" was substituable
if(($subdef = $request->get('subdef')) === null) {
$subdef = 'thumbnail';
}

$this->getSubDefinitionSubstituer()->substituteSubdef($record, $subdef, $media);
$this->getDataboxLogger($record->getDatabox())
->log($record, \Session_Logger::EVENT_SUBSTITUTE, 'thumbnail', '');
->log($record, \Session_Logger::EVENT_SUBSTITUTE, $subdef, '');

unlink($tempoFile);
rmdir($tempoDir);
$success = true;
$message = $this->app->trans('Thumbnail has been successfully substitued');
} catch (\Exception $e) {
$message = sprintf($this->app->trans('Subdef "%s" has been successfully substitued'), $subdef);
}
catch (\Exception $e) {
$success = false;
$message = $this->app->trans('file is not valid');
}

return $this->render('prod/actions/Tools/iframeUpload.html.twig', [
'success' => $success,
'message' => $message,
'success' => $success,
'message' => $message,
]);
}

Expand All @@ -344,14 +369,15 @@ public function submitConfirmBoxAction(Request $request)
try {
$record = new record_adapter($this->app, $request->request->get('sbas_id'), $request->request->get('record_id'));
$var = [
'video_title' => $record->get_title(['encode'=> record_adapter::ENCODE_NONE]),
'video_title' => $record->get_title(['encode' => record_adapter::ENCODE_NONE]),
'image' => $request->request->get('image', ''),
];
$return = [
'error' => false,
'datas' => $this->render($template, $var),
];
} catch (\Exception $e) {
}
catch (\Exception $e) {
$return = [
'error' => true,
'datas' => $this->app->trans('an error occured'),
Expand All @@ -378,7 +404,8 @@ public function applyThumbnailExtractionAction(Request $request)
}

$return = ['success' => true, 'message' => ''];
} catch (\Exception $e) {
}
catch (\Exception $e) {
$return = ['success' => false, 'message' => $e->getMessage()];
}

Expand Down Expand Up @@ -418,7 +445,8 @@ public function editRecordSharing(Request $request, $base_id, $record_id)
try {
$permalink->set_is_activated($state);
$return = ['success' => true, 'state' => $permalink->get_is_activated()];
} catch (\Exception $e) {
}
catch (\Exception $e) {
$return = ['success' => false, 'state' => $permalink->get_is_activated()];
}

Expand Down Expand Up @@ -474,13 +502,14 @@ private function substituteMedia(record_adapter $record, $subDefName, $subDefDat

$media = $this->app->getMediaFromUri($fileName);

if($subDefName == 'document') {
if ($subDefName == 'document') {
$this->getSubDefinitionSubstituer()->substituteDocument($record, $media);
} else {
}
else {
$this->getSubDefinitionSubstituer()->substituteSubdef($record, $subDefName, $media);
}
$this->getDataboxLogger($record->getDatabox())
->log($record, \Session_Logger::EVENT_SUBSTITUTE, $subDefName, '');
->log($record, \Session_Logger::EVENT_SUBSTITUTE, $subDefName, '');

unset($media);
$this->getFilesystem()->remove($fileName);
Expand Down Expand Up @@ -574,7 +603,7 @@ public function videoEditorAction(Request $request)
'_value' => $record->getCaption([$meta->get_name()]),
];

if (preg_match('/^VideoTextTrack(.*)$/iu', $meta->get_name(), $matches) && !empty($matches[1]) && strlen($matches[1]) == 2 ) {
if (preg_match('/^VideoTextTrack(.*)$/iu', $meta->get_name(), $matches) && !empty($matches[1]) && strlen($matches[1]) == 2) {
$field['label'] = $matches[1];
$field['meta_struct_id'] = $meta->get_id();
$field['value'] = '';
Expand All @@ -595,20 +624,21 @@ public function videoEditorAction(Request $request)
$conf = $this->getConf();

return $this->render('prod/actions/Tools/videoEditor.html.twig', [
'records' => $records,
'record' => $record,
'videoEditorConfig' => $conf->get(['video-editor']),
'metadatas' => $metadatas,
'JSonFields' => json_encode($JSFields),
'videoTextTrackFields' => $videoTextTrackFields
'records' => $records,
'record' => $record,
'videoEditorConfig' => $conf->get(['video-editor']),
'metadatas' => $metadatas,
'JSonFields' => json_encode($JSFields),
'videoTextTrackFields' => $videoTextTrackFields
]);
}

private function isPhysicallyPresent(record_adapter $record, $subdefName)
{
try {
return $record->get_subdef($subdefName)->is_physically_present();
} catch (\Exception $e) {
}
catch (\Exception $e) {
unset($e);
}

Expand Down
Loading

0 comments on commit 6573234

Please sign in to comment.