Skip to content
Snippets Groups Projects
Commit 414b9a1f authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Adding categories as tags to migrated news

parent 6f3cd905
No related branches found
No related tags found
1 merge request!6Feature news migration
...@@ -27,6 +27,7 @@ namespace SGalinski\SgNews\Command; ...@@ -27,6 +27,7 @@ namespace SGalinski\SgNews\Command;
***************************************************************/ ***************************************************************/
use SGalinski\SgNews\Domain\Model\News; use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Domain\Model\Tag;
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication; use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Database\DatabaseConnection; use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\DataHandling\DataHandler;
...@@ -57,6 +58,12 @@ class MigrateNewsCommandController extends CommandController { ...@@ -57,6 +58,12 @@ class MigrateNewsCommandController extends CommandController {
*/ */
protected $newsRepository; protected $newsRepository;
/**
* @var \SGalinski\SgNews\Domain\Repository\TagRepository
* @inject
*/
protected $tagRepository;
/** /**
* this array maps new pages to their original entry in the tx_news table * this array maps new pages to their original entry in the tx_news table
* *
...@@ -93,7 +100,8 @@ class MigrateNewsCommandController extends CommandController { ...@@ -93,7 +100,8 @@ class MigrateNewsCommandController extends CommandController {
/** @var DatabaseConnection $db */ /** @var DatabaseConnection $db */
$db = $GLOBALS['TYPO3_DB']; $db = $GLOBALS['TYPO3_DB'];
$where = 'hidden = 0 and deleted = 0'; $where = 'hidden = 0 and deleted = 0 and endtime = 0 and pid = 52';
/** @var \mysqli_result $result */ /** @var \mysqli_result $result */
$result = $db->exec_SELECTquery('*', 'tx_news_domain_model_news', $where); $result = $db->exec_SELECTquery('*', 'tx_news_domain_model_news', $where);
...@@ -137,20 +145,49 @@ class MigrateNewsCommandController extends CommandController { ...@@ -137,20 +145,49 @@ class MigrateNewsCommandController extends CommandController {
$title = date('Y-m-d', $row['datetime']) . ' - ' . $row['title']; $title = date('Y-m-d', $row['datetime']) . ' - ' . $row['title'];
$newsPage->setTitle($title); $newsPage->setTitle($title);
$newsPage->setAuthor($row['author']); $newsPage->setAuthor($row['author']);
$newsPage->addTag($this->getMatchingTag($row));
$this->newsRepository->update($newsPage); $this->newsRepository->update($newsPage);
$this->persistenceManager->persistAll(); $this->persistenceManager->persistAll();
// update content element from the new page // update content element from the new page
$where = 'pid = ' . $newPageId . ' AND sys_language_uid = ' . (int) $row['sys_language_uid']; $where = 'pid = ' . $newPageId . ' AND sys_language_uid = ' . $this->languageMap[(int) $row['sys_language_uid']];
$db->exec_UPDATEquery('tt_content', $where, ['bodytext' => $row['bodytext']]); $db->exec_UPDATEquery('tt_content', $where, ['bodytext' => $row['bodytext']]);
} }
} else { // this row is a translation and should simply update the content accordingly } else { // this row is a translation and should simply update the content accordingly
$this->updateTranslation($row); $this->updateTranslation($row);
} }
} }
}
/**
* @param array $row
* @return Tag $tag
*
* @throws IllegalObjectTypeException
* @throws UnknownObjectException
*/
private function getMatchingTag(array $row) {
/** @var Tag $matchingTag */
$matchingTag = $this->tagRepository->findByUid((int) $row['categories']);
if ($matchingTag === NULL) {
$matchingTag = $this->objectManager->get(Tag::class);
/** @var DatabaseConnection $db */
$db = $GLOBALS['TYPO3_DB'];
$where = 'uid = ' . $row['categories'];
/** @var \mysqli_result $result */
$result = $db->exec_SELECTquery('title', 'sys_category', $where);
$matchingTag->setTitle($result->fetch_row()[0]);
$matchingTag->setPid(1);
$this->tagRepository->add($matchingTag);
}
$this->pagesToMigrate = $resultArray; $this->persistenceManager->persistAll();
return $matchingTag;
} }
/** /**
...@@ -172,14 +209,20 @@ class MigrateNewsCommandController extends CommandController { ...@@ -172,14 +209,20 @@ class MigrateNewsCommandController extends CommandController {
$result = $db->exec_SELECTquery('l18n_parent', 'tt_content', $where); $result = $db->exec_SELECTquery('l18n_parent', 'tt_content', $where);
$originalContentElement = $result->fetch_row(); $originalContentElement = $result->fetch_row();
$where = 'l18n_parent = ' . (int) $originalContentElement[0]; // if its the new defaul, there is no l18n_parent
if ((int) $this->languageMap[(int) $row['sys_language_uid'] === 0]) {
$where = 'uid = ' . (int) $originalContentElement[0];
} else {
$where = 'l18n_parent = ' . (int) $originalContentElement[0];
}
// look up the correct language id, if they have changed // look up the correct language id, if they have changed
if ($this->languageMap[(int) $row['sys_language_uid']]) { if (isset($this->languageMap[(int) $row['sys_language_uid']])) {
$where .= ' AND sys_language_uid = ' . $this->languageMap[(int) $row['sys_language_uid']]; $where .= ' AND sys_language_uid = ' . $this->languageMap[(int) $row['sys_language_uid']];
} else { } else {
$where .= ' AND sys_language_uid = ' . (int) $row['sys_language_uid']; $where .= ' AND sys_language_uid = ' . (int) $row['sys_language_uid'];
} }
$db->exec_UPDATEquery('tt_content', $where, ['bodytext' => $row['bodytext']]); $db->exec_UPDATEquery('tt_content', $where, ['bodytext' => $row['bodytext']]);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment