From 2922775935067d60b586279fab63e9d8c6c0b99b Mon Sep 17 00:00:00 2001 From: doishub Date: Mon, 10 Jul 2023 11:18:38 +0200 Subject: [PATCH 1/5] Support importing via the product installer --- contao/config/config.php | 4 +++ .../AddRecommendationValidatorListener.php | 26 +++++++++++++++++++ .../RecommendationArchiveValidator.php | 24 +++++++++++++++++ .../Validator/RecommendationValidator.php | 24 +++++++++++++++++ translations/setup.de.yaml | 10 +++++++ translations/setup.en.yaml | 10 +++++++ 6 files changed, 98 insertions(+) create mode 100644 src/EventListener/ProductInstaller/AddRecommendationValidatorListener.php create mode 100644 src/Import/Validator/RecommendationArchiveValidator.php create mode 100644 src/Import/Validator/RecommendationValidator.php create mode 100644 translations/setup.de.yaml create mode 100644 translations/setup.en.yaml diff --git a/contao/config/config.php b/contao/config/config.php index 36e49be..150123a 100644 --- a/contao/config/config.php +++ b/contao/config/config.php @@ -8,6 +8,7 @@ use Oveleon\ContaoRecommendationBundle\ModuleRecommendationReader; use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel; use Oveleon\ContaoRecommendationBundle\Model\RecommendationModel; +use Oveleon\ContaoRecommendationBundle\EventListener\ProductInstaller\AddRecommendationValidatorListener; // Back end modules ArrayUtil::arrayInsert($GLOBALS['BE_MOD']['content'], 5, [ @@ -39,3 +40,6 @@ // Models $GLOBALS['TL_MODELS']['tl_recommendation'] = RecommendationModel::class; $GLOBALS['TL_MODELS']['tl_recommendation_archive'] = RecommendationArchiveModel::class; + +// Add product installer validators +$GLOBALS['PI_HOOKS']['addValidator'][] = [AddRecommendationValidatorListener::class, 'addValidators']; diff --git a/src/EventListener/ProductInstaller/AddRecommendationValidatorListener.php b/src/EventListener/ProductInstaller/AddRecommendationValidatorListener.php new file mode 100644 index 0000000..ca4372d --- /dev/null +++ b/src/EventListener/ProductInstaller/AddRecommendationValidatorListener.php @@ -0,0 +1,26 @@ + + * @copyright Oveleon + */ + +namespace Oveleon\ContaoRecommendationBundle\EventListener\ProductInstaller; + +use Oveleon\ContaoRecommendationBundle\Import\Validator\RecommendationArchiveValidator; +use Oveleon\ProductInstaller\Import\Validator; + +class AddRecommendationValidatorListener +{ + public function addValidators(): void + { + // Connects jumpTo pages + Validator::addValidatorCollection([RecommendationArchiveValidator::class], ['setJumpToPageConnection']); + } +} diff --git a/src/Import/Validator/RecommendationArchiveValidator.php b/src/Import/Validator/RecommendationArchiveValidator.php new file mode 100644 index 0000000..45457c4 --- /dev/null +++ b/src/Import/Validator/RecommendationArchiveValidator.php @@ -0,0 +1,24 @@ + + */ +class RecommendationArchiveValidator implements ValidatorInterface +{ + static public function getTrigger(): string + { + return RecommendationArchiveModel::getTable(); + } + + static public function getModel(): string + { + return RecommendationArchiveModel::class; + } +} diff --git a/src/Import/Validator/RecommendationValidator.php b/src/Import/Validator/RecommendationValidator.php new file mode 100644 index 0000000..918b4ba --- /dev/null +++ b/src/Import/Validator/RecommendationValidator.php @@ -0,0 +1,24 @@ + + */ +class RecommendationValidator implements ValidatorInterface +{ + static public function getTrigger(): string + { + return RecommendationModel::getTable(); + } + + static public function getModel(): string + { + return RecommendationModel::class; + } +} diff --git a/translations/setup.de.yaml b/translations/setup.de.yaml new file mode 100644 index 0000000..2778805 --- /dev/null +++ b/translations/setup.de.yaml @@ -0,0 +1,10 @@ +setup: + tables: + tl_recommendation_archive: 'Bewertungen-Archive' + tl_recommendation: 'Bewertungen' + prompt: + recommendation_archive: + jumpTo: + label: 'Bewertungen-Archiv → Weiterleitungsseite' + description: 'Ein oder mehrere Bewertungen-Archive verweisen auf eine Weiterleitungsseite, welche nicht aufgelöst werden kann. Ihre Auswahl wird für alle weiteren Bewertungen-Archive, welche auf die selbe Weiterleitungsseite referenzieren, übernommen.' + explanation: 'Beim Importieren eines oder mehrerer Bewertungen-Archive konnte die zugehörige Weiterleitungsseite nicht gefunden werden. Wählen Sie bitte eine Seite aus Ihrer Contao-Instanz, um eine Verknüpfung zwischen diesen Archiven und einer Seite herzustellen.

Folgende Seite wurde nicht importiert und benötigt eine Alternative:' diff --git a/translations/setup.en.yaml b/translations/setup.en.yaml new file mode 100644 index 0000000..e38add1 --- /dev/null +++ b/translations/setup.en.yaml @@ -0,0 +1,10 @@ +setup: + tables: + tl_recommendation_archive: 'Recommendation archives' + tl_recommendation: 'Recommendations' + prompt: + recommendation_archive: + jumpTo: + label: 'Recommendation-Archive → Redirect page' + description: 'One or more recommendation archives refer to a forwarding page that cannot be resolved. Your selection is applied to all other rating archives that reference the same redirection page.' + explanation: 'When importing one or more recommendation archives, the corresponding redirect page could not be found. Please select a page from your Contao instance to create a link between these archives and a page.

The following page was not imported and needs an alternative:' From cebef5b4d1f7830d3061c50a10c0311646a201e5 Mon Sep 17 00:00:00 2001 From: doishub Date: Thu, 7 Sep 2023 10:12:43 +0200 Subject: [PATCH 2/5] - Structure modified - Product Installer added to `setLoadAfter` --- contao/config/config.php | 2 +- src/ContaoManager/Plugin.php | 6 +++++- .../AddRecommendationValidatorListener.php | 2 +- src/Import/Validator/RecommendationArchiveValidator.php | 3 +-- 4 files changed, 8 insertions(+), 5 deletions(-) rename src/EventListener/{ProductInstaller => Import}/AddRecommendationValidatorListener.php (89%) diff --git a/contao/config/config.php b/contao/config/config.php index 150123a..8696869 100644 --- a/contao/config/config.php +++ b/contao/config/config.php @@ -8,7 +8,7 @@ use Oveleon\ContaoRecommendationBundle\ModuleRecommendationReader; use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel; use Oveleon\ContaoRecommendationBundle\Model\RecommendationModel; -use Oveleon\ContaoRecommendationBundle\EventListener\ProductInstaller\AddRecommendationValidatorListener; +use Oveleon\ContaoRecommendationBundle\EventListener\Import\AddRecommendationValidatorListener; // Back end modules ArrayUtil::arrayInsert($GLOBALS['BE_MOD']['content'], 5, [ diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index d32d03c..3eb53b6 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -15,6 +15,7 @@ use Contao\ManagerPlugin\Bundle\Config\BundleConfig; use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; use Oveleon\ContaoRecommendationBundle\ContaoRecommendationBundle; +use Oveleon\ProductInstaller\ProductInstaller; class Plugin implements BundlePluginInterface { @@ -26,7 +27,10 @@ public function getBundles(ParserInterface $parser): array return [ BundleConfig::create(ContaoRecommendationBundle::class) ->setReplace(['recommendation']) - ->setLoadAfter([ContaoCoreBundle::class]) + ->setLoadAfter([ + ContaoCoreBundle::class, + ProductInstaller::class + ]) ]; } } diff --git a/src/EventListener/ProductInstaller/AddRecommendationValidatorListener.php b/src/EventListener/Import/AddRecommendationValidatorListener.php similarity index 89% rename from src/EventListener/ProductInstaller/AddRecommendationValidatorListener.php rename to src/EventListener/Import/AddRecommendationValidatorListener.php index ca4372d..b622295 100644 --- a/src/EventListener/ProductInstaller/AddRecommendationValidatorListener.php +++ b/src/EventListener/Import/AddRecommendationValidatorListener.php @@ -11,7 +11,7 @@ * @copyright Oveleon */ -namespace Oveleon\ContaoRecommendationBundle\EventListener\ProductInstaller; +namespace Oveleon\ContaoRecommendationBundle\EventListener\Import; use Oveleon\ContaoRecommendationBundle\Import\Validator\RecommendationArchiveValidator; use Oveleon\ProductInstaller\Import\Validator; diff --git a/src/Import/Validator/RecommendationArchiveValidator.php b/src/Import/Validator/RecommendationArchiveValidator.php index 45457c4..e8f17f8 100644 --- a/src/Import/Validator/RecommendationArchiveValidator.php +++ b/src/Import/Validator/RecommendationArchiveValidator.php @@ -3,14 +3,13 @@ namespace Oveleon\ContaoRecommendationBundle\Import\Validator; use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel; -use Oveleon\ProductInstaller\Import\Validator\ValidatorInterface; /** * Validator class for validating the recommendation records during and after import. * * @author Daniele Sciannimanica */ -class RecommendationArchiveValidator implements ValidatorInterface +class RecommendationArchiveValidator { static public function getTrigger(): string { From 8aca2f66686ab0256141a3f4569afb9b50275e0f Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek <55794780+zoglo@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:22:08 +0100 Subject: [PATCH 3/5] Consider archive connections --- contao/config/config.php | 1 + .../Import/AddRecommendationValidatorListener.php | 11 +++++++++++ translations/setup.de.yaml | 9 +++++++++ translations/setup.en.yaml | 9 +++++++++ 4 files changed, 30 insertions(+) diff --git a/contao/config/config.php b/contao/config/config.php index 8696869..2d8de38 100644 --- a/contao/config/config.php +++ b/contao/config/config.php @@ -43,3 +43,4 @@ // Add product installer validators $GLOBALS['PI_HOOKS']['addValidator'][] = [AddRecommendationValidatorListener::class, 'addValidators']; +$GLOBALS['PI_HOOKS']['setModuleValidatorArchiveConnections'][] = [AddRecommendationValidatorListener::class, 'setArchiveConnections']; diff --git a/src/EventListener/Import/AddRecommendationValidatorListener.php b/src/EventListener/Import/AddRecommendationValidatorListener.php index b622295..177abb4 100644 --- a/src/EventListener/Import/AddRecommendationValidatorListener.php +++ b/src/EventListener/Import/AddRecommendationValidatorListener.php @@ -14,7 +14,9 @@ namespace Oveleon\ContaoRecommendationBundle\EventListener\Import; use Oveleon\ContaoRecommendationBundle\Import\Validator\RecommendationArchiveValidator; +use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel; use Oveleon\ProductInstaller\Import\Validator; +use Oveleon\ProductInstaller\Import\Validator\ModuleValidator; class AddRecommendationValidatorListener { @@ -23,4 +25,13 @@ public function addValidators(): void // Connects jumpTo pages Validator::addValidatorCollection([RecommendationArchiveValidator::class], ['setJumpToPageConnection']); } + + public function setArchiveConnections(array $row): array + { + return match ($row['type']) { + 'recommendationlist', 'recommendationreader' => ['field' => 'recommendation_archives', 'table' => RecommendationArchiveModel::getTable()], + 'recommendationform' => ['field' => 'recommendation_archive', 'table' => RecommendationArchiveModel::getTable()], + default => [], + }; + } } diff --git a/translations/setup.de.yaml b/translations/setup.de.yaml index 2778805..cd51130 100644 --- a/translations/setup.de.yaml +++ b/translations/setup.de.yaml @@ -8,3 +8,12 @@ setup: label: 'Bewertungen-Archiv → Weiterleitungsseite' description: 'Ein oder mehrere Bewertungen-Archive verweisen auf eine Weiterleitungsseite, welche nicht aufgelöst werden kann. Ihre Auswahl wird für alle weiteren Bewertungen-Archive, welche auf die selbe Weiterleitungsseite referenzieren, übernommen.' explanation: 'Beim Importieren eines oder mehrerer Bewertungen-Archive konnte die zugehörige Weiterleitungsseite nicht gefunden werden. Wählen Sie bitte eine Seite aus Ihrer Contao-Instanz, um eine Verknüpfung zwischen diesen Archiven und einer Seite herzustellen.

Folgende Seite wurde nicht importiert und benötigt eine Alternative:' + module: + recommendation_archives: + label: 'Modul → Bewertungsarchive' + description: 'Dem Modul konnten ein oder mehrere Archive nicht zugeordnet werden. Ihre Auswahl wird für das derzeitige Modul übernommen.' + explanation: 'Beim Importieren eines oder mehrerer Module konnten zugehörige Archive nicht gefunden werden. Wählen Sie bitte ein Archiv aus Ihrer Contao-Instanz aus, um eine Verknüpfung zwischen diesem Modul und einem Archiv herzustellen.' + recommendation_archive: + label: 'Modul → Bewertungsarchiv' + description: 'Dem Modul konnte kein Archiv nicht zugeordnet werden. Ihre Auswahl wird für das derzeitige Modul übernommen.' + explanation: 'Beim Importieren eines Moduls konnte kein zugehöriges Archiv gefunden werden. Wählen Sie bitte ein Archiv aus Ihrer Contao-Instanz aus, um eine Verknüpfung zwischen diesem Modul und einem Archiv herzustellen.' diff --git a/translations/setup.en.yaml b/translations/setup.en.yaml index e38add1..7b4e1bf 100644 --- a/translations/setup.en.yaml +++ b/translations/setup.en.yaml @@ -8,3 +8,12 @@ setup: label: 'Recommendation-Archive → Redirect page' description: 'One or more recommendation archives refer to a forwarding page that cannot be resolved. Your selection is applied to all other rating archives that reference the same redirection page.' explanation: 'When importing one or more recommendation archives, the corresponding redirect page could not be found. Please select a page from your Contao instance to create a link between these archives and a page.

The following page was not imported and needs an alternative:' + module: + recommendation_archives: + label: 'Module → Recommendation archives' + description: 'One or more archives could not be assigned to the module. Your selection will be applied to the current module.' + explanation: 'During the import of one or more modules, the corresponding archives could not be found. Please select an archive from your Contao instance to create a link between this module and an archive.' + recommendation_archive: + label: 'Module → Recommendation archive' + description: 'No archive could not be assigned to the module. Your selection will be applied to the current module.' + explanation: 'During the import of a module, no associated archive could be found. Please select an archive from your Contao instance to create a link between this module and an archive.' From fdcfd0333fa908d0db59abf44b5b891184030379 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek <55794780+zoglo@users.noreply.github.com> Date: Mon, 4 Mar 2024 12:34:59 +0100 Subject: [PATCH 4/5] Add setUserGroupArchiveConnections --- contao/config/config.php | 3 ++- .../Import/AddRecommendationValidatorListener.php | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/contao/config/config.php b/contao/config/config.php index 2d8de38..f5bfc2b 100644 --- a/contao/config/config.php +++ b/contao/config/config.php @@ -43,4 +43,5 @@ // Add product installer validators $GLOBALS['PI_HOOKS']['addValidator'][] = [AddRecommendationValidatorListener::class, 'addValidators']; -$GLOBALS['PI_HOOKS']['setModuleValidatorArchiveConnections'][] = [AddRecommendationValidatorListener::class, 'setArchiveConnections']; +$GLOBALS['PI_HOOKS']['setModuleValidatorArchiveConnections'][] = [AddRecommendationValidatorListener::class, 'setModuleArchiveConnections']; +$GLOBALS['PI_HOOKS']['setUserGroupValidatorArchiveConnections'][] = [AddRecommendationValidatorListener::class, 'setUserGroupArchiveConnections']; diff --git a/src/EventListener/Import/AddRecommendationValidatorListener.php b/src/EventListener/Import/AddRecommendationValidatorListener.php index 177abb4..2b5e82f 100644 --- a/src/EventListener/Import/AddRecommendationValidatorListener.php +++ b/src/EventListener/Import/AddRecommendationValidatorListener.php @@ -26,7 +26,7 @@ public function addValidators(): void Validator::addValidatorCollection([RecommendationArchiveValidator::class], ['setJumpToPageConnection']); } - public function setArchiveConnections(array $row): array + public function setModuleArchiveConnections(array $row): array { return match ($row['type']) { 'recommendationlist', 'recommendationreader' => ['field' => 'recommendation_archives', 'table' => RecommendationArchiveModel::getTable()], @@ -34,4 +34,9 @@ public function setArchiveConnections(array $row): array default => [], }; } + + public function setUserGroupArchiveConnections(array &$connections): void + { + $connections['recommendations'] = RecommendationArchiveModel::getTable(); + } } From 899ada25b4dfa97da7b4648702ec3166d6df742e Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek <55794780+zoglo@users.noreply.github.com> Date: Tue, 5 Mar 2024 13:38:57 +0100 Subject: [PATCH 5/5] Add translations --- translations/setup.de.yaml | 4 ++++ translations/setup.en.yaml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/translations/setup.de.yaml b/translations/setup.de.yaml index cd51130..55194af 100644 --- a/translations/setup.de.yaml +++ b/translations/setup.de.yaml @@ -17,3 +17,7 @@ setup: label: 'Modul → Bewertungsarchiv' description: 'Dem Modul konnte kein Archiv nicht zugeordnet werden. Ihre Auswahl wird für das derzeitige Modul übernommen.' explanation: 'Beim Importieren eines Moduls konnte kein zugehöriges Archiv gefunden werden. Wählen Sie bitte ein Archiv aus Ihrer Contao-Instanz aus, um eine Verknüpfung zwischen diesem Modul und einem Archiv herzustellen.' + user_group: + recommendations: + label: 'Benutzergruppe "%userGroupName%" → Bewertungsarchive' + description: 'Ein oder mehrere Archive konnten nicht zugewiesen werden, bitte weisen Sie diese manuell zu.' diff --git a/translations/setup.en.yaml b/translations/setup.en.yaml index 7b4e1bf..b89681a 100644 --- a/translations/setup.en.yaml +++ b/translations/setup.en.yaml @@ -17,3 +17,7 @@ setup: label: 'Module → Recommendation archive' description: 'No archive could not be assigned to the module. Your selection will be applied to the current module.' explanation: 'During the import of a module, no associated archive could be found. Please select an archive from your Contao instance to create a link between this module and an archive.' + user_group: + recommendations: + label: 'User group "%userGroupName%" → Recommendation archives' + description: 'One or more archives could not be assigned, please assign them manually.'