‪TYPO3CMS  11.5
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;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 
32 class ‪WorkspaceVersionRecordsMigration implements ‪RowUpdaterInterface, LoggerAwareInterface
33 {
34  use LoggerAwareTrait;
35 
36  public function ‪getTitle(): string
37  {
38  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.';
39  }
40 
45  public function ‪hasPotentialUpdateForTable(string $tableName): bool
46  {
47  return BackendUtility::isTableWorkspaceEnabled($tableName);
48  }
49 
57  public function ‪updateTableRow(string $tableName, array $row): array
58  {
59  // We only modify records with "pid=-1"
60  if ((int)$row['pid'] !== -1) {
61  return $row;
62  }
63  // pid=-1 and live workspace => this may be very old "previous live" records that should be discarded
64  if ((int)$row['t3ver_wsid'] === 0) {
65  $deleteField = ‪$GLOBALS['TCA'][$tableName]['ctrl']['delete'] ?? 'deleted';
66  $row[$deleteField] = 1;
67  // continue processing versions
68  }
69  // regular versions and placeholders (t3ver_state one of -1, 0, 2, 4 - but not 3) having t3ver_oid set
70  if ((int)$row['t3ver_oid'] > 0 && (int)$row['t3ver_state'] !== 3) {
71  // We have a live version, let's connect that one
72  $liveRecord = $this->‪fetchPageId($tableName, (int)$row['t3ver_oid']);
73  if (is_array($liveRecord)) {
74  $row['pid'] = (int)$liveRecord['pid'];
75  return $row;
76  }
77  }
78  // move placeholder (t3ver_state=3) pointing to live version in t3ver_move_id
79  if ((int)$row['t3ver_state'] === 3 && (int)$row['t3ver_move_id'] > 0) {
80  // We have a live version, let's connect that one
81  $liveRecord = $this->‪fetchPageId($tableName, (int)$row['t3ver_move_id']);
82  if (is_array($liveRecord)) {
83  $row['pid'] = (int)$liveRecord['pid'];
84  return $row;
85  }
86  }
87  // No live version available
88  return $row;
89  }
90 
91  protected function ‪fetchPageId(string $tableName, int $id): ?array
92  {
93  return BackendUtility::getRecord($tableName, $id, 'pid');
94  }
95 }
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration
Definition: WorkspaceVersionRecordsMigration.php:33
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration\getTitle
‪getTitle()
Definition: WorkspaceVersionRecordsMigration.php:36
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration\fetchPageId
‪fetchPageId(string $tableName, int $id)
Definition: WorkspaceVersionRecordsMigration.php:91
‪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:57
‪TYPO3\CMS\Install\Updates\RowUpdater
Definition: L18nDiffsourceToJsonMigration.php:5
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration\hasPotentialUpdateForTable
‪bool hasPotentialUpdateForTable(string $tableName)
Definition: WorkspaceVersionRecordsMigration.php:45
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25