Created
December 6, 2012 11:41
-
-
Save smichaelsen/4223869 to your computer and use it in GitHub Desktop.
Extbase Storage Backend that writes the changes to sys_history and sys_log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Tx_OrderTracker_Persistence_Storage_VersionedTypo3DbBackend extends Tx_Extbase_Persistence_Storage_Typo3DbBackend { | |
/** | |
* @var t3lib_TCEmain | |
* @inject | |
*/ | |
protected $tcemain; | |
/** | |
* @param t3lib_TCEmain $tcemain | |
* @return void | |
*/ | |
public function injectTcemain(t3lib_TCEmain $tcemain) { | |
$this->tcemain = $tcemain; | |
} | |
/** | |
* Updates a row in the storage | |
* | |
* @param string $tableName The database table name | |
* @param array $row The row to be updated | |
* @param boolean $isRelation TRUE if we are currently inserting into a relation table, FALSE by default | |
* @return bool | |
*/ | |
public function updateRow($tableName, array $row, $isRelation = FALSE) { | |
$this->tcemain->start(array(), array()); | |
$currentRecord = t3lib_BEfunc::getRecord($tableName, $row['uid']); | |
// sys_log | |
$logId = $this->tcemain->log( | |
$tableName, // $table | |
$row['uid'], // $recuid | |
2, // $action | |
$row['pid'], // $recpid | |
0, // $error | |
'Record \'%s\' (%s) was updated.', // $details | |
10, // $details_nr | |
array(t3lib_BEfunc::getRecordTitle($tableName, $currentRecord), $tableName . ':' . $row['uid']), // $data | |
$row['pid'] // $event_pid | |
); | |
// sys_history | |
$this->tcemain->historyRecords[$tableName . ':' . $row['uid']] = $this->getHistoryRecord($currentRecord, $row); | |
$this->tcemain->setHistory($tableName, $row['uid'], $logId); | |
return parent::updateRow($tableName, $row, $isRelation); | |
} | |
/** | |
* @param array $record | |
* @param array $updatedFields | |
* @return array | |
*/ | |
protected function getHistoryRecord(array $record, array $updatedFields) { | |
$historyData = array( | |
'oldRecord' => array(), | |
'newRecord' => array() | |
); | |
foreach ($updatedFields as $fieldName => $value) { | |
if ($value != $record[$fieldName]) { | |
$historyData['oldRecord'][$fieldName] = $record[$fieldName]; | |
$historyData['newRecord'][$fieldName] = $value; | |
} | |
} | |
return $historyData; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment