}
}
+ function beforeUpdate($old, $request,$roo)
+ {
+ if(!empty($request['_restore'])){
+ $this->restore($roo);
+ }
+ }
+
function onInsert($request,$roo)
{
$this->writeEventLog();
// fill toEventString.
if (!empty($q['_with_obj_summary']) && !empty($this->on_id)) {
$obj = $this->object();
+
if ($obj && $obj->pid() && method_exists($obj,'toEventString')) {
$es = $obj->toEventString();
- var_dump($es);
- if (strpos($this->remarks, $es) < 0) {
+
+ if (empty($this->remarks) || strpos($this->remarks, $es) < 0) {
$ret['remarks'] = $es . ' ' . $this->remarks;
}
+ } else if (empty($this->remarks)){
+ $ret['remarks'] = "DELETED";
+
}
}
+ //print_r($ret);
return $ret;
}
return $file;
}
+
+ function restore($roo)
+ {
+ $file = $this->retrieveEventLog();
+
+ if(empty($file) || !file_exists($file)){
+ $roo->jerr('Could not retrieve the event log file');
+ }
+
+ $log = json_decode(file_get_contents($file), true);
+
+ if(empty($log['POST']) || empty($log['POST']['_delete']) || empty($log['DELETED_DATAOBJECTS'])){
+ $roo->jerr('Invalid url');
+ }
+
+ $restored = array();
+
+ foreach ($log['DELETED_DATAOBJECTS'] as $d){
+ if(
+ empty($d['id']) ||
+ empty($d['_table']) ||
+ (
+ !empty($restored[$d['_table']]) &&
+ in_array($d['id'], $restored[$d['_table']])
+ )
+ ){
+ continue;
+ }
+
+ if(!isset($restored[$d['_table']])){
+ $restored[$d['_table']] = array();
+ }
+
+ $restored[$d['_table']][] = $d['id'];
+
+ $table = DB_DataObject::factory($d['_table']);
+
+ if (!is_a($table,'DB_DataObject')) {
+ continue;
+ }
+
+ unset($d['_table']);
+
+ $table->setFrom($d);
+
+ /*
+ * need to use the old id
+ */
+ $table->id = $d['id'];
+
+ $table->sequenceKey(false,false);
+
+ $table->insert();
+ }
+
+ $roo->jok('RESTORE');
+ }
}