Skip to content
Snippets Groups Projects
Commit 6aee664b authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[BUGFIX] Replace AbstractUpdate class

parent d40c1409
No related branches found
No related tags found
1 merge request!25Feature upgrade to typo3 10
...@@ -31,57 +31,58 @@ use TYPO3\CMS\Backend\Utility\BackendUtility; ...@@ -31,57 +31,58 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Updates\AbstractUpdate; use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
/** /**
* Migrate template db entries to the correct root pages * Migrate template db entries to the correct root pages
*/ */
class UpdateAuthors extends AbstractUpdate { class UpdateAuthors implements UpgradeWizardInterface {
/** /**
* @var string * Retrieves the next site root in the page hierarchy from the current page
*
* @param int $currentPid
* @return int
*/ */
protected $identifier = 'tx_sgnews_update_authors'; protected function getSiteRoot($currentPid): int {
$rootLine = BackendUtility::BEgetRootLine((int) $currentPid);
$siteRoot = ['uid' => 0];
foreach ($rootLine as $page) {
if ((int) $page['is_siteroot'] === 1) {
$siteRoot = $page;
break;
}
}
return $siteRoot['uid'];
}
/** /**
* @var string * @return string
*/ */
protected $title = 'Migrate all news authors to the new author table for each site root.'; public function getIdentifier(): string {
return 'tx_sgnews_update_authors';
}
/** /**
* Checks whether updates are required. * @return string
*
* @param string &$description The description for the update
* @return bool Whether an update is required (TRUE) or not (FALSE)
*/ */
public function checkForUpdate(&$description) { public function getTitle(): string {
$description = 'Create new author entries for the old author field of news pages'; return 'Migrate all news authors to the new author table for each site root.';
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$rowCount = $queryBuilder->select('*')
->from('pages')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('doktype', News::DOK_TYPE_NEWS),
$queryBuilder->expr()->isNotNull('author')
)
)
->execute()->rowCount();
return $rowCount > 0;
} }
/** /**
* Performs the according updates. * @return string
*
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
*/ */
public function performUpdate(array &$dbQueries, &$customMessages) { public function getDescription(): string {
$dbQueries = []; return 'Create new author entries for the old author field of news pages';
}
/**
* @return bool
*/
public function executeUpdate(): bool {
$newsQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); $newsQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$newsQueryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $newsQueryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$newsEntries = $newsQueryBuilder->select('*') $newsEntries = $newsQueryBuilder->select('*')
...@@ -94,7 +95,6 @@ class UpdateAuthors extends AbstractUpdate { ...@@ -94,7 +95,6 @@ class UpdateAuthors extends AbstractUpdate {
) )
->execute()->fetchAll(); ->execute()->fetchAll();
if (count($newsEntries) <= 0) { if (count($newsEntries) <= 0) {
$this->markWizardAsDone();
return TRUE; return TRUE;
} }
foreach ($newsEntries as $news) { foreach ($newsEntries as $news) {
...@@ -127,8 +127,6 @@ class UpdateAuthors extends AbstractUpdate { ...@@ -127,8 +127,6 @@ class UpdateAuthors extends AbstractUpdate {
'crdate' => time(), 'crdate' => time(),
'tstamp' => time(), 'tstamp' => time(),
])->execute(); ])->execute();
$dbQueries[] = $authorQueryBuilder->getSQL();
$authorUid = (int) $authorQueryBuilder->getConnection()->lastInsertId(); $authorUid = (int) $authorQueryBuilder->getConnection()->lastInsertId();
} else { } else {
$authorUid = $author[0]['uid']; $authorUid = $author[0]['uid'];
...@@ -139,30 +137,36 @@ class UpdateAuthors extends AbstractUpdate { ...@@ -139,30 +137,36 @@ class UpdateAuthors extends AbstractUpdate {
->set('author', '') ->set('author', '')
->where($newsQueryBuilder->expr()->eq('uid', $news['uid'])) ->where($newsQueryBuilder->expr()->eq('uid', $news['uid']))
->execute(); ->execute();
$dbQueries[] = $newsQueryBuilder->getSQL();
} }
$this->markWizardAsDone();
return TRUE; return TRUE;
} }
/** /**
* Retrieves the next site root in the page hierarchy from the current page * @return bool
*
* @param int $currentPid
* @return int
*/ */
protected function getSiteRoot($currentPid): int { public function updateNecessary(): bool {
$rootLine = BackendUtility::BEgetRootLine((int) $currentPid); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$siteRoot = ['uid' => 0]; $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$rowCount = $queryBuilder->select('*')
->from('pages')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('doktype', News::DOK_TYPE_NEWS),
$queryBuilder->expr()->isNotNull('author')
)
)
->execute()->rowCount();
foreach ($rootLine as $page) { return $rowCount > 0;
if ((int) $page['is_siteroot'] === 1) { }
$siteRoot = $page;
break;
}
}
return $siteRoot['uid']; /**
* @return array|string[]
*/
public function getPrerequisites(): array {
return [
DatabaseUpdatedPrerequisite::class
];
} }
} }
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