diff --git a/Classes/Command/MigrateNewsCommandController.php b/Classes/Command/MigrateNewsCommandController.php index 8be0cbcd37765f99436ebc95b1bf2ba0c1ddadff..78911fb45619d2428aa411305c0a471f772c9e06 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); + } } /**