From 9629cf1959582827168e4a4557a8fa7e1e3a6024 Mon Sep 17 00:00:00 2001 From: Nicole Cordes <typo3@cordes.co> Date: Fri, 16 Dec 2016 00:51:13 +0100 Subject: [PATCH] [TASK] Update file list module access in backend groups and users As the file list module was renamed, backend groups and users access lists need adjustments. This patch updates the module name and removes the non-existing "file" module from those lists. Resolves: #78979 Releases: master, 7.6 Change-Id: I06bd10523399f38e2a0ec6fdf5740cbfea6dd509 Reviewed-on: https://review.typo3.org/50982 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Nicole Cordes <typo3@cordes.co> Tested-by: Nicole Cordes <typo3@cordes.co> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> --- .../FileListInAccessModuleListUpdate.php | 115 ++++++++++++++++++ typo3/sysext/install/ext_localconf.php | 1 + 2 files changed, 116 insertions(+) create mode 100644 typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php diff --git a/typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php b/typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php new file mode 100644 index 000000000000..2ba61fce9905 --- /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 9dcfacccbdcd..e005ce688122 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; -- GitLab