TYPO3 CMS  TYPO3_7-6
FilesReplacePermissionUpdate.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 = 'Set the "Files:replace" permission for all BE user/groups with "Files:write" set';
26 
33  public function checkForUpdate(&$description)
34  {
35  if ($this->isWizardDone()) {
36  return false;
37  }
38  $description = 'A new file permission was introduced regarding replacing files.' .
39  ' This update sets "Files:replace" for all BE users/groups with the permission "Files:write".';
40  $updateNeeded = false;
41  $db = $this->getDatabaseConnection();
42 
43  // Fetch user records where the writeFile is set and replaceFile is not
44  $notMigratedRowsCount = $db->exec_SELECTcountRows(
45  'uid',
46  'be_users',
47  $this->getWhereClause()
48  );
49  if ($notMigratedRowsCount > 0) {
50  $updateNeeded = true;
51  }
52 
53  if (!$updateNeeded) {
54  // Fetch group records where the writeFile is set and replaceFile is not
55  $notMigratedRowsCount = $db->exec_SELECTcountRows(
56  'uid',
57  'be_groups',
58  $this->getWhereClause()
59  );
60  if ($notMigratedRowsCount > 0) {
61  $updateNeeded = true;
62  }
63  }
64  return $updateNeeded;
65  }
66 
74  public function performUpdate(array &$dbQueries, &$customMessages)
75  {
76  $db = $this->getDatabaseConnection();
77 
78  // Iterate over users and groups table to perform permission updates
79  $tablesToProcess = ['be_groups', 'be_users'];
80  foreach ($tablesToProcess as $table) {
81  $records = $this->getRecordsFromTable($table);
82  foreach ($records as $singleRecord) {
83  $updateArray = [
84  'file_permissions' => $singleRecord['file_permissions'] . ',replaceFile'
85  ];
86  $db->exec_UPDATEquery($table, 'uid=' . (int)$singleRecord['uid'], $updateArray);
87  // Get last executed query
88  $dbQueries[] = str_replace(chr(10), ' ', $db->debug_lastBuiltQuery);
89  // Check for errors
90  if ($db->sql_error()) {
91  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($db->sql_error());
92  return false;
93  }
94  }
95  }
96  $this->markWizardAsDone();
97  return true;
98  }
99 
106  protected function getRecordsFromTable($table)
107  {
108  $fields = implode(',', ['uid', 'file_permissions']);
109  $records = $this->getDatabaseConnection()->exec_SELECTgetRows($fields, $table, $this->getWhereClause());
110  return $records;
111  }
112 
118  protected function getWhereClause()
119  {
120  return 'file_permissions LIKE \'%writeFile%\' AND file_permissions NOT LIKE \'%replaceFile%\'';
121  }
122 }