소스 검색

Adding error_logs, fixing queries - refs BT#4875

Julio Montoya 12 년 전
부모
커밋
6149fc66b0
3개의 변경된 파일49개의 추가작업 그리고 25개의 파일을 삭제
  1. 32 20
      tests/migrate/migration.class.php
  2. 4 0
      tests/migrate/migration.custom.class.php
  3. 13 5
      tests/migrate/migration.mssql.class.php

+ 32 - 20
tests/migrate/migration.class.php

@@ -95,13 +95,16 @@ class Migration {
     public function migrate($matches) {
         $found = false;
         $table_idx = -1;
+        error_log("\n".'------------ Migration->migrate function called ------------'."\n");
+        
         foreach ($matches as $id => $table) {
             error_log('Found table ' . $table['orig_table']);
             $build_only = false;
             if (empty($table['dest_table'])) {
-                error_log(' ...which is just for data building');
+                error_log(' ... which is just for data building');
                 $build_only = true;
             }
+            
             // Process the migration of fields from the given table
             $sql_select_fields = array();
             foreach ($table['fields_match'] as $id_field => $details) {
@@ -116,36 +119,45 @@ class Migration {
                     $func_alter = $details['sql_alter'];
                     $sql_select_fields[$details['orig']] = MigrationCustom::$func_alter($details['orig']);
                 }
-                error_log('  Found field ' . $details['orig'] . ' to be selected as ' . $sql_select_fields[$details['orig']]);
+                error_log('Found field ' . $details['orig'] . ' to be selected as ' . $sql_select_fields[$details['orig']]);
             }
+            
             $this->select_all($table['orig_table'], $sql_select_fields);
+            
             if (count($table['fields_match']) == 0) {
                 error_log('No fields found');
                 continue;
             }
-            while ($row = $this->fetch_row()) {
-                $dest_row = array();
-                $first_field = '';
-                foreach ($table['fields_match'] as $id_field => $details) {
-                    if ($id_field == 0) {
-                        $first_field = $details['dest'];
+            //if ($this->num_rows) {
+            if (1) {
+                error_log('Records found: '.$this->num_rows);
+                while ($row = $this->fetch_row()) {
+                    error_log(print_r($row, 1));
+                    $dest_row = array();
+                    $first_field = '';
+                    foreach ($table['fields_match'] as $id_field => $details) {
+                        if ($id_field == 0) {
+                            $first_field = $details['dest'];
+                        }
+                        // process the fields one by one
+                        if ($details['func'] == 'none') {
+                            $dest_data = $row[$details['orig']];
+                        } else {
+                            $dest_data = MigrationCustom::$details['func']($row[$details['orig']], $this->data_list);
+                        }
+                        $dest_row[$details['dest']] = $dest_data;
                     }
-                    // process the fields one by one
-                    if ($details['func'] == 'none') {
-                        $dest_data = $row[$details['orig']];
+                    if (!empty($table['dest_func'])) {
+                        error_log('Calling MigrationCustom::' . $table['dest_func'] . ' on data recovered: ' . print_r($dest_row, 1));
+                        //$table['dest_func']($dest_row);
                     } else {
-                        $dest_data = MigrationCustom::$details['func']($row[$details['orig']], $this->data_list);
+                        $this->errors_stack[] = "No destination data dest_func found. Abandoning data with first field $first_field = " . $dest_row[$first_field];
                     }
-                    $dest_row[$details['dest']] = $dest_data;
-                }
-                if (!empty($table['dest_func'])) {
-                    error_log('Calling MigrationCustom::' . $table['dest_func'] . ' on data recovered: ' . print_r($dest_row, 1));
-                    //$table['dest_func']($dest_row);
-                } else {
-                    $this->errors_stack[] = "No destination data dest_func found. Abandoning data with first field $first_field = " . $dest_row[$first_field];
                 }
+                error_log('Finished processing table ' . $table['orig_table']."\n\n");
+            } else {
+                error_log('No records found');
             }
-            error_log('Finished processing table ' . $table['orig_table']);
         }
     }
 }

+ 4 - 0
tests/migrate/migration.custom.class.php

@@ -51,4 +51,8 @@ class MigrationCustom {
     public function log_original_session_unique_id(&$omigrate, $data) {
         $omigrate['sessions'][$data] = 0;
     }
+    
+    public function store_user_data1() {
+        
+    }
 }

+ 13 - 5
tests/migrate/migration.mssql.class.php

@@ -18,7 +18,7 @@ class MigrationMSSQL extends Migration {
             $this->errors_stack[] = 'Could not connect. MSSQL error: ' . mssql_get_last_message();
             return false;
         }
-        mssql_select_db($dbname, $this->c);
+        mssql_select_db($this->odbname, $this->c);
         return true;
     }
 
@@ -27,15 +27,23 @@ class MigrationMSSQL extends Migration {
         foreach ($fields as $field) {
             $fields_sql .= $field . ', ';
         }
-        $fields_sql = substr($fields_sql, 0, -2);
-        $sql = 'SELECT ' . $fields_sql . ' FROM ' . $table;
+        if (!empty($fields_sql)) {
+            $fields_sql = substr($fields_sql, 0, -2);
+        }
+        $sql = "SELECT $fields_sql FROM $table";
         //remove
         error_log($sql);
         $this->rows_iterator = mssql_query($sql, $this->c);
+        
+        if ($this->rows_iterator  === false) {
+            error_log("--- Error with query ".$sql." MSSQL error: ".mssql_get_last_message()."-- \n");
+        }
     }
 
-    public function fetch_row() {
+    public function fetch_row() {        
         return mssql_fetch_row($this->rows_iterator);
     }
-
+    public function num_rows() {
+        return mssql_num_rows($this->rows_iterator);
+    }    
 }