‪TYPO3CMS  10.4
WorkspaceVersionRecordsMigration.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;
24 
33 class ‪WorkspaceVersionRecordsMigration implements ‪RowUpdaterInterface, LoggerAwareInterface
34 {
35  use LoggerAwareTrait;
36 
37  public function ‪getTitle(): string
38  {
39  return 'Scan for versioned records and fix their pid, or if no connection to a workspace is given, remove them completely to avoid having them shown on the live website.';
40  }
41 
46  public function ‪hasPotentialUpdateForTable(string $tableName): bool
47  {
49  }
50 
58  public function ‪updateTableRow(string $tableName, array $row): array
59  {
60  // We only modify records with "pid=-1"
61  if ((int)$row['pid'] !== -1) {
62  return $row;
63  }
64  // pid=-1 and live workspace => this may be very old "previous live" records that should be discarded
65  if ((int)$row['t3ver_wsid'] === 0) {
66  $deleteField = ‪$GLOBALS['TCA'][$tableName]['ctrl']['delete'] ?? 'deleted';
67  $row[$deleteField] = 1;
68  // continue processing versions
69  }
70  // regular versions and placeholders (t3ver_state one of -1, 0, 2, 4 - but not 3) having t3ver_oid set
71  if ((int)$row['t3ver_oid'] > 0 && (int)$row['t3ver_state'] !== ‪VersionState::MOVE_PLACEHOLDER) {
72  // We have a live version, let's connect that one
73  $liveRecord = $this->‪fetchPageId($tableName, (int)$row['t3ver_oid']);
74  if (is_array($liveRecord)) {
75  $row['pid'] = (int)$liveRecord['pid'];
76  return $row;
77  }
78  }
79  // move placeholder (t3ver_state=3) pointing to live version in t3ver_move_id
80  if ((int)$row['t3ver_move_id'] > 0 && (int)$row['t3ver_state'] === ‪VersionState::MOVE_PLACEHOLDER) {
81  // We have a live version, let's connect that one
82  $liveRecord = $this->‪fetchPageId($tableName, (int)$row['t3ver_move_id']);
83  if (is_array($liveRecord)) {
84  $row['pid'] = (int)$liveRecord['pid'];
85  return $row;
86  }
87  }
88  // No live version available
89  return $row;
90  }
91 
92  protected function ‪fetchPageId(string $tableName, int $id): ?array
93  {
94  return ‪BackendUtility::getRecord($tableName, $id, 'pid');
95  }
96 }
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration
Definition: WorkspaceVersionRecordsMigration.php:34
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration\getTitle
‪getTitle()
Definition: WorkspaceVersionRecordsMigration.php:37
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration\fetchPageId
‪fetchPageId(string $tableName, int $id)
Definition: WorkspaceVersionRecordsMigration.php:92
‪TYPO3\CMS\Install\Updates\RowUpdater\RowUpdaterInterface
Definition: RowUpdaterInterface.php:24
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration\updateTableRow
‪array updateTableRow(string $tableName, array $row)
Definition: WorkspaceVersionRecordsMigration.php:58
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled
‪static bool isTableWorkspaceEnabled($table)
Definition: BackendUtility.php:4021
‪TYPO3\CMS\Install\Updates\RowUpdater
Definition: RowUpdaterInterface.php:18
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration\hasPotentialUpdateForTable
‪bool hasPotentialUpdateForTable(string $tableName)
Definition: WorkspaceVersionRecordsMigration.php:46
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Versioning\VersionState\MOVE_PLACEHOLDER
‪const MOVE_PLACEHOLDER
Definition: VersionState.php:72