diff --git a/lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php b/lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php index e1a1084907..52ec210100 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php @@ -114,7 +114,6 @@ function changeSubdefsAction(Request $request, $sbas_id) { $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]; - $options[Image::OPTION_SUBSTITUABLE] = $config["image"]["definitions"][$preset][Image::OPTION_SUBSTITUABLE]; foreach ($config["image"]["definitions"][$preset][Subdef::OPTION_DEVICE] as $devices) { $options[Subdef::OPTION_DEVICE][] = $devices; } @@ -186,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']; @@ -212,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); } } diff --git a/lib/Alchemy/Phrasea/Media/Subdef/Image.php b/lib/Alchemy/Phrasea/Media/Subdef/Image.php index 84be838050..46d5903417 100644 --- a/lib/Alchemy/Phrasea/Media/Subdef/Image.php +++ b/lib/Alchemy/Phrasea/Media/Subdef/Image.php @@ -26,7 +26,6 @@ class Image extends Provider const OPTION_WATERMARKTEXT = 'watermarktext'; const OPTION_WATERMARKRID = 'watermarkrid'; const OPTION_BACKGROUNDCOLOR = 'backgroundcolor'; - const OPTION_SUBSTITUABLE = 'substituable'; protected $options = []; @@ -44,7 +43,6 @@ public function __construct(TranslatorInterface $translator) $this->registerOption(new OptionType\Text($this->translator->trans('Watermark text'), self::OPTION_WATERMARKTEXT, '')); $this->registerOption(new OptionType\Text($this->translator->trans('Watermark Record_id'), self::OPTION_WATERMARKRID, '')); $this->registerOption(new OptionType\Text($this->translator->trans('Background Color'), self::OPTION_BACKGROUNDCOLOR, '')); - $this->registerOption(new OptionType\Boolean($this->translator->trans('Substituable'), self::OPTION_SUBSTITUABLE, false)); } public function getType() diff --git a/lib/classes/databox/subdef.php b/lib/classes/databox/subdef.php index 1c027ab318..2bc32f4361 100644 --- a/lib/classes/databox/subdef.php +++ b/lib/classes/databox/subdef.php @@ -83,8 +83,8 @@ public function __construct(SubdefType $type, SimpleXMLElement $sd, TranslatorIn } $this->name = strtolower($sd->attributes()->name); $this->downloadable = p4field::isyes($sd->attributes()->downloadable); - $this->substituable = p4field::isyes($sd->substituable); - $this->orderable = isset($sd->attributes()->orderable) && p4field::isyes($sd->attributes()->orderable); + $this->substituable = isset($sd->attributes()->substituable) && p4field::isyes($sd->attributes()->substituable); + $this->orderable = !isset($sd->attributes()->orderable) || p4field::isyes($sd->attributes()->orderable); $this->tobuild = !isset($sd->attributes()->tobuild) || p4field::isyes($sd->attributes()->tobuild); $this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : ''; $this->preset = $sd->attributes()->presets; @@ -165,9 +165,6 @@ protected function buildImageSubdef(SimpleXMLElement $sd) if ($sd->backgroundcolor) { $image->setOptionValue(Image::OPTION_BACKGROUNDCOLOR, $sd->backgroundcolor); } - if ($sd->substituable) { - $image->setOptionValue(Image::OPTION_SUBSTITUABLE, p4field::isyes($sd->substituable)); - } return $image; } /** diff --git a/lib/classes/databox/subdefsStructure.php b/lib/classes/databox/subdefsStructure.php index ffd6927b8a..69261f1bd1 100644 --- a/lib/classes/databox/subdefsStructure.php +++ b/lib/classes/databox/subdefsStructure.php @@ -246,7 +246,7 @@ public function add_subdef($groupname, $name, $class, $mediatype, $preset, $path * @return databox_subdefsStructure * @throws Exception */ - public function set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable = true, $preset = "Custom", $toBuild = true) + public function set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable = true, $preset = "Custom", $toBuild = true, $substituable = false) { $dom_struct = $this->databox->get_dom_structure(); @@ -256,6 +256,7 @@ public function set_subdef($group, $name, $class, $downloadable, $options, $labe $subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false')); $subdef->setAttribute('orderable', ($orderable ? 'true' : 'false')); $subdef->setAttribute('tobuild', ($toBuild ? 'true' : 'false')); + $subdef->setAttribute('substituable', ($substituable ? 'true' : 'false')); $subdef->setAttribute('presets', $preset); foreach ($labels as $code => $label) { diff --git a/lib/classes/patch/418RC7.php b/lib/classes/patch/418RC7.php index 1732008ea7..71a2a4db9c 100644 --- a/lib/classes/patch/418RC7.php +++ b/lib/classes/patch/418RC7.php @@ -2,7 +2,6 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Core\Configuration\PropertyAccess; -use Alchemy\Phrasea\Databox\SubdefGroup; class patch_418RC7 implements patchInterface { @@ -61,43 +60,26 @@ public function apply(base $base, Application $app) private $thumbSubstitution = null; - private function patch_databox(databox $databox, Application $app) + public function patch_databox(databox $databox, Application $app) { /** @var PropertyAccess $conf */ $conf = $app['conf']; - if($this->thumbSubstitution === null) { + if ($this->thumbSubstitution === null) { // first db $this->thumbSubstitution = $conf->get(['registry', 'modules', 'thumb-substitution']); $conf->remove(['registry', 'modules', 'thumb-substitution']); } if ($this->thumbSubstitution) { - $subdefStructure = $databox->get_subdef_structure(); $dom_struct = $databox->get_dom_structure(); $dom_xp = $databox->get_xpath_structure(); - /** @var SubdefGroup $sdGroup */ - foreach ($subdefStructure as $sdGroup) { - $group = $sdGroup->getName(); - - $nodes = $dom_xp->query('//record/subdefs/subdefgroup[@name="' . $group . '"]/subdef[@name="thumbnail"]'); - if ($nodes->length > 0) { - $dom_sd = $nodes->item(0); - - while (true) { - $nodes = $dom_xp->query('substituable', $dom_sd); - if ($nodes->length === 0) { - break; - } - $dom_sd->removeChild($nodes->item(0)); - } - $dom_sd->appendChild( - $dom_struct->createElement('substituable') - )->appendChild( - $dom_struct->createTextNode('yes') - ); - } + $nodes = $dom_xp->query('//record/subdefs/subdefgroup/subdef[@name="thumbnail"]'); + for ($i = 0; $i < $nodes->length; $i++) { + /** @var \DOMElement $node */ + $node = $nodes->item($i); + $node->setAttribute('substituable', 'true'); } $databox->saveStructure($dom_struct); diff --git a/logs/.gitkeep b/logs/.gitkeep old mode 100644 new mode 100755 diff --git a/templates/web/admin/subdefs.html.twig b/templates/web/admin/subdefs.html.twig index b94e27c043..0fb71104b3 100644 --- a/templates/web/admin/subdefs.html.twig +++ b/templates/web/admin/subdefs.html.twig @@ -456,6 +456,13 @@ + + {{ 'subdef.substituable' | trans }} + + + + {{ 'classe' | trans }} diff --git a/tests/classes/databox/subdefTest.php b/tests/classes/databox/subdefTest.php index f403712621..9478a50147 100644 --- a/tests/classes/databox/subdefTest.php +++ b/tests/classes/databox/subdefTest.php @@ -249,6 +249,43 @@ public function providesOrderableStatuses() ]; } + /** + * @param bool $expected + * @param null|string $configValue + * @dataProvider providesSubstituableStatuses + */ + public function testSubstituableStatus($expected, $configValue, $message) + { + $xmlTemplate = <<<'EOF' + + + /home/datas/noweb/db_alch_phrasea/video/ + image + %s + +EOF; + + if (null !== $configValue) { + $configValue = ' orderable="' . $configValue . '"'; + } + + $xml = sprintf($xmlTemplate, $configValue ?: ''); + + $sut = new databox_subdef(new Type\Image(), simplexml_load_string($xml), $this->translator); + + $this->assertSame($expected, $sut->isSubstituable(), $message); + } + + public function providesSubstituableStatuses() + { + return [ + [false, '', 'No substituable Status set should defaults to true'], + [false, '', 'substituable should default to false'], + [true, 'yes', 'substituable should be true'], + [false, 'no', 'substituable should be false'], + ]; + } + /** * @return PHPUnit_Framework_MockObject_MockObject|TranslatorInterface */