Skip to content

Commit

Permalink
[BUGFIX] Allow deletion of records in tables without soft delete
Browse files Browse the repository at this point in the history
\TYPO3\CMS\Install\Updates\DatabaseRowsUpdateWizard currently can only
update rows.

\TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration
however needs to delete rows and marks them as deleted.
We now check for this value for tables without soft delete
and delete the row straight away

Resolves: #91213
Releases: master
Change-Id: I21163c7db435c316231c8e25daa8c190b1507621
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64328
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <look@susi.dev>
  • Loading branch information
helhum authored and susannemoog committed Apr 28, 2020
1 parent b333945 commit a92fd9f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
78 changes: 50 additions & 28 deletions typo3/sysext/install/Classes/Updates/DatabaseRowsUpdateWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace TYPO3\CMS\Install\Updates;

use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -213,22 +214,13 @@ public function executeUpdate(): bool
// Target table and sys_registry table are on the same connection, use a transaction
$connectionForTable->beginTransaction();
try {
$connectionForTable->update(
$this->updateOrDeleteRow(
$connectionForTable,
$connectionForTable,
$table,
(int)$rowBefore['uid'],
$updatedFields,
[
'uid' => $rowBefore['uid'],
]
);
$connectionForTable->update(
'sys_registry',
[
'entry_value' => serialize($startPosition),
],
[
'entry_namespace' => 'installUpdateRows',
'entry_key' => 'rowUpdatePosition',
]
$startPosition
);
$connectionForTable->commit();
} catch (\Exception $up) {
Expand All @@ -238,22 +230,13 @@ public function executeUpdate(): bool
} else {
// Different connections for table and sys_registry -> execute two
// distinct queries and hope for the best.
$connectionForTable->update(
$this->updateOrDeleteRow(
$connectionForTable,
$connectionForSysRegistry,
$table,
(int)$rowBefore['uid'],
$updatedFields,
[
'uid' => $rowBefore['uid'],
]
);
$connectionForSysRegistry->update(
'sys_registry',
[
'entry_value' => serialize($startPosition),
],
[
'entry_namespace' => 'installUpdateRows',
'entry_key' => 'rowUpdatePosition',
]
$startPosition
);
}
}
Expand Down Expand Up @@ -314,4 +297,43 @@ protected function getStartPosition(string $firstTable): array
}
return $startPosition;
}

/**
* @param Connection $connectionForTable
* @param string $table
* @param array $updatedFields
* @param int $uid
* @param Connection $connectionForSysRegistry
* @param array $startPosition
*/
protected function updateOrDeleteRow(Connection $connectionForTable, Connection $connectionForSysRegistry, string $table, int $uid, array $updatedFields, array $startPosition): void
{
$deleteField = $GLOBALS['TCA'][$table]['ctrl']['delete'] ?? null;
if ($deleteField === null && $updatedFields['deleted'] === 1) {
$connectionForTable->delete(
$table,
[
'uid' => $uid,
]
);
} else {
$connectionForTable->update(
$table,
$updatedFields,
[
'uid' => $uid,
]
);
}
$connectionForSysRegistry->update(
'sys_registry',
[
'entry_value' => serialize($startPosition),
],
[
'entry_namespace' => 'installUpdateRows',
'entry_key' => 'rowUpdatePosition',
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function updateTableRow(string $tableName, array $row): array
}
// pid=-1 and live workspace => this may be very old "previous live" records that should be discarded
if ((int)$row['t3ver_wsid'] === 0) {
$row['deleted'] = 1;
$deleteField = $GLOBALS['TCA'][$tableName]['ctrl']['delete'] ?? 'deleted';
$row[$deleteField] = 1;
// continue processing versions
}
// regular versions and placeholders (t3ver_state one of -1, 0, 2, 4 - but not 3) having t3ver_oid set
Expand Down

0 comments on commit a92fd9f

Please sign in to comment.