2 namespace TYPO3\CMS\Install\Updates
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Database\ConnectionPool
;
18 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
;
19 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
20 use TYPO3\CMS\Core\Utility\GeneralUtility
;
23 * Migrate the workspaces notification settings to the enhanced schema.
25 class WorkspacesNotificationSettingsUpdate
extends AbstractUpdate
30 protected $title = 'Migrate the workspaces notification settings to the enhanced schema';
33 * Checks if an update is needed
35 * @param string &$description The description for the update
36 * @return bool Whether an update is needed (TRUE) or not (FALSE)
38 public function checkForUpdate(&$description)
40 if (!ExtensionManagementUtility
::isLoaded('workspaces') ||
$this->isWizardDone()) {
44 $workspacesCount = GeneralUtility
::makeInstance(ConnectionPool
::class)
45 ->getConnectionForTable('sys_workspace')
51 $stagesCount = GeneralUtility
::makeInstance(ConnectionPool
::class)
52 ->getConnectionForTable('sys_workspace_stage')
55 'sys_workspace_stage',
58 if ($workspacesCount +
$stagesCount > 0) {
59 $description = 'The workspaces notification settings have been extended'
60 . ' and need to be migrated to the new definitions. This update wizard'
61 . ' upgrades the accordant settings in the available workspaces and stages.';
64 $this->markWizardAsDone();
70 * Perform the database updates for workspace records
72 * @param array &$databaseQueries Queries done in this update
73 * @param string &$customMessage Custom message
76 public function performUpdate(array &$databaseQueries, &$customMessage)
78 $workspaceConnection = GeneralUtility
::makeInstance(ConnectionPool
::class)->getConnectionForTable('sys_workspace');
79 $queryBuilder = $workspaceConnection->createQueryBuilder();
80 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility
::makeInstance(DeletedRestriction
::class));
81 $statement = $queryBuilder->select('*')->from('sys_workspace')->execute();
82 while ($workspaceRecord = $statement->fetch()) {
83 $update = $this->prepareWorkspaceUpdate($workspaceRecord);
84 if ($update !== null
) {
85 $queryBuilder = $workspaceConnection->createQueryBuilder();
86 $queryBuilder->update('sys_workspace')
88 $queryBuilder->expr()->eq(
90 $queryBuilder->createNamedParameter($workspaceRecord['uid'], \PDO
::PARAM_INT
)
93 foreach ($update as $field => $value) {
94 $queryBuilder->set($field, $value);
96 $databaseQueries[] = $queryBuilder->getSQL();
97 $queryBuilder->execute();
101 $stageConnection = GeneralUtility
::makeInstance(ConnectionPool
::class)->getConnectionForTable('sys_workspace_stage');
102 $queryBuilder = $stageConnection->createQueryBuilder();
103 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility
::makeInstance(DeletedRestriction
::class));
104 $statement = $queryBuilder->select('*')->from('sys_workspace_stage')->execute();
105 while ($stageRecord = $statement->fetch()) {
106 $update = $this->prepareStageUpdate($stageRecord);
107 if ($update !== null
) {
108 $queryBuilder = $workspaceConnection->createQueryBuilder();
109 $queryBuilder->update('sys_workspace_stage')
111 $queryBuilder->expr()->eq(
113 $queryBuilder->createNamedParameter($stageRecord['uid'], \PDO
::PARAM_INT
)
116 foreach ($update as $field => $value) {
117 $queryBuilder->set($field, $value);
119 $databaseQueries[] = $queryBuilder->getSQL();
120 $queryBuilder->execute();
124 $this->markWizardAsDone();
129 * Prepares SQL updates for workspace records.
131 * @param array $workspaceRecord
134 protected function prepareWorkspaceUpdate(array $workspaceRecord)
136 if (empty($workspaceRecord['uid'])) {
141 $update = $this->mapSettings($workspaceRecord, $update, 'edit', 'edit');
142 $update = $this->mapSettings($workspaceRecord, $update, 'publish', 'publish');
143 $update = $this->mapSettings($workspaceRecord, $update, 'publish', 'execute');
148 * Prepares SQL update for stage records.
150 * @param array $stageRecord
153 protected function prepareStageUpdate(array $stageRecord)
155 if (empty($stageRecord['uid'])) {
160 $update = $this->mapSettings($stageRecord, $update);
165 * Maps settings to new meaning.
167 * @param array $record
168 * @param array $update
169 * @param string $from
173 protected function mapSettings(array $record, array $update, $from = '', $to = '')
175 $fromPrefix = ($from ?
$from . '_' : '');
176 $toPrefix = ($to ?
$to . '_' : '');
179 // Previous setting: "Allow notification settings during stage change"
180 if ($record[$fromPrefix . 'allow_notificaton_settings']) {
183 // Previous setting: "All are selected per default (can be changed)"
184 if ((int)$record[$fromPrefix . 'notification_mode'] === 0) {
188 if (isset($record['responsible_persons'])) {
189 // Custom stages: preselect responsible persons (8)
191 } elseif ($to === 'edit') {
192 // Workspace "edit" stage: preselect members (2)
194 } elseif ($to === 'publish') {
195 // Workspace "publish" stage: preselect owners (1)
198 // Workspace "execute" stage: preselect owners (1) and members (2) as default
199 $preselection = 1 +
2;
202 $update[$toPrefix . 'allow_notificaton_settings'] = $settings;
203 $update[$toPrefix . 'notification_preselection'] = $preselection;