[TASK] Update file list module access in backend groups and users 82/50982/5
authorNicole Cordes <typo3@cordes.co>
Thu, 15 Dec 2016 23:51:13 +0000 (00:51 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 15 Feb 2017 07:36:45 +0000 (08:36 +0100)
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>
typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php [new file with mode: 0644]
typo3/sysext/install/ext_localconf.php

diff --git a/typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php b/typo3/sysext/install/Classes/Updates/FileListInAccessModuleListUpdate.php
new file mode 100644 (file)
index 0000000..2ba61fc
--- /dev/null
@@ -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;
+    }
+}
index 9dcfacc..e005ce6 100644 (file)
@@ -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;