fix : permalink creation for subdef_id=0 is now ignored (PHRAS-3280)

fix : label was not escaped for "createMany" permalinks
This commit is contained in:
jygaulier
2020-11-19 20:27:53 +01:00
parent 79eb12279d
commit bcc032dc11

View File

@@ -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])
),
];
}