From 13b1a98ee92938503d5566ca6b1c1762b11a0a01 Mon Sep 17 00:00:00 2001
From: Torsten Oppermann <torsten@sgalinski.de>
Date: Wed, 25 Jul 2018 09:16:01 +0200
Subject: [PATCH] [TASK] Fixing category mapping  bug

---
 Classes/Command/MigrateNewsCommandController.php | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Classes/Command/MigrateNewsCommandController.php b/Classes/Command/MigrateNewsCommandController.php
index 78911fb..5e781c5 100644
--- a/Classes/Command/MigrateNewsCommandController.php
+++ b/Classes/Command/MigrateNewsCommandController.php
@@ -112,7 +112,7 @@ class MigrateNewsCommandController extends CommandController {
 	public function runMigrateNewsCommand(
 		$copyPageId, $categoryPid, $year = 2015,
 		$languageMapAsJson = '{"3":1,"1":0,"2":2,"0":3}',
-		$categoryMapAsJson = '{"2":10,"3":11,"4":12,"5":13,"6":14,"7":15,"8":16,"9":17}',
+		$categoryMapAsJson = '{"2":17,"3":16,"4":15,"5":14,"6":14,"7":15,"8":16,"9":17}',
 		$pId = 52
 	) {
 		// fix repair translation bug where tsfe is missing from command controller, can be removed when v1.5 is released
@@ -249,23 +249,23 @@ class MigrateNewsCommandController extends CommandController {
 	 * Get the tag / category, matching the news
 	 *
 	 * @param array $row
+	 * @return News
 	 */
 	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);
-
-		foreach ($result->fetch_row() as $mmRow) {
+		$result = $db->exec_SELECTquery('uid_local, sorting_foreign', 'sys_category_record_mm_news_migration', $where);
 
+		while ($mmRow = $result->fetch_assoc()) {
 			$values = [
-				'uid_local' => $this->categoryMap[(int) $mmRow[0]],
+				'uid_local' => $this->categoryMap[(int) $mmRow['uid_local']],
 				'uid_foreign' => $this->newsPagesMap[(int) $row['uid']],
 				'tablenames' => 'pages',
-				'fieldname' => 'tx_sgnews_tags'
+				'fieldname' => 'tx_sgnews_tags',
+				'sorting_foreign' => (int) $mmRow['sorting_foreign']
 			];
 			$db->exec_INSERTquery('sys_category_record_mm', $values);
 		}
-- 
GitLab