Skip to content
Snippets Groups Projects

[TASk] Implementation

Merged Torsten Oppermann requested to merge feature_upgrade_wizard into master
2 files
+ 99
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 95
0
<?php
namespace SGalinski\SgSeo\Updates;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Install\Updates\AbstractUpdate;
/**
* Migrate dd_googlesitemap db entries for sg_seo
*/
class MigrateGoogleSitemapData extends AbstractUpdate {
/**
* @var string
*/
protected $title = 'Migrates all db entries of dd_google_sitemap to the according tables of sg_seo';
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected $objectManager;
/**
* Checks whether updates are required.
*
* @param string &$description The description for the update
* @return bool Whether an update is required (TRUE) or not (FALSE)
*/
public function checkForUpdate(&$description): bool {
$description = 'Set the site_root_id for all the queue entries and templates if not set or pid = 0';
$oldRowsFound = FALSE;
$databaseConnection = $GLOBALS['TYPO3_DB'];
$where = 'tx_sgseo_lastmod = "" AND tx_ddgooglesitemap_lastmod != ""';
$result = $databaseConnection->exec_SELECTquery('*', 'pages', $where);
if ($result->num_rows > 0) {
$oldRowsFound = TRUE;
}
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): bool {
$databaseConnection = $GLOBALS['TYPO3_DB'];
$where = 'site_root_id = 0';
$result = $databaseConnection->exec_SELECTquery(
'uid, tx_ddgooglesitemap_lastmod, tx_ddgooglesitemap_priority, tx_ddgooglesitemap_change_frequency',
'pages', $where
)->fetch_all();
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
/** @var array $result */
foreach ($result as $row) {
$where = 'uid = ' . $row[0];
$databaseConnection->exec_UPDATEquery(
'pages', $where,
['tx_sgseo_lastmod' => $row[1], 'tx_sgseo_priority' => $row[2], 'tx_sgseo_change_frequency' => $row[3]]
);
$dbQueries[] = $databaseConnection->debug_lastBuiltQuery;
}
$this->markWizardAsDone();
return TRUE;
}
}
Loading