DataObjects/Events.php
[Pman.Core] / DataObjects / Events.php
index 337bffc..d1dba13 100644 (file)
@@ -604,83 +604,46 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             $roo->jerr('Invalid url');
         }
         
-        $processed = array();
         $restored = array();
-        $affects  = array();
         
         foreach ($log['DELETED_DATAOBJECTS'] as $d){
             if(
                     empty($d['id']) || 
                     empty($d['_table']) || 
                     (
-                            !empty($processed[$d['_table']]) && 
-                            in_array($d['id'], $processed[$d['_table']])
+                            !empty($restored[$d['_table']]) && 
+                            in_array($d['id'], $restored[$d['_table']])
                     )
             ){
                 continue;
             }
             
-            $tableName = $d['_table'];
-            
-            unset($d['_table']);
-            
-            if(!isset($processed[$tableName])){
-                $processed[$tableName] = array();
+            if(!isset($restored[$d['_table']])){
+                $restored[$d['_table']] = array();
             }
             
-            $processed[$tableName][] = $d['id'];
+            $restored[$d['_table']][] = $d['id'];
             
-            
-            $table = DB_DataObject::factory($tableName);
+            $table = DB_DataObject::factory($d['_table']);
             
             if (!is_a($table,'DB_DataObject')) {
                 continue;
             }
             
-            $table->query("ALTER TABLE {$tableName} DISABLE ALL TRIGGERS");
-            
-            $table = DB_DataObject::factory($tableName);
-            
-            $pk = $table->keys();
-            
-            $all_links = $GLOBALS['_DB_DATAOBJECT']['LINKS'][$this->_database];
-
-            foreach($all_links as $tbl => $links) {
-                foreach($links as $col => $totbl_col) {
-                    $to = explode(':', $totbl_col);
-                    if ($to[0] != $this->tableName()) {
-                        continue;
-                    }
-                    
-                    if(!isset($affects[$tbl])){
-                        $affects[$tbl] = array();
-                    }
-                    
-                    if(!isset($affects[$tbl][$col])){
-                        $affects[$tbl][$col] = array();
-                    }
-                    
-                    $affects[$tbl][$col][$d['id']] = $table->tableName() . '.' . ((empty($pk)) ? 'id' : $pk[0]);
-                    
-                }
-            }
+            unset($d['_table']);
             
             $table->setFrom($d);
             
-            $table->insert();
-            
-            if(!isset($restored[$table->tableName()])){
-                $restored[$table->tableName()] = array();
-            }
-            
-            $restored[$table->tableName()][$d['id']] = $table;
-            
-            $table = DB_DataObject::factory($tableName);
+            /*
+             * need to use the old id
+             */
+            $table->id = $d['id'];
             
-            $table->query("ALTER TABLE {$tableName} ENABLE ALL TRIGGERS");
+            $table->sequenceKey(false,false);
             
+            $table->insert();     
         }
-        print_R($affects);exit;
         
+        $roo->jok('RESTORE');
     }
 }