|
@@ -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']);
|
|
|
}
|
|
|
}
|
|
|
}
|