From 88228d58fba92567e0e32aa6712aa177917a57f2 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek <55794780+zoglo@users.noreply.github.com> Date: Mon, 11 Dec 2023 21:54:04 +0100 Subject: [PATCH 1/2] Skip migrations for non-existing style-manager groups (#84) --- src/StyleManager/Sync.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/StyleManager/Sync.php b/src/StyleManager/Sync.php index dd3318e..f3e311d 100644 --- a/src/StyleManager/Sync.php +++ b/src/StyleManager/Sync.php @@ -15,6 +15,7 @@ use Contao\Message; use Contao\Model\Collection; use Contao\StringUtil; +use Contao\System; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; use DOMDocument; @@ -22,16 +23,20 @@ use DOMNode; use Oveleon\ContaoComponentStyleManager\Model\StyleManagerArchiveModel; use Oveleon\ContaoComponentStyleManager\Model\StyleManagerModel; +use Psr\Log\LoggerInterface; class Sync { protected ContaoFramework $framework; protected Connection $connection; - public function __construct(ContaoFramework $framework, Connection $connection) + private ?LoggerInterface $logger; + + public function __construct(ContaoFramework $framework, Connection $connection, LoggerInterface $logger = null) { $this->framework = $framework; $this->connection = $connection; + $this->logger = $logger; } /** @@ -65,6 +70,13 @@ public function shouldRunObjectConversion($table = null): bool $key = array_keys($arrConfig)[1]; } + if (is_numeric($key) && empty(StyleManagerModel::findById($key))) + { + // Skip if the configuration was already converted or can not be found anymore as the PK does not exist + $this->logger->error('Style Manager conversion for table "'.$table.'" and id "'.$key.'" has been skipped due to primary key not existing anymore.)'); + return false; + } + return is_numeric($key); } From 7b8661423b125c6b84c799ae321d0e98f9be60de Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek <55794780+zoglo@users.noreply.github.com> Date: Tue, 12 Dec 2023 00:14:58 +0100 Subject: [PATCH 2/2] Fix typo for log message --- src/StyleManager/Sync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StyleManager/Sync.php b/src/StyleManager/Sync.php index f3e311d..476b240 100644 --- a/src/StyleManager/Sync.php +++ b/src/StyleManager/Sync.php @@ -73,7 +73,7 @@ public function shouldRunObjectConversion($table = null): bool if (is_numeric($key) && empty(StyleManagerModel::findById($key))) { // Skip if the configuration was already converted or can not be found anymore as the PK does not exist - $this->logger->error('Style Manager conversion for table "'.$table.'" and id "'.$key.'" has been skipped due to primary key not existing anymore.)'); + $this->logger->error('Style Manager conversion for table "'.$table.'" and id "'.$key.'" has been skipped due to primary key not existing anymore.'); return false; }