‪TYPO3CMS  ‪main
WorkspaceMovePlaceholderRemovalMigration.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Log\LoggerAwareInterface;
21 use Psr\Log\LoggerAwareTrait;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 
38 {
39  use LoggerAwareTrait;
40 
41  public function ‪getTitle(): string
42  {
43  return 'Scan for move placeholders of workspaces and remove them from the database.';
44  }
45 
50  public function ‪hasPotentialUpdateForTable(string $tableName): bool
51  {
52  return BackendUtility::isTableWorkspaceEnabled($tableName);
53  }
54 
62  public function ‪updateTableRow(string $tableName, array $row): array
63  {
64  // We only want the information from the move placeholder
65  if ((int)$row['t3ver_state'] !== 3) {
66  return $row;
67  }
68 
69  // Since t3ver_state = 3 and t3ver_state = 4 are not connected, the only way to do this is via the live record
70  $liveUid = (int)($row['t3ver_move_id'] ?? 0);
71  $workspaceId = (int)($row['t3ver_wsid'] ?? 0);
72 
73  // Update the move pointer with the pid & sorting values of the move placeholder
74  if ($liveUid > 0) {
75  $updatedFieldsForMovePointer = [
76  'pid' => (int)$row['pid'],
77  ];
78  $sortByFieldName = ‪$GLOBALS['TCA'][$tableName]['ctrl']['sortby'] ?? null;
79  if ($sortByFieldName) {
80  $updatedFieldsForMovePointer[$sortByFieldName] = (int)$row[$sortByFieldName];
81  }
82 
83  // Update the move pointer record
84  GeneralUtility::makeInstance(ConnectionPool::class)
85  ->getConnectionForTable($tableName)
86  ->update(
87  $tableName,
88  $updatedFieldsForMovePointer,
89  [
90  't3ver_oid' => $liveUid,
91  't3ver_state' => ‪VersionState::MOVE_POINTER,
92  't3ver_wsid' => $workspaceId,
93  ]
94  );
95  }
96 
97  // The "deleted" key marks the information that this record should be deleted
98  // (with soft-delete or hard-delete) in the RowUpdater main class.
99  $row['deleted'] = 1;
100  return $row;
101  }
102 }
‪TYPO3\CMS\Install\Updates\RowUpdater\RowUpdaterInterface
Definition: RowUpdaterInterface.php:24
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceMovePlaceholderRemovalMigration\hasPotentialUpdateForTable
‪bool hasPotentialUpdateForTable(string $tableName)
Definition: WorkspaceMovePlaceholderRemovalMigration.php:50
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceMovePlaceholderRemovalMigration
Definition: WorkspaceMovePlaceholderRemovalMigration.php:38
‪TYPO3\CMS\Core\Versioning\VersionState\MOVE_POINTER
‪const MOVE_POINTER
Definition: VersionState.php:61
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceMovePlaceholderRemovalMigration\getTitle
‪getTitle()
Definition: WorkspaceMovePlaceholderRemovalMigration.php:41
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceMovePlaceholderRemovalMigration\updateTableRow
‪array updateTableRow(string $tableName, array $row)
Definition: WorkspaceMovePlaceholderRemovalMigration.php:62
‪TYPO3\CMS\Install\Updates\RowUpdater
Definition: L18nDiffsourceToJsonMigration.php:18
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51