mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-31 14:07:16 +00:00
add method rewriteReceiptLog()
This commit is contained in:
parent
5bdf7868d5
commit
b05a7f2ba5
|
@ -3593,6 +3593,77 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
|
|||
return $this->_receiptStatus;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Rewrites the complete receipt log
|
||||
*
|
||||
* Attention: this function is highly dangerous.
|
||||
* It removes an existing receipt log and rewrites it.
|
||||
* This method was added for importing an xml dump.
|
||||
*
|
||||
* @param array $receiptlog new status log with the newest log entry first.
|
||||
* @return boolean true on success, otherwise false
|
||||
*/
|
||||
function rewriteReceiptLog($recipients) { /* {{{ */
|
||||
$db = $this->_document->_dms->getDB();
|
||||
|
||||
$queryStr= "SELECT `tblDocumentRecipients`.* FROM `tblDocumentRecipients` WHERE `tblDocumentRecipients`.`documentID` = '". $this->_document->getID() ."' AND `tblDocumentRecipients`.`version` = '". $this->_version ."' ";
|
||||
$res = $db->getResultArray($queryStr);
|
||||
if (is_bool($res) && !$res)
|
||||
return false;
|
||||
|
||||
$db->startTransaction();
|
||||
|
||||
if($res) {
|
||||
foreach($res as $receipt) {
|
||||
$receiptID = $receipt['receiptID'];
|
||||
|
||||
/* First, remove the old entries */
|
||||
$queryStr = "DELETE from `tblDocumentReceiptLog` where `receiptID`=".$receiptID;
|
||||
if (!$db->getResult($queryStr)) {
|
||||
$db->rollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
|
||||
$queryStr = "DELETE from `tblDocumentRecipients` where `receiptID`=".$receiptID;
|
||||
if (!$db->getResult($queryStr)) {
|
||||
$db->rollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Second, insert the new entries */
|
||||
foreach($recipients as $receipt) {
|
||||
$queryStr = "INSERT INTO `tblDocumentRecipients` (`documentID`, `version`, `type`, `required`) ".
|
||||
"VALUES ('".$this->_document->getID()."', '".$this->_version."', ".$receipt['type'] .", ".$receipt['required']->getID().")";
|
||||
if (!$db->getResult($queryStr)) {
|
||||
$db->rollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
$receiptID = $db->getInsertID('tblDocumentRecipients', 'receiptID');
|
||||
$receiptlog = array_reverse($receipt['logs']);
|
||||
foreach($receiptlog as $log) {
|
||||
if(!SeedDMS_Core_DMS::checkDate($log['date'], 'Y-m-d H:i:s')) {
|
||||
$db->rollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
$queryStr = "INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) ".
|
||||
"VALUES ('".$receiptID ."', '".(int) $log['status']."', ".$db->qstr($log['comment']) .", ".$db->qstr($log['date']).", ".$log['user']->getID().")";
|
||||
if (!$db->getResult($queryStr)) {
|
||||
$db->rollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
$receiptLogID = $db->getInsertID('tblDocumentReceiptLog', 'receiptLogID');
|
||||
if(!empty($log['file'])) {
|
||||
SeedDMS_Core_File::copyFile($log['file'], $this->_dms->contentDir . $this->_document->getDir() . 'r' . $receiptLogID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$db->commitTransaction();
|
||||
return true;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Get the current revision status of the document content
|
||||
* The revision status is a list of revisions
|
||||
|
|
Loading…
Reference in New Issue
Block a user