From 5d03ccae2d60a34b8ae4802ed576aa018776a101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20Schottm=C3=BCller?= Date: Wed, 20 Nov 2024 23:21:19 +0100 Subject: [PATCH] Fixed wrong imports Correctly wired listeners and services --- src/DependencyInjection/TagsExtension.php | 4 +- .../DataContainer/ArticleCallbackListener.php | 53 ++++++++++++++ .../ArticleCopyCallbackListener.php | 34 --------- .../ArticleDeleteCallbackListener.php | 35 --------- .../CalendarCallbackListener.php | 47 ++++++++++++ .../CalendarEventCopyCallbackListener.php | 34 --------- .../CalendarEventDeleteCallbackListener.php | 28 -------- .../DataContainer/ContentCallbackListener.php | 47 ++++++++++++ .../ContentCopyCallbackListener.php | 34 --------- .../ContentDeleteCallbackListener.php | 28 -------- .../DataContainer/FaqCallbackListener.php | 47 ++++++++++++ .../DataContainer/FaqCopyCallbackListener.php | 34 --------- .../FaqDeleteCallbackListener.php | 28 -------- .../DataContainer/FileCallbackListener.php | 57 +++++++++++++++ .../FileCopyCallbackListener.php | 41 ----------- .../FileDeleteCallbackListener.php | 32 --------- .../DataContainer/MemberCallbackListener.php | 47 ++++++++++++ .../MemberCopyCallbackListener.php | 34 --------- .../MemberDeleteCallbackListener.php | 28 -------- .../DataContainer/NewsCallbackListener.php | 70 ++++++++++++++++++ .../NewsCopyCallbackListener.php | 34 --------- .../NewsDeleteCallbackListener.php | 28 -------- .../NewsLoadCallbackListener.php | 38 ---------- ...kListener.php => PageCallbackListener.php} | 28 ++++---- .../TagsInsertTag.php} | 43 +++++++++-- src/InsertTag/TagsArticleInsertTag.php | 26 ------- src/InsertTag/TagsArticleUrlInsertTag.php | 26 ------- src/InsertTag/TagsContentInsertTag.php | 26 ------- src/InsertTag/TagsEventInsertTag.php | 26 ------- src/InsertTag/TagsFaqInsertTag.php | 26 ------- src/InsertTag/TagsFileInsertTag.php | 26 ------- src/InsertTag/TagsNewsInsertTag.php | 26 ------- src/Resources/config/listener.yml | 72 +++++++++++++++++++ src/Resources/config/services.yml | 3 + src/Resources/contao/classes/CalendarTags.php | 5 +- src/Resources/contao/classes/NewsTags.php | 5 +- src/Resources/contao/classes/TagHelper.php | 1 + .../contao/modules/ModuleEventReaderTags.php | 1 + 38 files changed, 504 insertions(+), 698 deletions(-) create mode 100644 src/EventListener/DataContainer/ArticleCallbackListener.php delete mode 100644 src/EventListener/DataContainer/ArticleCopyCallbackListener.php delete mode 100644 src/EventListener/DataContainer/ArticleDeleteCallbackListener.php create mode 100644 src/EventListener/DataContainer/CalendarCallbackListener.php delete mode 100644 src/EventListener/DataContainer/CalendarEventCopyCallbackListener.php delete mode 100644 src/EventListener/DataContainer/CalendarEventDeleteCallbackListener.php create mode 100644 src/EventListener/DataContainer/ContentCallbackListener.php delete mode 100644 src/EventListener/DataContainer/ContentCopyCallbackListener.php delete mode 100644 src/EventListener/DataContainer/ContentDeleteCallbackListener.php create mode 100644 src/EventListener/DataContainer/FaqCallbackListener.php delete mode 100644 src/EventListener/DataContainer/FaqCopyCallbackListener.php delete mode 100644 src/EventListener/DataContainer/FaqDeleteCallbackListener.php create mode 100644 src/EventListener/DataContainer/FileCallbackListener.php delete mode 100644 src/EventListener/DataContainer/FileCopyCallbackListener.php delete mode 100644 src/EventListener/DataContainer/FileDeleteCallbackListener.php create mode 100644 src/EventListener/DataContainer/MemberCallbackListener.php delete mode 100644 src/EventListener/DataContainer/MemberCopyCallbackListener.php delete mode 100644 src/EventListener/DataContainer/MemberDeleteCallbackListener.php create mode 100644 src/EventListener/DataContainer/NewsCallbackListener.php delete mode 100644 src/EventListener/DataContainer/NewsCopyCallbackListener.php delete mode 100644 src/EventListener/DataContainer/NewsDeleteCallbackListener.php delete mode 100644 src/EventListener/DataContainer/NewsLoadCallbackListener.php rename src/EventListener/DataContainer/{PageDeleteCallbackListener.php => PageCallbackListener.php} (50%) rename src/InsertTag/{TagsUsedInsertTag.php => Resolver/TagsInsertTag.php} (52%) delete mode 100644 src/InsertTag/TagsArticleInsertTag.php delete mode 100644 src/InsertTag/TagsArticleUrlInsertTag.php delete mode 100644 src/InsertTag/TagsContentInsertTag.php delete mode 100644 src/InsertTag/TagsEventInsertTag.php delete mode 100644 src/InsertTag/TagsFaqInsertTag.php delete mode 100644 src/InsertTag/TagsFileInsertTag.php delete mode 100644 src/InsertTag/TagsNewsInsertTag.php create mode 100644 src/Resources/config/listener.yml diff --git a/src/DependencyInjection/TagsExtension.php b/src/DependencyInjection/TagsExtension.php index 88c7b6e..c293bb9 100644 --- a/src/DependencyInjection/TagsExtension.php +++ b/src/DependencyInjection/TagsExtension.php @@ -27,7 +27,7 @@ public function load(array $mergedConfig, ContainerBuilder $container) new FileLocator(__DIR__.'/../Resources/config') ); - //$loader->load('listener.yml'); - //$loader->load('services.yml'); + $loader->load('listener.yml'); + $loader->load('services.yml'); } } diff --git a/src/EventListener/DataContainer/ArticleCallbackListener.php b/src/EventListener/DataContainer/ArticleCallbackListener.php new file mode 100644 index 0000000..1c0d3d8 --- /dev/null +++ b/src/EventListener/DataContainer/ArticleCallbackListener.php @@ -0,0 +1,53 @@ +id) { + return; + } + + $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); + $tags = array(); + while (($row = $objTags->fetchAssociative()) !== false) { + \array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); + } + foreach ($tags as $entry) { + $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); + } + } + + #[AsCallback(table: 'tl_article', target: 'config.ondelete')] + public function onDeleteArticle(DataContainer $dc, int $undoId): void + { + if (!$dc->id) { + return; + } + + $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") + ->executeQuery(array($dc->table, $dc->id)); + $arrContentElements = $this->db->prepare("SELECT DISTINCT id FROM tl_content WHERE pid = ?") + ->executeQuery(array($dc->id)); + while (($row = $arrContentElements->fetchAssociative()) !== false) { + $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") + ->executeQuery(array('tl_content', $row['id'])); + } + } +} diff --git a/src/EventListener/DataContainer/ArticleCopyCallbackListener.php b/src/EventListener/DataContainer/ArticleCopyCallbackListener.php deleted file mode 100644 index 9d3c02a..0000000 --- a/src/EventListener/DataContainer/ArticleCopyCallbackListener.php +++ /dev/null @@ -1,34 +0,0 @@ -db = $db; - } - - public function __invoke(int $insertId, DataContainer $dc): void - { - if (!$dc->id) { - return; - } - - $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table); - $tags = array(); - while ($objTags->next()) { - \array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag)); - } - foreach ($tags as $entry) { - $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertId, $entry['tag'], $entry['table']); - } - } -} diff --git a/src/EventListener/DataContainer/ArticleDeleteCallbackListener.php b/src/EventListener/DataContainer/ArticleDeleteCallbackListener.php deleted file mode 100644 index 206b821..0000000 --- a/src/EventListener/DataContainer/ArticleDeleteCallbackListener.php +++ /dev/null @@ -1,35 +0,0 @@ -db = $db; - } - - public function __invoke(DataContainer $dc, int $undoId): void - { - if (!$dc->id) { - return; - } - - $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute($dc->table, $dc->id); - $arrContentElements = $this->db->prepare("SELECT DISTINCT id FROM tl_content WHERE pid = ?") - ->execute($dc->id)->fetchEach('id'); - foreach ($arrContentElements as $cte_id) - { - $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute('tl_content', $cte_id); - } - } -} diff --git a/src/EventListener/DataContainer/CalendarCallbackListener.php b/src/EventListener/DataContainer/CalendarCallbackListener.php new file mode 100644 index 0000000..6af95a2 --- /dev/null +++ b/src/EventListener/DataContainer/CalendarCallbackListener.php @@ -0,0 +1,47 @@ +id) { + return; + } + + $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); + $tags = array(); + while (($row = $objTags->fetchAssociative()) !== false) { + \array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); + } + foreach ($tags as $entry) { + $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); + } + } + + #[AsCallback(table: 'tl_calendar_events', target: 'config.ondelete')] + public function onDeleteCalendar(DataContainer $dc, int $undoId): void + { + if (!$dc->id) { + return; + } + + $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") + ->executeQuery(array($dc->table, $dc->id)); + } +} diff --git a/src/EventListener/DataContainer/CalendarEventCopyCallbackListener.php b/src/EventListener/DataContainer/CalendarEventCopyCallbackListener.php deleted file mode 100644 index 5af7158..0000000 --- a/src/EventListener/DataContainer/CalendarEventCopyCallbackListener.php +++ /dev/null @@ -1,34 +0,0 @@ -db = $db; - } - - public function __invoke(int $insertId, DataContainer $dc): void - { - if (!$dc->id) { - return; - } - - $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table); - $tags = array(); - while ($objTags->next()) { - \array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag)); - } - foreach ($tags as $entry) { - $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertId, $entry['tag'], $entry['table']); - } - } -} diff --git a/src/EventListener/DataContainer/CalendarEventDeleteCallbackListener.php b/src/EventListener/DataContainer/CalendarEventDeleteCallbackListener.php deleted file mode 100644 index 8dcd13f..0000000 --- a/src/EventListener/DataContainer/CalendarEventDeleteCallbackListener.php +++ /dev/null @@ -1,28 +0,0 @@ -db = $db; - } - - public function __invoke(DataContainer $dc, int $undoId): void - { - if (!$dc->id) { - return; - } - - $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute($dc->table, $dc->id); - } -} diff --git a/src/EventListener/DataContainer/ContentCallbackListener.php b/src/EventListener/DataContainer/ContentCallbackListener.php new file mode 100644 index 0000000..05be0fb --- /dev/null +++ b/src/EventListener/DataContainer/ContentCallbackListener.php @@ -0,0 +1,47 @@ +id) { + return; + } + + $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); + $tags = array(); + while (($row = $objTags->fetchAssociative()) !== false) { + \array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); + } + foreach ($tags as $entry) { + $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); + } + } + + #[AsCallback(table: 'tl_content', target: 'config.ondelete')] + public function onDeleteContent(DataContainer $dc, int $undoId): void + { + if (!$dc->id) { + return; + } + + $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") + ->executeQuery(array($dc->table, $dc->id)); + } +} diff --git a/src/EventListener/DataContainer/ContentCopyCallbackListener.php b/src/EventListener/DataContainer/ContentCopyCallbackListener.php deleted file mode 100644 index 61444ab..0000000 --- a/src/EventListener/DataContainer/ContentCopyCallbackListener.php +++ /dev/null @@ -1,34 +0,0 @@ -db = $db; - } - - public function __invoke(int $insertId, DataContainer $dc): void - { - if (!$dc->id) { - return; - } - - $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table); - $tags = array(); - while ($objTags->next()) { - \array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag)); - } - foreach ($tags as $entry) { - $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertId, $entry['tag'], $entry['table']); - } - } -} diff --git a/src/EventListener/DataContainer/ContentDeleteCallbackListener.php b/src/EventListener/DataContainer/ContentDeleteCallbackListener.php deleted file mode 100644 index ea38964..0000000 --- a/src/EventListener/DataContainer/ContentDeleteCallbackListener.php +++ /dev/null @@ -1,28 +0,0 @@ -db = $db; - } - - public function __invoke(DataContainer $dc, int $undoId): void - { - if (!$dc->id) { - return; - } - - $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute($dc->table, $dc->id); - } -} diff --git a/src/EventListener/DataContainer/FaqCallbackListener.php b/src/EventListener/DataContainer/FaqCallbackListener.php new file mode 100644 index 0000000..0a1dd27 --- /dev/null +++ b/src/EventListener/DataContainer/FaqCallbackListener.php @@ -0,0 +1,47 @@ +id) { + return; + } + + $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); + $tags = array(); + while (($row = $objTags->fetchAssociative()) !== false) { + \array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); + } + foreach ($tags as $entry) { + $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); + } + } + + #[AsCallback(table: 'tl_faq', target: 'config.ondelete')] + public function onDeleteFaq(DataContainer $dc, int $undoId): void + { + if (!$dc->id) { + return; + } + + $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") + ->executeQuery(array($dc->table, $dc->id)); + } +} diff --git a/src/EventListener/DataContainer/FaqCopyCallbackListener.php b/src/EventListener/DataContainer/FaqCopyCallbackListener.php deleted file mode 100644 index 61d9900..0000000 --- a/src/EventListener/DataContainer/FaqCopyCallbackListener.php +++ /dev/null @@ -1,34 +0,0 @@ -db = $db; - } - - public function __invoke(int $insertId, DataContainer $dc): void - { - if (!$dc->id) { - return; - } - - $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table); - $tags = array(); - while ($objTags->next()) { - \array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag)); - } - foreach ($tags as $entry) { - $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertId, $entry['tag'], $entry['table']); - } -} -} diff --git a/src/EventListener/DataContainer/FaqDeleteCallbackListener.php b/src/EventListener/DataContainer/FaqDeleteCallbackListener.php deleted file mode 100644 index 8b8fda4..0000000 --- a/src/EventListener/DataContainer/FaqDeleteCallbackListener.php +++ /dev/null @@ -1,28 +0,0 @@ -db = $db; - } - - public function __invoke(DataContainer $dc, int $undoId): void - { - if (!$dc->id) { - return; - } - - $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute($dc->table, $dc->id); -} -} diff --git a/src/EventListener/DataContainer/FileCallbackListener.php b/src/EventListener/DataContainer/FileCallbackListener.php new file mode 100644 index 0000000..f3935f9 --- /dev/null +++ b/src/EventListener/DataContainer/FileCallbackListener.php @@ -0,0 +1,57 @@ +id) { + return; + } + + //$sourceModel = FilesModel::findByPath($source); + //$destModel = FilesModel::findByPath($destination); + + //if ($sourceModel != null && $destModel != null) { + //$objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($sourceModel->id, $dc->table); + $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); + $tags = array(); + while (($row = $objTags->fetchAssociative()) !== false) { + \array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); + } + foreach ($tags as $entry) { +// $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($destModel->id, $entry['tag'], $entry['table']); + $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); + } + //} + } + + #[AsCallback(table: 'tl_files', target: 'config.ondelete')] + public function onDeleteFile(string $source, DataContainer $dc): void + { + if (!$dc->id) { + return; + } + + $fileModel = FilesModel::findByPath($source); + if ($fileModel != null) { + $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") + ->executeQuery(array($dc->table, $fileModel->id)); + } + } +} diff --git a/src/EventListener/DataContainer/FileCopyCallbackListener.php b/src/EventListener/DataContainer/FileCopyCallbackListener.php deleted file mode 100644 index a8e7566..0000000 --- a/src/EventListener/DataContainer/FileCopyCallbackListener.php +++ /dev/null @@ -1,41 +0,0 @@ -db = $db; - } - - public function __invoke(int $insertId, DataContainer $dc): void - { - if (!$dc->id) { - return; - } - - //$sourceModel = FilesModel::findByPath($source); - //$destModel = FilesModel::findByPath($destination); - - //if ($sourceModel != null && $destModel != null) { - //$objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($sourceModel->id, $dc->table); - $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table); - $tags = array(); - while ($objTags->next()) { - \array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag)); - } - foreach ($tags as $entry) { -// $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($destModel->id, $entry['tag'], $entry['table']); - $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertId, $entry['tag'], $entry['table']); - } - //} -} -} diff --git a/src/EventListener/DataContainer/FileDeleteCallbackListener.php b/src/EventListener/DataContainer/FileDeleteCallbackListener.php deleted file mode 100644 index d8e6ed8..0000000 --- a/src/EventListener/DataContainer/FileDeleteCallbackListener.php +++ /dev/null @@ -1,32 +0,0 @@ -db = $db; - } - - public function __invoke(string $source, DataContainer $dc): void - { - if (!$dc->id) { - return; - } - - $fileModel = FilesModel::findByPath($source); - if ($fileModel != null) { - $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute($dc->table, $fileModel->id); - } - } -} diff --git a/src/EventListener/DataContainer/MemberCallbackListener.php b/src/EventListener/DataContainer/MemberCallbackListener.php new file mode 100644 index 0000000..fc7931e --- /dev/null +++ b/src/EventListener/DataContainer/MemberCallbackListener.php @@ -0,0 +1,47 @@ +id) { + return; + } + + $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); + $tags = array(); + while (($row = $objTags->fetchAssociative()) !== false) { + \array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); + } + foreach ($tags as $entry) { + $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); + } + } + + #[AsCallback(table: 'tl_member', target: 'config.ondelete')] + public function onDeleteMember(DataContainer $dc, int $undoId): void + { + if (!$dc->id) { + return; + } + + $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") + ->executeQuery(array($dc->table, $dc->id)); + } +} diff --git a/src/EventListener/DataContainer/MemberCopyCallbackListener.php b/src/EventListener/DataContainer/MemberCopyCallbackListener.php deleted file mode 100644 index 1798cf2..0000000 --- a/src/EventListener/DataContainer/MemberCopyCallbackListener.php +++ /dev/null @@ -1,34 +0,0 @@ -db = $db; - } - - public function __invoke(int $insertId, DataContainer $dc): void - { - if (!$dc->id) { - return; - } - - $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table); - $tags = array(); - while ($objTags->next()) { - \array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag)); - } - foreach ($tags as $entry) { - $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertId, $entry['tag'], $entry['table']); - } -} -} diff --git a/src/EventListener/DataContainer/MemberDeleteCallbackListener.php b/src/EventListener/DataContainer/MemberDeleteCallbackListener.php deleted file mode 100644 index 9190d77..0000000 --- a/src/EventListener/DataContainer/MemberDeleteCallbackListener.php +++ /dev/null @@ -1,28 +0,0 @@ -db = $db; - } - - public function __invoke(DataContainer $dc, int $undoId): void - { - if (!$dc->id) { - return; - } - - $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute($dc->table, $dc->id); - } -} diff --git a/src/EventListener/DataContainer/NewsCallbackListener.php b/src/EventListener/DataContainer/NewsCallbackListener.php new file mode 100644 index 0000000..95d22dc --- /dev/null +++ b/src/EventListener/DataContainer/NewsCallbackListener.php @@ -0,0 +1,70 @@ +id) { + return; + } + + $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); + $tags = array(); + while (($row = $objTags->fetchAssociative()) !== false) { + \array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); + } + foreach ($tags as $entry) { + $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); + } + } + + #[AsCallback(table: 'tl_news', target: 'config.ondelete')] + public function onDeleteNews(DataContainer $dc, int $undoId): void + { + if (!$dc->id) { + return; + } + + $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") + ->executeQuery(array($dc->table, $dc->id)); + } + + #[AsCallback(table: 'tl_news', target: 'config.onload')] + public function onLoadNews(DataContainer|null $dc = null): void + { + if (null === $dc || !$dc->id || 'edit' !== $this->requestStack->getCurrentRequest()->query->get('act')) { + return; + } + + $element = ContentModel::findById($dc->id); + + /* + if (null === $element || 'my_content_element' !== $element->type) { + return; + } + + $GLOBALS['TL_DCA']['tl_content']['fields']['text']['eval']['mandatory'] = false; + */ + + //NewsTags::generateFeedsByArchive($dc->id); + } + +} diff --git a/src/EventListener/DataContainer/NewsCopyCallbackListener.php b/src/EventListener/DataContainer/NewsCopyCallbackListener.php deleted file mode 100644 index ba12ab7..0000000 --- a/src/EventListener/DataContainer/NewsCopyCallbackListener.php +++ /dev/null @@ -1,34 +0,0 @@ -db = $db; - } - - public function __invoke(int $insertId, DataContainer $dc): void - { - if (!$dc->id) { - return; - } - - $objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table); - $tags = array(); - while ($objTags->next()) { - \array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag)); - } - foreach ($tags as $entry) { - $this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertId, $entry['tag'], $entry['table']); - } - } -} diff --git a/src/EventListener/DataContainer/NewsDeleteCallbackListener.php b/src/EventListener/DataContainer/NewsDeleteCallbackListener.php deleted file mode 100644 index 7592cca..0000000 --- a/src/EventListener/DataContainer/NewsDeleteCallbackListener.php +++ /dev/null @@ -1,28 +0,0 @@ -db = $db; - } - - public function __invoke(DataContainer $dc, int $undoId): void - { - if (!$dc->id) { - return; - } - - $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute($dc->table, $dc->id); - } -} diff --git a/src/EventListener/DataContainer/NewsLoadCallbackListener.php b/src/EventListener/DataContainer/NewsLoadCallbackListener.php deleted file mode 100644 index 2ba7493..0000000 --- a/src/EventListener/DataContainer/NewsLoadCallbackListener.php +++ /dev/null @@ -1,38 +0,0 @@ -requestStack = $requestStack; - } - - public function __invoke(DataContainer|null $dc = null): void - { - if (null === $dc || !$dc->id || 'edit' !== $this->requestStack->getCurrentRequest()->query->get('act')) { - return; - } - - $element = ContentModel::findById($dc->id); - - /* - if (null === $element || 'my_content_element' !== $element->type) { - return; - } - - $GLOBALS['TL_DCA']['tl_content']['fields']['text']['eval']['mandatory'] = false; - */ - - //NewsTags::generateFeedsByArchive($dc->id); - } -} diff --git a/src/EventListener/DataContainer/PageDeleteCallbackListener.php b/src/EventListener/DataContainer/PageCallbackListener.php similarity index 50% rename from src/EventListener/DataContainer/PageDeleteCallbackListener.php rename to src/EventListener/DataContainer/PageCallbackListener.php index e9280b5..6974cb4 100644 --- a/src/EventListener/DataContainer/PageDeleteCallbackListener.php +++ b/src/EventListener/DataContainer/PageCallbackListener.php @@ -5,18 +5,19 @@ use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; use Contao\DataContainer; use Doctrine\DBAL\Connection; +use Symfony\Contracts\Translation\TranslatorInterface; -#[AsCallback(table: 'tl_page', target: 'config.ondelete')] -class PageDeleteCallbackListener +class PageCallbackListener { - private $db; - - public function __construct(Connection $db) + public function __construct( + private readonly TranslatorInterface $translator, + private readonly Connection $db, + ) { - $this->db = $db; } - public function __invoke(DataContainer $dc, int $undoId): void + #[AsCallback(table: 'tl_page', target: 'config.ondelete')] + public function onDeletePage(DataContainer $dc, int $undoId): void { if (!$dc->id) { return; @@ -24,18 +25,17 @@ public function __invoke(DataContainer $dc, int $undoId): void // remove tags of all articles in the page $arrArticles = $this->db->prepare("SELECT DISTINCT id FROM tl_article WHERE pid = ?") - ->execute($dc->id)->fetchEach('id'); - foreach ($arrArticles as $id) - { + ->executeQuery(array($dc->id)); + while (($row = $arrArticles->fetchAssociative()) !== false) { $arrContentElements = $this->db->prepare("SELECT DISTINCT id FROM tl_content WHERE pid = ?") - ->execute($id)->fetchEach('id'); - foreach ($arrContentElements as $cte_id) + ->executeQuery(array($row['id'])); + while (($crow = $arrContentElements->fetchAssociative()) !== false) { $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute('tl_content', $cte_id); + ->executeQuery(array('tl_content', $crow['id'])); } $this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") - ->execute('tl_article', $id); + ->executeQuery(array('tl_article', $row['id'])); } } } diff --git a/src/InsertTag/TagsUsedInsertTag.php b/src/InsertTag/Resolver/TagsInsertTag.php similarity index 52% rename from src/InsertTag/TagsUsedInsertTag.php rename to src/InsertTag/Resolver/TagsInsertTag.php index 77a969c..45cfd59 100644 --- a/src/InsertTag/TagsUsedInsertTag.php +++ b/src/InsertTag/Resolver/TagsInsertTag.php @@ -1,21 +1,52 @@ getParameters()->get(0)) { + throw new InvalidInsertTagException('Missing parameters for insert tag.'); + } + + $parameter = $insertTag->getParameters()->get(0); + + return match ($insertTag->getName()) { + 'tags_article' => new InsertTagResult(TagHelper::tagsForTableAndId('tl_article', $parameter, false), OutputType::text), + 'tags_article_url' => new InsertTagResult(TagHelper::tagsForTableAndId('tl_article_url', $parameter, false), OutputType::text), + 'tags_content' => new InsertTagResult(TagHelper::tagsForTableAndId('tl_content', $parameter, false), OutputType::text), + 'tags_event' => new InsertTagResult(TagHelper::tagsForTableAndId('tl_calendar_events', $parameter, false), OutputType::text), + 'tags_faq' => new InsertTagResult(TagHelper::tagsForTableAndId('tl_faq', $parameter, false), OutputType::text), + 'tags_file' => new InsertTagResult(TagHelper::tagsForTableAndId('tl_files', $parameter, false), OutputType::text), + 'tags_news' => new InsertTagResult(TagHelper::tagsForTableAndId('tl_news', $parameter, false), OutputType::text), + default => throw new InvalidInsertTagException(), + }; + + } + + #[AsInsertTag('tags_used')] + public function replaceInsertTagWithoutParameters(ResolvedInsertTag $insertTag): InsertTagResult { $parameter = $insertTag->getParameters()->get(0); if ($parameter == null) { diff --git a/src/InsertTag/TagsArticleInsertTag.php b/src/InsertTag/TagsArticleInsertTag.php deleted file mode 100644 index 23062be..0000000 --- a/src/InsertTag/TagsArticleInsertTag.php +++ /dev/null @@ -1,26 +0,0 @@ -getParameters()->get(0)) { - throw new InvalidInsertTagException('Missing parameters for insert tag.'); - } - - $parameter = $insertTag->getParameters()->get(0); - - $res = TagHelper::tagsForTableAndId('tl_article', $parameter, false, $max_tags, $relevance, $target); - return new InsertTagResult($res, OutputType::text); - } -} diff --git a/src/InsertTag/TagsArticleUrlInsertTag.php b/src/InsertTag/TagsArticleUrlInsertTag.php deleted file mode 100644 index 5dfbad0..0000000 --- a/src/InsertTag/TagsArticleUrlInsertTag.php +++ /dev/null @@ -1,26 +0,0 @@ -getParameters()->get(0)) { - throw new InvalidInsertTagException('Missing parameters for insert tag.'); - } - - $parameter = $insertTag->getParameters()->get(0); - - $res = TagHelper::tagsForTableAndId('tl_article_url', $parameter, false); - return new InsertTagResult($res, OutputType::text); - } -} diff --git a/src/InsertTag/TagsContentInsertTag.php b/src/InsertTag/TagsContentInsertTag.php deleted file mode 100644 index 1d989d5..0000000 --- a/src/InsertTag/TagsContentInsertTag.php +++ /dev/null @@ -1,26 +0,0 @@ -getParameters()->get(0)) { - throw new InvalidInsertTagException('Missing parameters for insert tag.'); - } - - $parameter = $insertTag->getParameters()->get(0); - - $res = TagHelper::tagsForTableAndId('tl_content', $parameter, false, $max_tags, $relevance, $target); - return new InsertTagResult($res, OutputType::text); - } -} diff --git a/src/InsertTag/TagsEventInsertTag.php b/src/InsertTag/TagsEventInsertTag.php deleted file mode 100644 index a6b11eb..0000000 --- a/src/InsertTag/TagsEventInsertTag.php +++ /dev/null @@ -1,26 +0,0 @@ -getParameters()->get(0)) { - throw new InvalidInsertTagException('Missing parameters for insert tag.'); - } - - $parameter = $insertTag->getParameters()->get(0); - - $res = TagHelper::tagsForTableAndId('tl_calendar_events', $parameter, false, $max_tags, $relevance, $target); - return new InsertTagResult($res, OutputType::text); - } -} diff --git a/src/InsertTag/TagsFaqInsertTag.php b/src/InsertTag/TagsFaqInsertTag.php deleted file mode 100644 index b66ad42..0000000 --- a/src/InsertTag/TagsFaqInsertTag.php +++ /dev/null @@ -1,26 +0,0 @@ -getParameters()->get(0)) { - throw new InvalidInsertTagException('Missing parameters for insert tag.'); - } - - $parameter = $insertTag->getParameters()->get(0); - - $res = TagHelper::tagsForTableAndId('tl_faq', $parameter, false, $max_tags, $relevance, $target); - return new InsertTagResult($res, OutputType::text); - } -} diff --git a/src/InsertTag/TagsFileInsertTag.php b/src/InsertTag/TagsFileInsertTag.php deleted file mode 100644 index fae26ad..0000000 --- a/src/InsertTag/TagsFileInsertTag.php +++ /dev/null @@ -1,26 +0,0 @@ -getParameters()->get(0)) { - throw new InvalidInsertTagException('Missing parameters for insert tag.'); - } - - $parameter = $insertTag->getParameters()->get(0); - - $res = TagHelper::tagsForTableAndId('tl_files', $parameter, false, $max_tags, $relevance, $target); - return new InsertTagResult($res, OutputType::text); - } -} diff --git a/src/InsertTag/TagsNewsInsertTag.php b/src/InsertTag/TagsNewsInsertTag.php deleted file mode 100644 index d05bd9d..0000000 --- a/src/InsertTag/TagsNewsInsertTag.php +++ /dev/null @@ -1,26 +0,0 @@ -getParameters()->get(0)) { - throw new InvalidInsertTagException('Missing parameters for insert tag.'); - } - - $parameter = $insertTag->getParameters()->get(0); - - $res = TagHelper::tagsForTableAndId('tl_news', $parameter, false, $max_tags, $relevance, $target); - return new InsertTagResult($res, OutputType::text); - } -} diff --git a/src/Resources/config/listener.yml b/src/Resources/config/listener.yml new file mode 100644 index 0000000..5835ba6 --- /dev/null +++ b/src/Resources/config/listener.yml @@ -0,0 +1,72 @@ +services: + _defaults: + autoconfigure: true + + contao.listener.compile_article: + class: Hschottm\TagsBundle\EventListener\CompileArticleListener + arguments: + - '@translator' + - '@database_connection' + + contao.listener.parse_articles: + class: Hschottm\TagsBundle\EventListener\ParseArticlesListener + arguments: + - '@translator' + - '@database_connection' + + contao.listener.revise_table: + class: Hschottm\TagsBundle\EventListener\ReviseTableListener + arguments: + - '@translator' + - '@database_connection' + - '@request_stack' + + contao.listener.data_container.article: + class: Hschottm\TagsBundle\EventListener\DataContainer\ArticleCallbackListener + arguments: + - '@translator' + - '@database_connection' + + contao.listener.data_container.calendar: + class: Hschottm\TagsBundle\EventListener\DataContainer\CalendarCallbackListener + arguments: + - '@translator' + - '@database_connection' + + contao.listener.data_container.content: + class: Hschottm\TagsBundle\EventListener\DataContainer\ContentCallbackListener + arguments: + - '@translator' + - '@database_connection' + + contao.listener.data_container.faq: + class: Hschottm\TagsBundle\EventListener\DataContainer\FaqCallbackListener + arguments: + - '@translator' + - '@database_connection' + + contao.listener.data_container.file: + class: Hschottm\TagsBundle\EventListener\DataContainer\FileCallbackListener + arguments: + - '@translator' + - '@database_connection' + + contao.listener.data_container.member: + class: Hschottm\TagsBundle\EventListener\DataContainer\MemberrCallbackListener + arguments: + - '@translator' + - '@database_connection' + + contao.listener.data_container.news: + class: Hschottm\TagsBundle\EventListener\DataContainer\NewsCallbackListener + arguments: + - '@translator' + - '@database_connection' + - '@request_stack' + + contao.listener.data_container.page: + class: Hschottm\TagsBundle\EventListener\DataContainer\PageCallbackListener + arguments: + - '@translator' + - '@database_connection' + diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 7292075..281d737 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,3 +1,6 @@ services: _defaults: autoconfigure: true + + contao.insert_tag.resolver.tags: + class: Hschottm\TagsBundle\InsertTag\Resolver\TagsInsertTag diff --git a/src/Resources/contao/classes/CalendarTags.php b/src/Resources/contao/classes/CalendarTags.php index ac818d9..c8b77eb 100644 --- a/src/Resources/contao/classes/CalendarTags.php +++ b/src/Resources/contao/classes/CalendarTags.php @@ -2,8 +2,9 @@ namespace Hschottm\TagsBundle; -use \Contao\Calendar; -use \Contao\Database; +use Contao\Calendar; +use Contao\Database; +use Contao\FrontendTemplate; /** * Contao Open Source CMS - tags extension diff --git a/src/Resources/contao/classes/NewsTags.php b/src/Resources/contao/classes/NewsTags.php index 6c80cec..b6d5328 100644 --- a/src/Resources/contao/classes/NewsTags.php +++ b/src/Resources/contao/classes/NewsTags.php @@ -10,8 +10,9 @@ namespace Hschottm\TagsBundle; -use \Contao\News; -use \Contao\Database; +use Contao\News; +use Contao\Database; +use Contao\FrontendTemplate; class NewsTags extends News { diff --git a/src/Resources/contao/classes/TagHelper.php b/src/Resources/contao/classes/TagHelper.php index be66f2e..0bff727 100644 --- a/src/Resources/contao/classes/TagHelper.php +++ b/src/Resources/contao/classes/TagHelper.php @@ -8,6 +8,7 @@ use Contao\Database; use Contao\PageModel; use Contao\StringUtil; +use Contao\FrontendTemplate; /** * Contao Open Source CMS - tags extension diff --git a/src/Resources/contao/modules/ModuleEventReaderTags.php b/src/Resources/contao/modules/ModuleEventReaderTags.php index a1de53c..79beafd 100644 --- a/src/Resources/contao/modules/ModuleEventReaderTags.php +++ b/src/Resources/contao/modules/ModuleEventReaderTags.php @@ -8,6 +8,7 @@ use Contao\CoreBundle\Exception\RedirectResponseException; use Contao\CoreBundle\Routing\ResponseContext\HtmlHeadBag\HtmlHeadBag; use Contao\Comments; +use Contao\FrontendTemplate; /** * Contao Open Source CMS - tags extension