Skip to content
Snippets Groups Projects
Commit 5b0847f3 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[TASK] Drastically improve the upgrade wizard (performance, functionality)

parent 3d72f981
No related branches found
No related tags found
No related merge requests found
......@@ -68,28 +68,19 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
public function checkForUpdate(&$description) {
$description = 'Move site root ids to pid & update pids to their correspondent site root ids';
// check if site_root columns actually exist
$hasColumn = [];
foreach ($this->tables as $table) {
$hasColumn[$table] = $this->siteRootColumnExists($table);
}
// are there site root columns differing from pids?
foreach ($this->tables as $table) {
if (!$hasColumn[$table]) {
if (!$this->siteRootColumnExists($table)) {
continue;
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$rowCount = $queryBuilder->select('*')
->from($table)
->where(
$queryBuilder->expr()->neq('site_root_id', 'pid')
)
->where($queryBuilder->expr()->neq('site_root_id', 'pid'))
->execute()->rowCount();
if ($rowCount > 0) {
return TRUE;
break;
}
}
......@@ -97,9 +88,7 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
foreach ($this->tables as $table) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$result = $queryBuilder->select('pid')
->from($table)
->execute()->fetchAll();
$result = $queryBuilder->select('pid')->from($table)->groupBy('pid')->execute();
foreach ($result as $row) {
$siteRootId = BackendService::getSiteRoot($row['pid']);
if ($siteRootId !== $row['pid']) {
......@@ -117,57 +106,29 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
* @throws \Doctrine\DBAL\DBALException
*/
public function performUpdate(array &$dbQueries, &$customMessages) {
$dbQueries = [];
// set pids to siteroot
foreach ($this->tables as $table) {
if (!$this->siteRootColumnExists($table)) {
continue;
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$result = $queryBuilder->select('uid', 'site_root_id')
->from($table)
->execute()->fetchAll();
$dbQueries[] = $queryBuilder->getSQL();
/** @var array $result */
foreach ($result as $row) {
$queryBuilder->update($table)
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT))
)
->set('pid', (int) $row['site_root_id'])
->execute();
$dbQueries[] = $queryBuilder->getSQL();
}
}
// check if pid is a site root, if not update it to the nearest one
foreach ($this->tables as $table) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$result = $queryBuilder->select('uid', 'pid')
->from($table)
->execute()->fetchAll();
$dbQueries[] = $queryBuilder->getSQL();
/** @var array $result */
foreach ($result as $row) {
$siteRootId = BackendService::getSiteRoot($row['pid']);
if ($siteRootId === 0) {
$siteRootId = 1;
}
if ($siteRootId !== (int) $row['pid']) {
$queryBuilder->update($table)
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT))
)
->set('pid', $siteRootId, TRUE)
->execute();
if ($this->siteRootColumnExists($table)) {
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
$sql = 'UPDATE ' . $table . ' SET pid = site_root_id';
$connection->executeQuery($sql);
$dbQueries[] = $sql;
} else {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll()->add(
GeneralUtility::makeInstance(DeletedRestriction::class)
);
$result = $queryBuilder->select('pid')->from($table)->groupBy('pid')->execute();
/** @var array $result */
foreach ($result as $row) {
$siteRootId = BackendService::getSiteRoot($row['pid']);
if ($siteRootId === 0) {
$siteRootId = 1;
}
$queryBuilder->update($table)->set('pid', $siteRootId)->where('pid = ' . $row['pid'])->execute();
$dbQueries[] = $queryBuilder->getSQL();
}
}
......@@ -180,17 +141,12 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
/**
* check if site_root columns actually exist
*
* @param $table
* @param string $table
* @return bool
*/
private function siteRootColumnExists($table) {
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
$result = $connection->getSchemaManager()->listTableColumns($table);
if (\array_key_exists('site_root_id', $result)) {
return TRUE;
}
return FALSE;
return \array_key_exists('site_root_id', $result);
}
}
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