TYPO3 CMS  TYPO3_7-6
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 
21 {
25  protected $title = 'Update module access to file list module';
26 
30  protected $tableFieldArray = [
31  'be_groups' => 'groupMods',
32  'be_users' => 'userMods',
33  ];
34 
42  public function checkForUpdate(&$description)
43  {
44  if ($this->isWizardDone()) {
45  return false;
46  }
47 
48  $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.';
49 
50  $db = $this->getDatabaseConnection();
51  foreach ($this->tableFieldArray as $table => $field) {
52  $count = $db->exec_SELECTcountRows(
53  '*',
54  $table,
55  $db->listQuery($field, 'file_list', $table)
56  );
57  if ($count > 0) {
58  return true;
59  }
60  }
61 
62  return false;
63  }
64 
73  public function performUpdate(array &$databaseQueries, &$customMessage)
74  {
75  $db = $this->getDatabaseConnection();
76  foreach ($this->tableFieldArray as $table => $field) {
77  $rows = $db->exec_SELECTgetRows(
78  'uid,' . $field,
79  $table,
80  $db->listQuery($field, 'file_list', $table)
81  );
82  if (empty($rows)) {
83  continue;
84  }
85  foreach ($rows as $row) {
86  $moduleList = explode(',', $row[$field]);
87  $moduleList = array_combine($moduleList, $moduleList);
88  $moduleList['file_list'] = 'file_FilelistList';
89  unset($moduleList['file']);
90  $db->exec_UPDATEquery(
91  $table,
92  'uid=' . (int)$row['uid'],
93  [
94  $field => implode(',', $moduleList),
95  ]
96  );
97  $databaseQueries[] = $db->debug_lastBuiltQuery;
98  }
99  }
100  $this->markWizardAsDone();
101 
102  return true;
103  }
104 }