Add loading of data into database. #762
This commit is contained in:
parent
c318c471ff
commit
4c0460bdb5
1 changed files with 110 additions and 5 deletions
|
|
@ -127,7 +127,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the load file for the backup data
|
// create the load file for the backup data
|
||||||
$this->createLoadDataFileForBackupData($backup_data);
|
$this->createLoadDataFileForBackupData($backup_data, $archive_table_name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -229,7 +229,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
|
|
||||||
$rider_id = '\N';
|
$rider_id = '\N';
|
||||||
if ($row['rider_id'] != NULL)
|
if ($row['rider_id'] != NULL)
|
||||||
$rider_id = $row]'rider_id'];
|
$rider_id = $row['rider_id'];
|
||||||
|
|
||||||
$date_create = $row['date_create'];
|
$date_create = $row['date_create'];
|
||||||
$date_schedule = $row['date_schedule'];
|
$date_schedule = $row['date_schedule'];
|
||||||
|
|
@ -311,6 +311,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
$fac_type = $row['facilitated_type'];
|
$fac_type = $row['facilitated_type'];
|
||||||
|
|
||||||
$coord_long = $row['coord_long'];
|
$coord_long = $row['coord_long'];
|
||||||
|
$coord_lat = $row['coord_lat'];
|
||||||
$priority = $row['priority'];
|
$priority = $row['priority'];
|
||||||
$meta = $row['meta'];
|
$meta = $row['meta'];
|
||||||
|
|
||||||
|
|
@ -325,7 +326,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
|
|
||||||
$no_trade_in_reason = '\N';
|
$no_trade_in_reason = '\N';
|
||||||
if ($row['no_trade_in_reason'] != NULL)
|
if ($row['no_trade_in_reason'] != NULL)
|
||||||
$no_trade_in_reason = $row[' no_trade_in_reason'];
|
$no_trade_in_reason = $row['no_trade_in_reason'];
|
||||||
|
|
||||||
$will_wait = $row['will_wait'];
|
$will_wait = $row['will_wait'];
|
||||||
|
|
||||||
|
|
@ -383,11 +384,115 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
$data = [
|
$data = [
|
||||||
$id,
|
$id,
|
||||||
$cust_id,
|
$cust_id,
|
||||||
// TODO: finish writing to array
|
$cv_id,
|
||||||
|
$rider_id,
|
||||||
|
$date_create,
|
||||||
|
$date_schedule,
|
||||||
|
$date_fulfill,
|
||||||
|
$coordinates,
|
||||||
|
$flag_advance,
|
||||||
|
$service_type,
|
||||||
|
$source,
|
||||||
|
$date_cancel,
|
||||||
|
$status,
|
||||||
|
$del_instructions,
|
||||||
|
$del_address,
|
||||||
|
$create_user_id,
|
||||||
|
$assign_user_id,
|
||||||
|
$date_assign,
|
||||||
|
$warr_class,
|
||||||
|
$process_user_id,
|
||||||
|
$hub_id,
|
||||||
|
$cancel_reason,
|
||||||
|
$ref_jo_id,
|
||||||
|
$tier1_notes,
|
||||||
|
$tier2_notes,
|
||||||
|
$mode_of_payment,
|
||||||
|
$or_name,
|
||||||
|
$landmark,
|
||||||
|
$promo_details,
|
||||||
|
$or_num,
|
||||||
|
$trade_in_type,
|
||||||
|
$flag_rider_rating,
|
||||||
|
$flag_coolant,
|
||||||
|
$fac_hub_id,
|
||||||
|
$fac_type,
|
||||||
|
$coord_long,
|
||||||
|
$coord_lat,
|
||||||
|
$priority,
|
||||||
|
$meta,
|
||||||
|
$status_autoassign,
|
||||||
|
$first_name,
|
||||||
|
$last_name,
|
||||||
|
$plate_number,
|
||||||
|
$phone_mobile,
|
||||||
|
$no_trade_in_reason,
|
||||||
|
$will_wait,
|
||||||
|
$reason_not_waiting,
|
||||||
|
$not_waiting_notes,
|
||||||
|
$del_status,
|
||||||
|
$emergency_type_id,
|
||||||
|
$owner_type_id,
|
||||||
|
$cust_location_id,
|
||||||
|
$source_of_awareness,
|
||||||
|
$remarks,
|
||||||
|
$initial_concern,
|
||||||
|
$initial_concern_notes,
|
||||||
|
$gender,
|
||||||
|
$caller_class,
|
||||||
|
$inv_count
|
||||||
];
|
];
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: write the load data file function
|
protected function createLoadDataFileForBackupData($backup_data, $table_name)
|
||||||
|
{
|
||||||
|
// cache directory
|
||||||
|
$cache_dir = __DIR__ . '/../../var/cache';
|
||||||
|
|
||||||
|
$file = $cache_dir . '/jo_archive.tab';
|
||||||
|
error_log('opening file for jo archive - ' . $file);
|
||||||
|
|
||||||
|
$fp = fopen($file, 'w');
|
||||||
|
if ($fp === false)
|
||||||
|
{
|
||||||
|
error_log('could not open file for load data infile - ' . $file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach ($backup_data as $key => $data)
|
||||||
|
{
|
||||||
|
$line = implode('|', $data) . "\r\n";
|
||||||
|
fwrite($fp, $line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
$conn = $this->em->getConnection();
|
||||||
|
$stmt = $conn->prepare('LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $table_name . '
|
||||||
|
FIELDS TERMINATED BY \'|\'
|
||||||
|
LINES TERMINATED BY \'\\r\\n\'
|
||||||
|
(id, customer_id, cvehicle_id, rider_id, date_create,
|
||||||
|
date_schedule, date_fulfill, coordinates, flag_advance, service_type,
|
||||||
|
source, date_cancel, status, delivery_instructions, delivery_address,
|
||||||
|
create_user_id, assign_user_id, date_assign, warranty_class, process_user_id,
|
||||||
|
hub_id, cancel_reason, ref_jo_id, tier1_notes, tier2_notes,
|
||||||
|
mode_of_payment, or_name, landmark, promo_detail, or_num,
|
||||||
|
trade_in_type, flag_rider_rating, flag_coolant, facilitated_hub_id, facilitated_type,
|
||||||
|
coord_long, coord_lat, priority, meta, status_autoassign,
|
||||||
|
first_name, last_name, plate_number, phone_mobile, no_trade_in_reason,
|
||||||
|
will_wait, reason_not_waiting, not_waiting_notes, delivery_status, emergency_type_id,
|
||||||
|
ownership_type_id, cust_location_id, source_of_awareness, remarks, initial_concern,
|
||||||
|
initial_concern_notes, gender, caller_classification, inventory_count)');
|
||||||
|
|
||||||
|
$result = $stmt->execute();
|
||||||
|
|
||||||
|
if (!$result)
|
||||||
|
error_log('Failed loading data.');
|
||||||
|
|
||||||
|
// TODO: delete file?
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue