From bcc032dc110f46b817b5b13287a7ac746489df3c Mon Sep 17 00:00:00 2001 From: jygaulier Date: Thu, 19 Nov 2020 20:27:53 +0100 Subject: [PATCH] fix : permalink creation for subdef_id=0 is now ignored (PHRAS-3280) fix : label was not escaped for "createMany" permalinks --- lib/classes/media/Permalink/Adapter.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/classes/media/Permalink/Adapter.php b/lib/classes/media/Permalink/Adapter.php index f5aa4923c5..43d59b6d4e 100644 --- a/lib/classes/media/Permalink/Adapter.php +++ b/lib/classes/media/Permalink/Adapter.php @@ -397,6 +397,11 @@ class media_Permalink_Adapter implements cache_cacheableInterface $insk = ", 1, NOW(), NOW(), " . $connection->quote(self::cleanLabel($unicode, $record->get_title(['removeExtension' => true]))); // multiple rows foreach($subdef_ids as $subdef_id) { + // fake subdefs (icons substitution) for thumb/prev are hardcoded. + // since there is no subdef entry, we cant generate a plink + if($subdef_id === 0) { + continue; + } $inserts .= ($inserts ? ',' : '') . '(' . $connection->quote($subdef_id) . ', ' . $connection->quote($generator->generateString(64, TokenManipulator::LETTERS_AND_NUMBERS)) @@ -420,16 +425,25 @@ class media_Permalink_Adapter implements cache_cacheableInterface * @param Application $app * @param databox $databox * @param media_subdef[] $subdefs - * @throws \InvalidArgumentException|Exception + * @throws InvalidArgumentException|Exception */ public static function createMany(Application $app, databox $databox, $subdefs) { + /** @var unicode $unicode */ + $unicode = $app['unicode']; + $databoxId = $databox->get_sbas_id(); $recordIds = []; /** @var media_subdef[] $uniqSubdefs */ $uniqSubdefs = []; foreach ($subdefs as $media_subdef) { + // fake subdefs (icons substitution) for thumb/prev are hardcoded. + // since there is no subdef entry, we cant generate a plink + if($media_subdef->get_subdef_id() === 0) { + continue; + } + if ($media_subdef->get_sbas_id() !== $databoxId) { throw new InvalidArgumentException(sprintf( 'All subdefs should be from databox %d, got %d', @@ -469,7 +483,10 @@ class media_Permalink_Adapter implements cache_cacheableInterface $data[] = [ 'subdef_id' => $media_subdef->get_subdef_id(), 'token' => $generator->generateString(64, TokenManipulator::LETTERS_AND_NUMBERS), - 'label' => $records[$media_subdef->get_record_id()]->get_title(['removeExtension' => true]), + 'label' => self::cleanLabel( + $unicode, + $records[$media_subdef->get_record_id()]->get_title(['removeExtension' => true]) + ), ]; }