Commit 99c8137c authored by Frank Nägler's avatar Frank Nägler Committed by Andreas Fernandez
Browse files

[FEATURE] Add support for RecordHistory correlation ids in DataHandler

Resolves: #89292
Related: #89143
Releases: master
Change-Id: Ie10bcbfca7f43a60b80a2a6634759584043c7cf4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61848


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent b1cf4f25
......@@ -245,6 +245,13 @@ class DataHandler implements LoggerAwareInterface
*/
public $callBackObj;
/**
* A string which can be used as correlationId for RecordHistory entries.
* The string can later be used to rollback multiple changes at once.
* @var string
*/
protected $correlationId;
// *********************
// Internal variables (mapping arrays) which can be used (read-only) from outside
// *********************
......@@ -4020,7 +4027,7 @@ class DataHandler implements LoggerAwareInterface
}
}
$this->getRecordHistoryStore()->moveRecord($table, $uid, ['oldPageId' => $propArr['pid'], 'newPageId' => $destPid, 'oldData' => $propArr, 'newData' => $updateFields]);
$this->getRecordHistoryStore()->moveRecord($table, $uid, ['oldPageId' => $propArr['pid'], 'newPageId' => $destPid, 'oldData' => $propArr, 'newData' => $updateFields], $this->correlationId);
if ($this->enableLogging) {
// Logging...
$oldpagePropArr = $this->getRecordProperties('pages', $propArr['pid']);
......@@ -4083,7 +4090,7 @@ class DataHandler implements LoggerAwareInterface
$hookObj->moveRecord_afterAnotherElementPostProcess($table, $uid, $destPid, $origDestPid, $moveRec, $updateFields, $this);
}
}
$this->getRecordHistoryStore()->moveRecord($table, $uid, ['oldPageId' => $propArr['pid'], 'newPageId' => $destPid, 'oldData' => $propArr, 'newData' => $updateFields]);
$this->getRecordHistoryStore()->moveRecord($table, $uid, ['oldPageId' => $propArr['pid'], 'newPageId' => $destPid, 'oldData' => $propArr, 'newData' => $updateFields], $this->correlationId);
if ($this->enableLogging) {
// Logging...
$oldpagePropArr = $this->getRecordProperties('pages', $propArr['pid']);
......@@ -4747,9 +4754,9 @@ class DataHandler implements LoggerAwareInterface
// Add history entry
if ($undeleteRecord) {
$this->getRecordHistoryStore()->undeleteRecord($table, $uid);
$this->getRecordHistoryStore()->undeleteRecord($table, $uid, $this->correlationId);
} else {
$this->getRecordHistoryStore()->deleteRecord($table, $uid);
$this->getRecordHistoryStore()->deleteRecord($table, $uid, $this->correlationId);
}
// Update reference index:
......@@ -6524,7 +6531,7 @@ class DataHandler implements LoggerAwareInterface
// Set History data
$historyEntryId = 0;
if (isset($this->historyRecords[$table . ':' . $id])) {
$historyEntryId = $this->getRecordHistoryStore()->modifyRecord($table, $id, $this->historyRecords[$table . ':' . $id]);
$historyEntryId = $this->getRecordHistoryStore()->modifyRecord($table, $id, $this->historyRecords[$table . ':' . $id], $this->correlationId);
}
if ($this->enableLogging) {
if ($this->checkStoredRecords) {
......@@ -6628,7 +6635,7 @@ class DataHandler implements LoggerAwareInterface
$this->updateRefIndex($table, $id);
// Store in history
$this->getRecordHistoryStore()->addRecord($table, $id, $newRow);
$this->getRecordHistoryStore()->addRecord($table, $id, $newRow, $this->correlationId);
if ($newVersion) {
if ($this->enableLogging) {
......@@ -6740,7 +6747,8 @@ class DataHandler implements LoggerAwareInterface
$this->getRecordHistoryStore()->modifyRecord(
$table,
$id,
$this->historyRecords[$table . ':' . $id]
$this->historyRecords[$table . ':' . $id],
$this->correlationId
);
}
}
......@@ -8514,6 +8522,11 @@ class DataHandler implements LoggerAwareInterface
}
}
public function setCorrelationId(string $correlationId): void
{
$this->correlationId = $correlationId;
}
/**
* Entry point to post process a database insert. Currently bails early unless a UID has been forced
* and the database platform is not MySQL.
......
.. include:: ../../Includes.txt
==============================================================================
Feature: #89292 - Add support for RecordHistory correlationId's to DataHandler
==============================================================================
See :issue:`89292`
Description
===========
With :issue:`89143` a new feature for correlation ids in RecordHistory was introduced.
The DataHandler now also supports this feature by settings the :php:`$correlationId`
of the DataHandler instance.
.. code-block:: php
$correlationId = StringUtility::getUniqueId('slug_');
$data['pages'][$uid]['slug'] = $newSlug;
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->setCorrelationId($correlationId);
$dataHandler->start($data, []);
$dataHandler->process_datamap();
After this DataHandler operation the created RecordHistory entry contains the $correlationId.
.. index:: Backend, Database, PHP-API, ext:core
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment