[TASK] Update file list module access in backend groups and users 83/50983/4
authorNicole Cordes <typo3@cordes.co>
Thu, 15 Dec 2016 23:53:09 +0000 (00:53 +0100)
committerNicole Cordes <typo3@cordes.co>
Wed, 15 Feb 2017 17:41:20 +0000 (18:41 +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/50983
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
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..09522a1
--- /dev/null
@@ -0,0 +1,104 @@
+<?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!
+ */
+
+/**
+ * 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.';
+
+        $db = $this->getDatabaseConnection();
+        foreach ($this->tableFieldArray as $table => $field) {
+            $count = $db->exec_SELECTcountRows(
+                '*',
+                $table,
+                $db->listQuery($field, 'file_list', $table)
+            );
+            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)
+    {
+        $db = $this->getDatabaseConnection();
+        foreach ($this->tableFieldArray as $table => $field) {
+            $rows = $db->exec_SELECTgetRows(
+                'uid,' . $field,
+                $table,
+                $db->listQuery($field, 'file_list', $table)
+            );
+            if (empty($rows)) {
+                continue;
+            }
+            foreach ($rows as $row) {
+                $moduleList = explode(',', $row[$field]);
+                $moduleList = array_combine($moduleList, $moduleList);
+                $moduleList['file_list'] = 'file_FilelistList';
+                unset($moduleList['file']);
+                $db->exec_UPDATEquery(
+                    $table,
+                    'uid=' . (int)$row['uid'],
+                    [
+                        $field => implode(',', $moduleList),
+                    ]
+                );
+                $databaseQueries[] = $db->debug_lastBuiltQuery;
+            }
+        }
+        $this->markWizardAsDone();
+
+        return true;
+    }
+}
index 95fc849..3f3d2b6 100644 (file)
@@ -10,6 +10,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;