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;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
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
*/
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.
*
* @param string &$description The description for the update
* @return bool Whether an update is required (TRUE) or not (FALSE)
* @return string
*/
public function checkForUpdate(&$description) {
$description = 'Create new author entries for the old author field of news pages';
$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;
public function getTitle(): string {
return 'Migrate all news authors to the new author table for each site root.';
}
/**
* Performs the according updates.
*
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
* @return string
*/
public function performUpdate(array &$dbQueries, &$customMessages) {
$dbQueries = [];
public function getDescription(): string {
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->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$newsEntries = $newsQueryBuilder->select('*')
......@@ -94,7 +95,6 @@ class UpdateAuthors extends AbstractUpdate {
)
->execute()->fetchAll();
if (count($newsEntries) <= 0) {
$this->markWizardAsDone();
return TRUE;
}
foreach ($newsEntries as $news) {
......@@ -127,8 +127,6 @@ class UpdateAuthors extends AbstractUpdate {
'crdate' => time(),
'tstamp' => time(),
])->execute();
$dbQueries[] = $authorQueryBuilder->getSQL();
$authorUid = (int) $authorQueryBuilder->getConnection()->lastInsertId();
} else {
$authorUid = $author[0]['uid'];
......@@ -139,30 +137,36 @@ class UpdateAuthors extends AbstractUpdate {
->set('author', '')
->where($newsQueryBuilder->expr()->eq('uid', $news['uid']))
->execute();
$dbQueries[] = $newsQueryBuilder->getSQL();
}
$this->markWizardAsDone();
return TRUE;
}
/**
* Retrieves the next site root in the page hierarchy from the current page
*
* @param int $currentPid
* @return int
* @return bool
*/
protected function getSiteRoot($currentPid): int {
$rootLine = BackendUtility::BEgetRootLine((int) $currentPid);
$siteRoot = ['uid' => 0];
public function updateNecessary(): bool {
$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();
foreach ($rootLine as $page) {
if ((int) $page['is_siteroot'] === 1) {
$siteRoot = $page;
break;
}
}
return $rowCount > 0;
}
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