From 1801d33ecc5cb20b274dbd5f055e88fda0d879f5 Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Mon, 13 Apr 2026 00:49:33 +0200 Subject: [PATCH 1/2] refactor!: use comma-separated values for metainfo restrictions/templates Switch from pipe-delimited format (|1|2|3|) to comma-separated (1,2,3) for the restrictions and templates columns in metainfo_field table. - RestrictionField: use comma separator, override setValue to join without leading/trailing delimiter - Replace LIKE "%|value|%" queries with FIND_IN_SET in all handlers Co-Authored-By: Claude Opus 4.6 (1M context) --- .tools/psalm/baseline.xml | 6 ++++++ src/MetaInfo/Form/Field/RestrictionField.php | 10 ++++++++++ src/MetaInfo/Handler/ArticleHandler.php | 4 ++-- src/MetaInfo/Handler/CategoryHandler.php | 4 ++-- src/MetaInfo/Handler/MediaHandler.php | 4 ++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.tools/psalm/baseline.xml b/.tools/psalm/baseline.xml index 093807b82c..fb867fb2a4 100644 --- a/.tools/psalm/baseline.xml +++ b/.tools/psalm/baseline.xml @@ -3791,6 +3791,12 @@ + + + + + value]]> + diff --git a/src/MetaInfo/Form/Field/RestrictionField.php b/src/MetaInfo/Form/Field/RestrictionField.php index a5669fda88..dd68d602ec 100644 --- a/src/MetaInfo/Form/Field/RestrictionField.php +++ b/src/MetaInfo/Form/Field/RestrictionField.php @@ -26,9 +26,19 @@ public function __construct($tag = '', ?MetaInfoForm $form = null, array $attrib { parent::__construct('', $form, $attributes); + $this->setSeparator(','); $this->setNotice(I18n::msg('ctrl')); } + /** @return void */ + public function setValue($value) + { + if (is_array($value)) { + $value = implode(',', $value); + } + $this->value = $value; + } + public function setAllCheckboxLabel(string $label): void { $this->allCheckboxLabel = $label; diff --git a/src/MetaInfo/Handler/ArticleHandler.php b/src/MetaInfo/Handler/ArticleHandler.php index 87cc0e2c76..dd2d4bc7b6 100644 --- a/src/MetaInfo/Handler/ArticleHandler.php +++ b/src/MetaInfo/Handler/ArticleHandler.php @@ -59,11 +59,11 @@ protected function buildFilterCondition(array $params) // Alle Metafelder des Pfades sind erlaubt foreach ($OOArt->getPathAsArray() as $pathElement) { if ('' != $pathElement) { - $s .= ' OR `p`.`restrictions` LIKE "%|' . $pathElement . '|%"'; + $s .= ' OR FIND_IN_SET(' . $pathElement . ', `p`.`restrictions`)'; } } - $t = ' OR `p`.`templates` LIKE "%|' . $OOArt->getValue('template_id') . '|%"'; + $t = ' OR FIND_IN_SET(' . $OOArt->getValue('template_id') . ', `p`.`templates`)'; $restrictionsCondition = 'AND (`p`.`restrictions` = "" OR `p`.`restrictions` IS NULL ' . $s . ') AND (`p`.`templates` = "" OR `p`.`templates` IS NULL ' . $t . ')'; } diff --git a/src/MetaInfo/Handler/CategoryHandler.php b/src/MetaInfo/Handler/CategoryHandler.php index 5f37e61cc7..874ee45de2 100644 --- a/src/MetaInfo/Handler/CategoryHandler.php +++ b/src/MetaInfo/Handler/CategoryHandler.php @@ -69,12 +69,12 @@ protected function buildFilterCondition(array $params) // Alle Metafelder des Pfades sind erlaubt foreach ($OOCat->getPathAsArray() as $pathElement) { if ('' != $pathElement) { - $s .= ' OR `p`.`restrictions` LIKE "%|' . $pathElement . '|%"'; + $s .= ' OR FIND_IN_SET(' . $pathElement . ', `p`.`restrictions`)'; } } // Auch die Kategorie selbst kann Metafelder haben - $s .= ' OR `p`.`restrictions` LIKE "%|' . $params['id'] . '|%"'; + $s .= ' OR FIND_IN_SET(' . $params['id'] . ', `p`.`restrictions`)'; } return 'AND (`p`.`restrictions` = "" OR `p`.`restrictions` IS NULL ' . $s . ')'; diff --git a/src/MetaInfo/Handler/MediaHandler.php b/src/MetaInfo/Handler/MediaHandler.php index 98cb8ab00e..0468358d5e 100644 --- a/src/MetaInfo/Handler/MediaHandler.php +++ b/src/MetaInfo/Handler/MediaHandler.php @@ -146,13 +146,13 @@ protected function buildFilterCondition(array $params) // Alle Metafelder des Pfades sind erlaubt foreach ($OOCat->getPathAsArray() as $pathElement) { if ('' != $pathElement) { - $s .= ' OR `p`.`restrictions` LIKE "%|' . $pathElement . '|%"'; + $s .= ' OR FIND_IN_SET(' . $pathElement . ', `p`.`restrictions`)'; } } } // Auch die Kategorie selbst kann Metafelder haben - $s .= ' OR `p`.`restrictions` LIKE "%|' . $catId . '|%"'; + $s .= ' OR FIND_IN_SET(' . $catId . ', `p`.`restrictions`)'; $restrictionsCondition = 'AND (`p`.`restrictions` = "" OR `p`.`restrictions` IS NULL ' . $s . ')'; } From edbc89e1b64e062f486aebd935ac9bb145b84d4c Mon Sep 17 00:00:00 2001 From: gharlan <330436+gharlan@users.noreply.github.com> Date: Sun, 12 Apr 2026 22:51:10 +0000 Subject: [PATCH 2/2] style: apply php-cs-fixer changes --- src/MetaInfo/Form/Field/RestrictionField.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MetaInfo/Form/Field/RestrictionField.php b/src/MetaInfo/Form/Field/RestrictionField.php index dd68d602ec..d53372ad0d 100644 --- a/src/MetaInfo/Form/Field/RestrictionField.php +++ b/src/MetaInfo/Form/Field/RestrictionField.php @@ -8,6 +8,8 @@ use Redaxo\Core\MetaInfo\Form\MetaInfoForm; use Redaxo\Core\Translation\I18n; +use function is_array; + /** * @internal */