diff --git a/typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php b/typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php new file mode 100644 index 0000000000000000000000000000000000000000..2ba61fce9905ba4bf54ef7e8288ca1e5ff9f2a4e --- /dev/null +++ b/typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php @@ -0,0 +1,115 @@ +<?php +namespace TYPO3\CMS\Install\Updates; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +/** + * Update module access to the file list module + */ +class FileListInAccessModuleListUpdate extends AbstractUpdate +{ + /** + * @var string + */ + protected $title = 'Update module access to file list module'; + + /** + * @var array + */ + protected $tableFieldArray = [ + 'be_groups' => 'groupMods', + 'be_users' => 'userMods', + ]; + + /** + * Checks if an update is needed + * + * @param string &$description The description for the update + * + * @return bool Whether an update is needed (TRUE) or not (FALSE) + */ + public function checkForUpdate(&$description) + { + if ($this->isWizardDone()) { + return false; + } + + $description = 'The module name of the file list module has been changed. Update the access list of all backend groups and users where this module is available.'; + + foreach ($this->tableFieldArray as $table => $field) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable($table); + $queryBuilder->getRestrictions()->removeAll(); + $count = $queryBuilder->count('*') + ->from($table) + ->where( + $queryBuilder->expr()->inSet($field, $queryBuilder->expr()->literal('file_list')) + ) + ->execute() + ->fetchColumn(0); + if ($count > 0) { + return true; + } + } + + return false; + } + + /** + * Performs the database update for module access to file_list + * + * @param array &$databaseQueries Queries done in this update + * @param string &$customMessage Custom messages + * + * @return bool + */ + public function performUpdate(array &$databaseQueries, &$customMessage) + { + foreach ($this->tableFieldArray as $table => $field) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable($table); + $queryBuilder->getRestrictions()->removeAll(); + $statement = $queryBuilder->select('uid', $field) + ->from($table) + ->where( + $queryBuilder->expr()->inSet($field, $queryBuilder->expr()->literal('file_list')) + ) + ->execute(); + while ($row = $statement->fetch()) { + $moduleList = explode(',', $row[$field]); + $moduleList = array_combine($moduleList, $moduleList); + $moduleList['file_list'] = 'file_FilelistList'; + unset($moduleList['file']); + $updateQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable($table); + $updateQueryBuilder->update($table) + ->where( + $updateQueryBuilder->expr()->eq( + 'uid', + $updateQueryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT) + ) + ) + ->set($field, implode(',', $moduleList)); + $databaseQueries[] = $updateQueryBuilder->getSQL(); + $updateQueryBuilder->execute(); + } + } + $this->markWizardAsDone(); + + return true; + } +} diff --git a/typo3/sysext/install/ext_localconf.php b/typo3/sysext/install/ext_localconf.php index 9dcfacccbdcd45aaeddfa6e096c27e406d20cace..e005ce6881227560f6cac1753b6a37dc5ea4f969 100644 --- a/typo3/sysext/install/ext_localconf.php +++ b/typo3/sysext/install/ext_localconf.php @@ -9,6 +9,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['backendShort $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['processedFilesChecksum'] = \TYPO3\CMS\Install\Updates\ProcessedFileChecksumUpdate::class; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['filesReplacePermission'] = \TYPO3\CMS\Install\Updates\FilesReplacePermissionUpdate::class; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['tableCType'] = \TYPO3\CMS\Install\Updates\TableFlexFormToTtContentFieldsUpdate::class; +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\TYPO3\CMS\Install\Updates\FileListInAccessModuleListUpdate::class] = \TYPO3\CMS\Install\Updates\FileListInAccessModuleListUpdate::class; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\TYPO3\CMS\Install\Updates\FileListIsStartModuleUpdate::class] = \TYPO3\CMS\Install\Updates\FileListIsStartModuleUpdate::class; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['textmediaCType'] = \TYPO3\CMS\Install\Updates\ContentTypesToTextMediaUpdate::class; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\TYPO3\CMS\Install\Updates\WorkspacesNotificationSettingsUpdate::class] = \TYPO3\CMS\Install\Updates\WorkspacesNotificationSettingsUpdate::class;