DataObjects/Core_enum.php
[Pman.Core] / DataObjects / Events.php
index 337bffc..7105ab0 100644 (file)
@@ -329,7 +329,9 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         $rem  = array();
         // should this really go in remarks? - 
         if ($obj && method_exists($obj,'toEventString')) {
-            $rem[] = $obj->toEventString() ;
+            if($obj->toEventString() !== false){
+                $rem[] = $obj->toEventString();
+            }
         }
         $rem[] = $remarks;
         $this->remarks = implode(' : ', $rem);
@@ -450,8 +452,13 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         self::$deleted[] = $del;
         return true;
     }
+    static $extra_data = false;
+    
+    static function writeEventLogExtra($data) {
+        self::$extra_data = $data;
+    }
     
-    function writeEventLog($extra_data  = '')
+    function writeEventLog($extra_data  = false)
     {
         $ff  = HTML_FlexyFramework::get();
         if (empty($ff->Pman['event_log_dir'])) {
@@ -511,9 +518,12 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         if (!empty(self::$deleted)) {
             $out['DELETED_DATAOBJECTS'] = self::$deleted;
         }
-        if (!empty($extra_data)) {
+        if ($extra_data !== false) {
             $out['EXTRA'] = $extra_data;
         }
+        if ( self::$extra_data !== false) {
+            $out['EXTRA_DATA'] =  self::$extra_data;
+        }
         
         file_put_contents($file, json_encode($out));
         
@@ -604,83 +614,63 @@ 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");
+            unset($d['_table']);
             
-            $table = DB_DataObject::factory($tableName);
+            $table->setFrom($d);
             
-            $pk = $table->keys();
+            /*
+             * need to use the old id
+             */
+            $table->id = $d['id'];
             
-            $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]);
-                    
-                }
-            }
-            
-            $table->setFrom($d);
+            $table->sequenceKey(false,false);
             
             $table->insert();
             
-            if(!isset($restored[$table->tableName()])){
-                $restored[$table->tableName()] = array();
+            if($table->tableName() == 'crm_mailing_list_member'){
+                $ml = DB_DataObject::factory('crm_mailing_list');
+                if(!$ml->get($table->mailing_list_id)){
+                    continue;
+                }
+
+                $mlm = DB_DataObject::factory('crm_mailing_list_member');
+                $mlm->setFrom(array(
+                    'mailing_list_id' => $table->mailing_list_id,
+                    'is_active' => 1
+                ));
+
+                $o = clone($ml);
+                $ml->no_members = $mlm->count();
+                $ml->update($o);
             }
-            
-            $restored[$table->tableName()][$d['id']] = $table;
-            
-            $table = DB_DataObject::factory($tableName);
-            
-            $table->query("ALTER TABLE {$tableName} ENABLE ALL TRIGGERS");
-            
         }
-        print_R($affects);exit;
         
+        $roo->jok('RESTORE');
     }
 }