TYPO3 CMS  TYPO3_7-6
WorkspacesNotificationSettingsUpdate.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 
18 
23 {
27  protected $title = 'Migrate the workspaces notification settings to the enhanced schema';
28 
35  public function checkForUpdate(&$description)
36  {
37  if (!ExtensionManagementUtility::isLoaded('workspaces')) {
38  return false;
39  }
40 
41  if ($this->isWizardDone()) {
42  return false;
43  }
44 
45  $workspacesCount = $this->getDatabaseConnection()->exec_SELECTcountRows(
46  'uid',
47  'sys_workspace',
48  'deleted=0'
49  );
50 
51  $stagesCount = $this->getDatabaseConnection()->exec_SELECTcountRows(
52  'uid',
53  'sys_workspace_stage',
54  'deleted=0'
55  );
56 
57  if ($workspacesCount + $stagesCount > 0) {
58  $description = 'The workspaces notification settings have been extended'
59  . ' and need to be migrated to the new definitions. This update wizard'
60  . ' upgrades the accordant settings in the availble workspaces and stages.';
61  return true;
62  } else {
63  $this->markWizardAsDone();
64  }
65 
66  return false;
67  }
68 
76  public function performUpdate(array &$databaseQueries, &$customMessages)
77  {
78  $databaseConnection = $this->getDatabaseConnection();
79 
80  $workspaceRecords = $databaseConnection->exec_SELECTgetRows('*', 'sys_workspace', 'deleted=0');
81  foreach ($workspaceRecords as $workspaceRecord) {
82  $update = $this->prepareWorkspaceUpdate($workspaceRecord);
83  if ($update !== null) {
84  $databaseConnection->exec_UPDATEquery('sys_workspace', 'uid=' . (int)$workspaceRecord['uid'], $update);
85  $databaseQueries[] = $databaseConnection->debug_lastBuiltQuery;
86  }
87  }
88 
89  $stageRecords = $databaseConnection->exec_SELECTgetRows('*', 'sys_workspace_stage', 'deleted=0');
90  foreach ($stageRecords as $stageRecord) {
91  $update = $this->prepareStageUpdate($stageRecord);
92  if ($update !== null) {
93  $databaseConnection->exec_UPDATEquery('sys_workspace_stage', 'uid=' . (int)$stageRecord['uid'], $update);
94  $databaseQueries[] = $databaseConnection->debug_lastBuiltQuery;
95  }
96  }
97 
98  $this->markWizardAsDone();
99  return true;
100  }
101 
108  protected function prepareWorkspaceUpdate(array $workspaceRecord)
109  {
110  if (empty($workspaceRecord['uid'])) {
111  return null;
112  }
113 
114  $update = [];
115  $update = $this->mapSettings($workspaceRecord, $update, 'edit', 'edit');
116  $update = $this->mapSettings($workspaceRecord, $update, 'publish', 'publish');
117  $update = $this->mapSettings($workspaceRecord, $update, 'publish', 'execute');
118  return $update;
119  }
120 
127  protected function prepareStageUpdate(array $stageRecord)
128  {
129  if (empty($stageRecord['uid'])) {
130  return null;
131  }
132 
133  $update = [];
134  $update = $this->mapSettings($stageRecord, $update);
135  return $update;
136  }
137 
147  protected function mapSettings(array $record, array $update, $from = '', $to = '')
148  {
149  $fromPrefix = ($from ? $from . '_' : '');
150  $toPrefix = ($to ? $to . '_' : '');
151 
152  $settings = 0;
153  // Previous setting: "Allow notification settings during stage change"
154  if ($record[$fromPrefix . 'allow_notificaton_settings']) {
155  $settings += 1;
156  }
157  // Previous setting: "All are selected per default (can be changed)"
158  if ((int)$record[$fromPrefix . 'notification_mode'] === 0) {
159  $settings += 2;
160  }
161 
162  // Custom stages: preselect responsible persons (8)
163  if (isset($record['responsible_persons'])) {
164  $preselection = 8;
165  // Workspace "edit" stage: preselect members (2)
166  } elseif ($to === 'edit') {
167  $preselection = 2;
168  // Workspace "publish" stage: preselect owners (1)
169  } elseif ($to === 'publish') {
170  $preselection = 1;
171  // Workspace "execute" stage: preselect owners (1) and members (2) as default
172  } else {
173  $preselection = 1 + 2;
174  }
175 
176  $update[$toPrefix . 'allow_notificaton_settings'] = $settings;
177  $update[$toPrefix . 'notification_preselection'] = $preselection;
178 
179  return $update;
180  }
181 }