diff --git a/Classes/Update/AddSites/AbstractSiteUpgrade.php b/Classes/Update/AddSites/AbstractSiteUpgrade.php new file mode 100644 index 00000000..07930c12 --- /dev/null +++ b/Classes/Update/AddSites/AbstractSiteUpgrade.php @@ -0,0 +1,38 @@ + 'site 1', + * 124 => 'site 2', + * ] + * + * @var array + */ + protected array $mapping = []; + protected SiteService $siteService; + + public function __construct() + { + $this->siteService = GeneralUtility::makeInstance(SiteService::class); + } + + protected function getSiteIdentifierFromPage(int $pageIdentifier): string + { + if (array_key_exists($pageIdentifier, $this->mapping)) { + return $this->mapping[$pageIdentifier]; + } + $site = $this->siteService->getSiteFromPageIdentifier($pageIdentifier); + $siteIdentifier = $site->getIdentifier(); + $this->mapping[$pageIdentifier] = $siteIdentifier; + return $siteIdentifier; + } +} diff --git a/Classes/Update/AddSites/AddSitesForDownloads.php b/Classes/Update/AddSites/AddSitesForDownloads.php new file mode 100644 index 00000000..475402db --- /dev/null +++ b/Classes/Update/AddSites/AddSitesForDownloads.php @@ -0,0 +1,25 @@ +executeQuery('select * from ' . Download::TABLE_NAME . ' where deleted=0') + ->fetchAllAssociative(); + foreach ($records as $record) { + $siteIdentifier = $this->getSiteIdentifierFromPage($record['page']); + $connection->executeQuery( + 'update ' . Download::TABLE_NAME . ' set site = "' . $siteIdentifier . '" where uid=' . $record['uid'] + ); + } + } +} diff --git a/Classes/Update/AddSites/AddSitesForLinkclick.php b/Classes/Update/AddSites/AddSitesForLinkclick.php new file mode 100644 index 00000000..240f61d2 --- /dev/null +++ b/Classes/Update/AddSites/AddSitesForLinkclick.php @@ -0,0 +1,25 @@ +executeQuery('select * from ' . Linkclick::TABLE_NAME . ' where deleted=0') + ->fetchAllAssociative(); + foreach ($records as $record) { + $siteIdentifier = $this->getSiteIdentifierFromPage($record['page']); + $connection->executeQuery( + 'update ' . Linkclick::TABLE_NAME . ' set site = "' . $siteIdentifier . '" where uid=' . $record['uid'] + ); + } + } +} diff --git a/Classes/Update/AddSites/AddSitesForPagevisits.php b/Classes/Update/AddSites/AddSitesForPagevisits.php new file mode 100644 index 00000000..9844d220 --- /dev/null +++ b/Classes/Update/AddSites/AddSitesForPagevisits.php @@ -0,0 +1,25 @@ +executeQuery('select * from ' . Pagevisit::TABLE_NAME . ' where deleted=0') + ->fetchAllAssociative(); + foreach ($records as $record) { + $siteIdentifier = $this->getSiteIdentifierFromPage($record['page']); + $connection->executeQuery( + 'update ' . Pagevisit::TABLE_NAME . ' set site = "' . $siteIdentifier . '" where uid=' . $record['uid'] + ); + } + } +} diff --git a/Classes/Update/AddSitesUpgradeWizard.php b/Classes/Update/AddSitesUpgradeWizard.php new file mode 100644 index 00000000..a909b0ed --- /dev/null +++ b/Classes/Update/AddSitesUpgradeWizard.php @@ -0,0 +1,59 @@ +run(); +// GeneralUtility::makeInstance(AddSitesForDownloads::class)->run(); + GeneralUtility::makeInstance(AddSitesForLinkclick::class)->run(); + } catch (Throwable $exception) { + return false; + } + return true; + } + + public function updateNecessary(): bool + { + return DatabaseUtility::isFieldExistingInTable('site', Pagevisit::TABLE_NAME) + && DatabaseUtility::isAnyFieldFilledInTable('site', Pagevisit::TABLE_NAME) === false; + } + + public function getPrerequisites(): array + { + return [ + DatabaseUpdatedPrerequisite::class, + ]; + } +} diff --git a/Classes/Utility/DatabaseUtility.php b/Classes/Utility/DatabaseUtility.php index 6021e54d..e7c92587 100644 --- a/Classes/Utility/DatabaseUtility.php +++ b/Classes/Utility/DatabaseUtility.php @@ -97,4 +97,22 @@ public static function isFieldInTableFilled(string $fieldName, string $tableName ->executeQuery() ->fetchOne() !== ''; } + + /** + * @param string $fieldName + * @param string $tableName + * @return bool + * @throws ExceptionDbal + */ + public static function isAnyFieldFilledInTable(string $fieldName, string $tableName): bool + { + $queryBuilder = self::getQueryBuilderForTable($tableName); + return $queryBuilder + ->select($fieldName) + ->from($tableName) + ->where($fieldName . ' != \'\'') + ->setMaxResults(1) + ->executeQuery() + ->fetchOne() !== false; + } } diff --git a/Configuration/TCA/tx_lux_domain_model_download.php b/Configuration/TCA/tx_lux_domain_model_download.php index 538219e0..6e5dfcdb 100644 --- a/Configuration/TCA/tx_lux_domain_model_download.php +++ b/Configuration/TCA/tx_lux_domain_model_download.php @@ -22,7 +22,7 @@ 'hideTable' => true, ], 'types' => [ - '1' => ['showitem' => 'crdate,href,page,file,properties,domain,visitor'], + '1' => ['showitem' => 'crdate,href,page,file,properties,domain,site,visitor'], ], 'columns' => [ 'sys_language_uid' => [ @@ -104,6 +104,15 @@ 'readOnly' => true, ], ], + 'site' => [ + 'exclude' => true, + 'label' => 'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:' . Download::TABLE_NAME . '.site', + 'config' => [ + 'type' => 'input', + 'size' => 30, + 'readOnly' => true, + ], + ], 'visitor' => [ 'exclude' => true, 'label' => 'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:' . Download::TABLE_NAME . '.visitor', diff --git a/Configuration/TCA/tx_lux_domain_model_linkclick.php b/Configuration/TCA/tx_lux_domain_model_linkclick.php index e6d9b627..442ab489 100644 --- a/Configuration/TCA/tx_lux_domain_model_linkclick.php +++ b/Configuration/TCA/tx_lux_domain_model_linkclick.php @@ -21,7 +21,7 @@ 'hideTable' => true, ], 'types' => [ - '1' => ['showitem' => 'crdate,linklistener,page,visitor'], + '1' => ['showitem' => 'crdate,linklistener,page,site,visitor'], ], 'columns' => [ 'sys_language_uid' => [ @@ -86,6 +86,15 @@ 'readOnly' => true, ], ], + 'site' => [ + 'exclude' => true, + 'label' => 'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:' . Linkclick::TABLE_NAME . '.site', + 'config' => [ + 'type' => 'input', + 'size' => 30, + 'readOnly' => true, + ], + ], 'visitor' => [ 'exclude' => true, 'label' => 'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:' . Linkclick::TABLE_NAME . '.visitor', diff --git a/Configuration/TCA/tx_lux_domain_model_pagevisit.php b/Configuration/TCA/tx_lux_domain_model_pagevisit.php index 1f6ad376..84007a45 100644 --- a/Configuration/TCA/tx_lux_domain_model_pagevisit.php +++ b/Configuration/TCA/tx_lux_domain_model_pagevisit.php @@ -25,7 +25,7 @@ 'hideTable' => true, ], 'types' => [ - '1' => ['showitem' => 'page,language,crdate,referrer,domain,visitor'], + '1' => ['showitem' => 'page,language,crdate,referrer,domain,site,visitor'], ], 'columns' => [ 'sys_language_uid' => [ @@ -134,6 +134,15 @@ 'readOnly' => true, ], ], + 'site' => [ + 'exclude' => true, + 'label' => 'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:' . Pagevisit::TABLE_NAME . '.site', + 'config' => [ + 'type' => 'input', + 'size' => 30, + 'readOnly' => true, + ], + ], 'visitor' => [ 'exclude' => true, 'label' => 'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:' . Pagevisit::TABLE_NAME . '.visitor', diff --git a/Resources/Private/Language/de.locallang_db.xlf b/Resources/Private/Language/de.locallang_db.xlf index 5350e4c8..3a8ffae1 100644 --- a/Resources/Private/Language/de.locallang_db.xlf +++ b/Resources/Private/Language/de.locallang_db.xlf @@ -165,6 +165,10 @@ Current domain Aktuelle Domain + + Site + Site + Lead Lead @@ -244,6 +248,14 @@ File Datei + + Domain + Domain + + + Site + Site + Lead Lead @@ -452,6 +464,10 @@ Page Seite + + Site + Site + Lead Lead diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index ff305d1c..3ca3639b 100644 --- a/Resources/Private/Language/locallang_db.xlf +++ b/Resources/Private/Language/locallang_db.xlf @@ -125,6 +125,8 @@ Current domain + + Site Lead @@ -185,6 +187,12 @@ File + + Domain + + + Site + Lead @@ -344,6 +352,9 @@ Page + + Site + Lead diff --git a/ext_localconf.php b/ext_localconf.php index 92ae4433..cc4a644a 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -83,5 +83,14 @@ function () { * CacheHash: Add LUX paramters to excluded variables */ \In2code\Lux\Utility\CacheHashUtility::addLuxArgumentsToExcludedVariables(); + + /** + * Upgrade Wizards + * Todo: Can be removed when TYPO3 11 support is dropped + */ + if (\In2code\Lux\Utility\ConfigurationUtility::isTypo3Version11()) { + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['addSitesUpgradeWizard'] + = \In2code\Lux\Update\AddSitesUpgradeWizard::class; + } } ); diff --git a/ext_tables.sql b/ext_tables.sql index 7c017c6b..ce0991c9 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -126,6 +126,7 @@ CREATE TABLE tx_lux_domain_model_pagevisit ( language int(11) DEFAULT '0' NOT NULL, referrer text DEFAULT '' NOT NULL, domain varchar(255) DEFAULT '' NOT NULL, + site varchar(255) DEFAULT '' NOT NULL, tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, @@ -143,6 +144,7 @@ CREATE TABLE tx_lux_domain_model_pagevisit ( KEY parent (pid), KEY visitor (visitor), KEY page (page), + KEY site (site(50)), KEY language_lux (language), KEY referrer (referrer(50)), KEY domain (domain(50)), @@ -194,6 +196,7 @@ CREATE TABLE tx_lux_domain_model_download ( href varchar(255) DEFAULT '' NOT NULL, page int(11) DEFAULT '0' NOT NULL, domain varchar(255) DEFAULT '' NOT NULL, + site varchar(255) DEFAULT '' NOT NULL, tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, @@ -211,6 +214,7 @@ CREATE TABLE tx_lux_domain_model_download ( KEY href (href(50)), KEY page (page), KEY domain (domain(50)), + KEY site (site(50)), KEY crdate (crdate), KEY language (l10n_parent,sys_language_uid) ); @@ -252,6 +256,7 @@ CREATE TABLE tx_lux_domain_model_search ( visitor int(11) unsigned DEFAULT '0' NOT NULL, searchterm varchar(255) DEFAULT '' NOT NULL, + pagevisit int(11) DEFAULT '0' NOT NULL, tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, @@ -266,6 +271,7 @@ CREATE TABLE tx_lux_domain_model_search ( KEY parent (pid), KEY visitor (visitor), KEY searchterm (searchterm(20)), + KEY pagevisit (pagevisit), KEY crdate (crdate), KEY language (l10n_parent,sys_language_uid) ); @@ -332,6 +338,7 @@ CREATE TABLE tx_lux_domain_model_linkclick ( page int(11) DEFAULT '0' NOT NULL, linklistener int(11) DEFAULT '0' NOT NULL, + site varchar(255) DEFAULT '' NOT NULL, tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, @@ -347,6 +354,7 @@ CREATE TABLE tx_lux_domain_model_linkclick ( KEY visitor (visitor), KEY page (page), KEY linklistener (linklistener), + KEY site (site(50)), KEY crdate (crdate), KEY language (l10n_parent,sys_language_uid) );