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

[TASK] Staring work on new upgrade wizard

parent 2c0dd4e0
No related branches found
No related tags found
1 merge request!3New version 4 1
......@@ -65,14 +65,7 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
// check if site_root columns actually exist
$hasColumn = [];
foreach ($this->tables as $table) {
$hasColumn[$table] = FALSE;
$result = $databaseConnection->admin_get_fields($table);
foreach ($result as $column) {
if ($column['Field'] === 'site_root_id') {
$hasColumn[$table] = TRUE;
}
}
$hasColumn[$table] = $this->siteRootColumnExists($table);
}
// are there site root columns differing from pids?
......@@ -94,14 +87,12 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
foreach ($result as $row) {
$siteRootId = BackendService::getSiteRoot($row[0]);
if ($siteRootId !== $row[0]) {
return TRUE;
}
}
}
$this->isWizardDone();
return FALSE;
return !(!FALSE || $this->isWizardDone());
}
/**
......@@ -112,7 +103,68 @@ class UpdatePidToSiteRoot extends AbstractUpdate {
* @return bool Whether everything went smoothly or not
*/
public function performUpdate(array &$dbQueries, &$customMessages) {
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$dbQueries = [];
// set pids to siteroot
foreach ($this->tables as $table) {
if (!$this->siteRootColumnExists($table)) {
continue;
}
$result = $databaseConnection->exec_SELECTquery('uid, site_root_id', $table, '')->fetch_all();
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
/** @var array $result */
foreach ($result as $row) {
$where = 'uid = ' . $row[0];
$databaseConnection->exec_UPDATEquery($table, $where, ['pid' => $row[1]]);
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
}
}
// check if pid is a site root, if not update it to the nearest one
foreach ($this->tables as $table) {
$result = $databaseConnection->exec_SELECTquery('uid, pid', $table, '')->fetch_all();
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
/** @var array $result */
foreach ($result as $row) {
$siteRootId = BackendService::getSiteRoot($row[1]);
if ($siteRootId !== (int) $row[1]) {
if ($siteRootId === 0) {
$siteRootId = 1;
}
$where = 'uid = ' . $row[0];
$databaseConnection->exec_UPDATEquery($table, $where, ['pid' => $siteRootId]);
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
}
}
}
$this->markWizardAsDone();
return TRUE;
}
/**
* check if site_root columns actually exist
*
* @param $table
* @return bool
*/
private function siteRootColumnExists($table) {
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$result = $databaseConnection->admin_get_fields($table);
foreach ($result as $column) {
if ($column['Field'] === 'site_root_id') {
return TRUE;
}
}
return FALSE;
}
}
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