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

[TASK] Staring work on new upgrade wizard

parent c57bfddb
No related branches found
No related tags found
1 merge request!3New version 4 1
......@@ -27,16 +27,17 @@ namespace SGalinski\SgMail\Updates;
***************************************************************/
use SGalinski\SgMail\Service\BackendService;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Install\Updates\AbstractUpdate;
/**
* Migrate template db entries to the correct root pages
*/
class MigrateData extends AbstractUpdate {
class UpdatePidToSiteRoot extends AbstractUpdate {
/**
* @var string
*/
protected $title = 'Find all templates & queue entries without site root and assign the correct site root id';
protected $title = 'Find all templates & queue entries with site root and assign the correct site root id as pid. Also check if the pids are actually site roots and update them accordingly';
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
......@@ -57,70 +58,61 @@ class MigrateData extends AbstractUpdate {
* @return bool Whether an update is required (TRUE) or not (FALSE)
*/
public function checkForUpdate(&$description) {
$description = 'Set the site_root_id for all the queue entries and templates if not set or pid = 0';
$oldRowsFound = FALSE;
$description = 'Move site root ids to pid & update pids to their correspondent site root ids';
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$where = 'site_root_id = 0';
// 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 === 'site_root_id') {
$hasColumn[$table] = TRUE;
}
}
}
// are there site root columns differing from pids?
$where = 'site_root_id <> pid';
foreach ($this->tables as $table) {
if (!$hasColumn[$table]) {
continue;
}
$result = $databaseConnection->exec_SELECTquery('*', $table, $where);
if ($result->num_rows > 0) {
$oldRowsFound = TRUE;
return TRUE;
break;
}
}
return !(!$oldRowsFound || $this->isWizardDone());
}
/**
* Performs the accordant updates.
*
* @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) {
$databaseConnection = $GLOBALS['TYPO3_DB'];
// are the pids not belonging to site root pages ?
foreach ($this->tables as $table) {
$where = 'site_root_id = 0';
$result = $databaseConnection->exec_SELECTquery('uid, pid', $table, $where)->fetch_all();
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
/** @var array $result */
$result = $databaseConnection->exec_SELECTquery('pid', $table, '')->fetch_all();
foreach ($result as $row) {
$siteRootId = BackendService::getSiteRoot($row[1]);
if ($siteRootId === NULL) {
$this->retrieveFirstSiteRoot();
$siteRootId = BackendService::getSiteRoot($row[0]);
if ($siteRootId !== $row[0]) {
return TRUE;
}
$where = 'uid = ' . $row[0];
$databaseConnection->exec_UPDATEquery($table, $where, ['site_root_id' => $siteRootId]);
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
}
}
$this->markWizardAsDone();
return TRUE;
$this->isWizardDone();
return FALSE;
}
/**
* Get the first site root that is not pid = 0
* Performs the according updates.
*
* @return int
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
*/
private function retrieveFirstSiteRoot() {
public function performUpdate(array &$dbQueries, &$customMessages) {
$databaseConnection = $GLOBALS['TYPO3_DB'];
$where = "is_siteroot = 1 AND uid <> '0'";
$pagesResult = $databaseConnection->exec_SELECTgetSingleRow('uid', 'pages', $where, '', '', '1');
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
if (empty($pagesResult)) {
return 0;
}
return $pagesResult[0][0];
return TRUE;
}
}
......@@ -36,7 +36,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] =
\SGalinski\SgMail\Command\SendMailCommandController::class;
// add upgrade wizard for moving all db entries to their respected siteroot
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['tx_sgmail_migrate_data'] = \SGalinski\SgMail\Updates\MigrateData::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['tx_sgmail_update_pid_to_site_root'] = \SGalinski\SgMail\Updates\UpdatePidToSiteRoot::class;
if (TYPO3_MODE === 'BE') {
......
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