TYPO3 CMS  TYPO3_8-7
FileListInAccessModuleListUpdate.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
28  protected $title = 'Update module access to file list module';
29 
33  protected $tableFieldArray = [
34  'be_groups' => 'groupMods',
35  'be_users' => 'userMods',
36  ];
37 
45  public function checkForUpdate(&$description)
46  {
47  if ($this->isWizardDone()) {
48  return false;
49  }
50 
51  $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.';
52 
53  foreach ($this->tableFieldArray as $table => $field) {
54  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
55  ->getQueryBuilderForTable($table);
56  $queryBuilder->getRestrictions()->removeAll();
57  $count = $queryBuilder->count('*')
58  ->from($table)
59  ->where(
60  $queryBuilder->expr()->inSet($field, $queryBuilder->expr()->literal('file_list'))
61  )
62  ->execute()
63  ->fetchColumn(0);
64  if ($count > 0) {
65  return true;
66  }
67  }
68 
69  return false;
70  }
71 
80  public function performUpdate(array &$databaseQueries, &$customMessage)
81  {
82  foreach ($this->tableFieldArray as $table => $field) {
83  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
84  ->getQueryBuilderForTable($table);
85  $queryBuilder->getRestrictions()->removeAll();
86  $statement = $queryBuilder->select('uid', $field)
87  ->from($table)
88  ->where(
89  $queryBuilder->expr()->inSet($field, $queryBuilder->expr()->literal('file_list'))
90  )
91  ->execute();
92  while ($row = $statement->fetch()) {
93  $moduleList = explode(',', $row[$field]);
94  $moduleList = array_combine($moduleList, $moduleList);
95  $moduleList['file_list'] = 'file_FilelistList';
96  unset($moduleList['file']);
97  $updateQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
98  ->getQueryBuilderForTable($table);
99  $updateQueryBuilder->update($table)
100  ->where(
101  $updateQueryBuilder->expr()->eq(
102  'uid',
103  $updateQueryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT)
104  )
105  )
106  ->set($field, implode(',', $moduleList));
107  $databaseQueries[] = $updateQueryBuilder->getSQL();
108  $updateQueryBuilder->execute();
109  }
110  }
111  $this->markWizardAsDone();
112 
113  return true;
114  }
115 }
static makeInstance($className,... $constructorArguments)