public function restore($Log, $DeleteLog = true)
{
if (is_numeric($Log)) {
// Grab the log.
$LogID = $Log;
$Log = $this->getWhere(['LogID' => $LogID]);
if (!$Log) {
throw notFoundException('Log');
}
$Log = array_pop($Log);
}
$this->restoreOne($Log, $DeleteLog);
// Check for a transaction.
if ($TransactionID = $Log['TransactionLogID']) {
$Logs = $this->getWhere(['TransactionLogID' => $TransactionID], '', 'asc', 0, 200);
foreach ($Logs as $LogRow) {
if ($LogRow['LogID'] == $Log['LogID']) {
continue;
}
$this->restoreOne($LogRow, $DeleteLog);
}
}
// Check for child data.
if (isset($Log['Data']['_Data'])) {
$Data = $Log['Data']['_Data'];
foreach ($Data as $RecordType => $Rows) {
foreach ($Rows as $Row) {
$LogRow = array_merge($Log, ['RecordType' => $RecordType, 'Data' => $Row]);
if ($RecordType == 'Comment') {
$LogRow['ParentRecordID'] = $Row['DiscussionID'];
}
$this->restoreOne($LogRow, false);
}
}
}
}