From a2477dbca9a324ce1d5c5e6f0354d3b0cd7a75af Mon Sep 17 00:00:00 2001 From: Torsten Oppermann <torsten@sgalinski.de> Date: Tue, 24 Jul 2018 19:28:47 +0200 Subject: [PATCH] [TASK] Fixing a bug with matching the tags when migrating news --- .../Command/MigrateNewsCommandController.php | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Classes/Command/MigrateNewsCommandController.php b/Classes/Command/MigrateNewsCommandController.php index 8be0cbc..78911fb 100644 --- a/Classes/Command/MigrateNewsCommandController.php +++ b/Classes/Command/MigrateNewsCommandController.php @@ -174,11 +174,7 @@ class MigrateNewsCommandController extends CommandController { $date = new \DateTime('@' . $row['datetime']); $newsPage->setLastUpdated($date); - - $matchingTag = $this->getMatchingTag($row); - if ($matchingTag && $matchingTag instanceof Tag) { - $newsPage->addTag($matchingTag); - } + $this->setMatchingTag($row); /** @var File $image */ $file = $this->getMatchingFile($row); @@ -253,17 +249,26 @@ class MigrateNewsCommandController extends CommandController { * Get the tag / category, matching the news * * @param array $row - * @return Object $tag */ - private function getMatchingTag(array $row) { - // look up the correct category id, if they have changed - if (isset($this->categoryMap[(int) $row['categories']])) { - $categoryId = $this->categoryMap[(int) $row['categories']]; - } else { - $categoryId = (int) $row['categories']; - } + private function setMatchingTag(array $row) { + /** @var DatabaseConnection $db */ + $db = $GLOBALS['TYPO3_DB']; + // get content element from the original page + $where = 'uid_foreign = ' . (int) $row['uid']; + + /** @var \mysqli_result $result */ + $result = $db->exec_SELECTquery('uid_local', 'sys_category_record_mm_news_migration', $where); - return $this->tagRepository->findByUid($categoryId); + foreach ($result->fetch_row() as $mmRow) { + + $values = [ + 'uid_local' => $this->categoryMap[(int) $mmRow[0]], + 'uid_foreign' => $this->newsPagesMap[(int) $row['uid']], + 'tablenames' => 'pages', + 'fieldname' => 'tx_sgnews_tags' + ]; + $db->exec_INSERTquery('sys_category_record_mm', $values); + } } /** -- GitLab