Added general history in Preorder
This commit is contained in:
@@ -39,6 +39,7 @@ class Preorder extends mfBaseModel {
|
||||
$this->creator = null;
|
||||
$this->editor = null;
|
||||
|
||||
// prevent potential infinite loop
|
||||
$nesting_level = mfValuecache::singleton()->get("preorder-save-nesting-level-".$this->id);
|
||||
if(!$nesting_level) {
|
||||
$nesting_level = 1;
|
||||
@@ -51,9 +52,6 @@ class Preorder extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
// prevent potential infinite loop
|
||||
//if($this->in_after_save) return true;
|
||||
//$this->in_after_save++;
|
||||
// update preorder OAID if it's different from the unit OAID
|
||||
// but only if the unit OAID is of the same origin as the campaign
|
||||
$old_oaid = $this->oaid;
|
||||
@@ -64,10 +62,9 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
|
||||
//TODO: history start
|
||||
if($this->status_id != $this->_old_data->status_id) {
|
||||
//if($this->status_id != $this->_old_data->status_id) {
|
||||
$this->createHistoryEntry();
|
||||
$this->_old_data->status_id = $this->status_id;
|
||||
}
|
||||
//}
|
||||
|
||||
// run triggers based on new status
|
||||
$this->runStatusTrigger();
|
||||
@@ -79,13 +76,22 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
|
||||
public function createHistoryEntry() {
|
||||
$history = PreorderHistoryModel::create([
|
||||
"preorder_id" => $this->id,
|
||||
"key" => 'preorderstatus_id',
|
||||
"old_value" => $this->_old_data->status_id,
|
||||
"new_value" => $this->status_id
|
||||
]);
|
||||
$history->save();
|
||||
if(!$this->id) return true;
|
||||
|
||||
$changed = $this->getChangedFields();
|
||||
|
||||
foreach($changed as $field) {
|
||||
$this->log->debug(__METHOD__.": $field changed from '".$this->_old_data->$field."' to '".$this->data->$field."'");
|
||||
$history = PreorderHistoryModel::create([
|
||||
"preorder_id" => $this->id,
|
||||
"key" => $field,
|
||||
"old_value" => $this->_old_data->$field,
|
||||
"new_value" => $this->data->$field
|
||||
]);
|
||||
$history->save();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function runStatusTrigger() {
|
||||
|
||||
Reference in New Issue
Block a user