From 29f1c34b2ce09f5851048be358df93748a934c85 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 4 Jun 2021 00:52:26 +0800 Subject: [PATCH 1/8] Change filename year to 4-digits #576 --- utils/get_warranty_serial/get_serials.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/get_warranty_serial/get_serials.php b/utils/get_warranty_serial/get_serials.php index 237ce266..3a0f3d24 100644 --- a/utils/get_warranty_serial/get_serials.php +++ b/utils/get_warranty_serial/get_serials.php @@ -23,10 +23,10 @@ $blob_client = BlobRestProxy::createBlobService($conn_string); $current_date = new DateTime(); $current_date->modify("-1 day"); -$date = $current_date->format('m-d-y'); +$date = $current_date->format('m-d-Y'); $filename = 'warrantylogs' . $date . '.csv'; -//print_r($filename); +error_log($filename); try { // NOTE: via download blob From b300814b500523c6ed9f72e80eef1efbc5fd7de8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 4 Jun 2021 10:22:28 +0000 Subject: [PATCH 2/8] Add error checking to processing script. Create new script for downloading files from motiv. #576 --- utils/get_warranty_serial/get_serials.php | 17 ++++-- utils/get_warranty_serial/new_get_serials.php | 49 +++++++++++++++ utils/load_warranty_serial/load_serials.php | 59 +++++++++++++++---- utils/warranty_motiv_local_bulk.sh | 36 +++++++++++ 4 files changed, 143 insertions(+), 18 deletions(-) create mode 100644 utils/get_warranty_serial/new_get_serials.php create mode 100755 utils/warranty_motiv_local_bulk.sh diff --git a/utils/get_warranty_serial/get_serials.php b/utils/get_warranty_serial/get_serials.php index 3a0f3d24..e9538e3f 100644 --- a/utils/get_warranty_serial/get_serials.php +++ b/utils/get_warranty_serial/get_serials.php @@ -20,14 +20,20 @@ $conn_string = "BlobEndpoint=$blob_url;\nSharedAccessSignature=$sas_token"; $blob_client = BlobRestProxy::createBlobService($conn_string); -$current_date = new DateTime(); -$current_date->modify("-1 day"); +// get date argument +$proc_date = $argv[1]; -$date = $current_date->format('m-d-Y'); +error_log($proc_date); -$filename = 'warrantylogs' . $date . '.csv'; +//$current_date = new DateTime(); +//$current_date->modify("-1 day"); + +//$date = $current_date->format('m-d-Y'); + +$filename = 'warrantylogs' . $proc_date . '.csv'; error_log($filename); +/* try { // NOTE: via download blob $res = $blob_client->getBlob('warranty', $filename); @@ -36,8 +42,7 @@ try { file_put_contents("/tmp/warranty_download_serial.txt", $res->getContentStream()); } catch (Exception $e) { file_put_contents("/tmp/serial_download_error.txt", $filename . "\n" . $e->getMessage() . "\n" . "\n", FILE_APPEND); -} - +} */ /* // NOTE: getting via url diff --git a/utils/get_warranty_serial/new_get_serials.php b/utils/get_warranty_serial/new_get_serials.php new file mode 100644 index 00000000..45161f3a --- /dev/null +++ b/utils/get_warranty_serial/new_get_serials.php @@ -0,0 +1,49 @@ +getBlob('warranty', $filename); + // print_r($res); + + if ($flag_overwrite > 0) + { + file_put_contents($output_file, $res->getContentStream()); + } + else + { + file_put_contents($output_file, "\r\n", FILE_APPEND); + file_put_contents($output_file, $res->getContentStream(), FILE_APPEND); + } +} catch (Exception $e) { + file_put_contents("/tmp/serial_download_error.txt", $filename . "\n" . $e->getMessage() . "\n" . "\n", FILE_APPEND); +} + + + + + diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index cd1cce90..6eb1d918 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -5,6 +5,9 @@ $csv = fopen($argv[1], 'r'); $dsn = $argv[2]; $user = $argv[3]; $pass = $argv[4]; +$output_file = $argv[5]; + +$output_fh = fopen($output_file, "w"); // connect to db $db = new PDO($dsn, $user, $pass); @@ -13,33 +16,54 @@ $db = new PDO($dsn, $user, $pass); $sth = $db->prepare('insert into warranty_serial (id, sku, date_create, source, meta_info) values (:serial, :sku, :date_create, :source, :meta_info)'); // go through rows -$counter = 0; $source = 'motiv'; while (($row = fgetcsv($csv)) !== false) { - // skip first line - if ($counter == 0) + // TODO: verify if these are still the headers if there are headers + // possible lines in output file: + // (1) header in csv file + // SerialNumber,Sku,DispatchStatus,CreatedDate,InventoryStatus,CategoryID,CategoryName + // (2) No available data + // (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF + // (4) Empty line + + // check if csv file has a header by checking contents of line + if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') || + ($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') || + ($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') || + ($row[6] == 'CategoryName')) { - $counter++; + // skip the header + error_log('Skipping the headers... '); continue; } - /* - $serial = trim(strtoupper($row[0])); - $sku = trim($row[1]); - $date_create = $row[2]; - $ref_id = $row[3]; */ + // check if No available data + if ($row[0] == 'No available data') + { + // skip the line + error_log('No available data, skipping the line...'); + continue; + } + // check if new line + if (empty($row[0])) + { + // skip + error_log('Skipping empty line...'); + continue; + } + // sample of line in output file: // serial number, sku, dispatch status, created date, inventory status, category id, category name // CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF $serial = trim(strtoupper($row[0])); - $sku = trim($row[1]); + $sku = trim(strtoupper($row[1])); $dispatch_status = trim($row[2]); $date_create = $row[3]; $inventory_status = trim($row[4]); $cat_id = trim($row[5]); - $cat_name = trim($row[6]); + $cat_name = trim(strtoupper($row[6])); $meta_info = [ 'dispatch_status' => $dispatch_status, @@ -50,6 +74,8 @@ while (($row = fgetcsv($csv)) !== false) $info = json_encode($meta_info); + error_log('Processing ' . $serial . ' and ' . $sku); + if ($sku == 'N/A') $sku = null; @@ -63,12 +89,21 @@ while (($row = fgetcsv($csv)) !== false) if (!$res) { + // log the error $err = $sth->errorInfo(); - echo "Error ($serial) - " . $err[2] . "\n"; + $err_message = "$serial - ERROR - " . $err[2] . "\n"; + fwrite($output_fh, $err_message); + } + else + { + // log successful adding of serial + $message = "$serial - SUCCESS - " . "\n"; + fwrite($output_fh, $message); } } // close file fclose($csv); +fclose($output_fh); diff --git a/utils/warranty_motiv_local_bulk.sh b/utils/warranty_motiv_local_bulk.sh new file mode 100755 index 00000000..167e8566 --- /dev/null +++ b/utils/warranty_motiv_local_bulk.sh @@ -0,0 +1,36 @@ +#!/bin/bash +touch /tmp/warranty_download_serial.csv +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-03-2021 /tmp/warranty_download_serial.csv 1 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-04-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-05-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-06-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-07-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-08-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-09-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-10-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-11-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-12-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-13-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-14-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-15-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-16-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-17-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-18-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-19-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-20-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-21-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-22-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-23-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-24-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-25-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-26-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-27-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-28-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-29-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-30-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-31-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-01-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-02-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-03-2021 /tmp/warranty_download_serial.csv 0 +touch /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" root password /tmp/warranty_load_status.txt From ed14a3defd013b30b786cabf3cab91ab717662df Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 8 Jun 2021 08:38:02 +0000 Subject: [PATCH 3/8] Fix scripts for warranty serials. #576 --- utils/load_warranty_serial/load_serials.php | 74 ++++++++++++++++----- utils/warranty_motiv_local.sh | 9 +++ utils/warranty_motiv_local_bulk.sh | 68 ++++++++++--------- utils/warranty_motiv_prod.sh | 11 ++- utils/warranty_motiv_prod_bulk.sh | 40 +++++++++++ 5 files changed, 152 insertions(+), 50 deletions(-) create mode 100755 utils/warranty_motiv_local.sh create mode 100755 utils/warranty_motiv_prod_bulk.sh diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index 6eb1d918..9df178bc 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -9,6 +9,14 @@ $output_file = $argv[5]; $output_fh = fopen($output_file, "w"); +if (!file_exists($csv)) +{ + $err_message = "No csv input file found." . "\n"; + fwrite($output_fh, $err_message); + fclose($output_fh); + exit(); +} + // connect to db $db = new PDO($dsn, $user, $pass); @@ -27,17 +35,6 @@ while (($row = fgetcsv($csv)) !== false) // (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF // (4) Empty line - // check if csv file has a header by checking contents of line - if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') || - ($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') || - ($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') || - ($row[6] == 'CategoryName')) - { - // skip the header - error_log('Skipping the headers... '); - continue; - } - // check if No available data if ($row[0] == 'No available data') { @@ -53,18 +50,67 @@ while (($row = fgetcsv($csv)) !== false) error_log('Skipping empty line...'); continue; } + + // check if csv file has a header by checking contents of line + if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') || + ($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') || + ($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') || + ($row[6] == 'CategoryName')) + { + // skip the header + error_log('Skipping the headers... '); + continue; + } // sample of line in output file: // serial number, sku, dispatch status, created date, inventory status, category id, category name // CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF + // MG2000313690,N/A,1,2021-05-14T23:47:30.6430000+08:00,0,10,GOLD $serial = trim(strtoupper($row[0])); $sku = trim(strtoupper($row[1])); $dispatch_status = trim($row[2]); - $date_create = $row[3]; + $str_date_create = trim($row[3]); $inventory_status = trim($row[4]); $cat_id = trim($row[5]); $cat_name = trim(strtoupper($row[6])); + error_log('Processing ' . $serial . ' and ' . $sku); + + // since some people cannot follow simple instructions... + // check the date format on the string + // try 2021-05-15T08:35:46+08:00 format on str_date_create + $date_create = DateTime::createFromFormat('Y-m-d\TH:i:sP', $str_date_create); + + if ($date_create == false) + { + // try this format: 2021-05-15T08:47:20.3330000+08:00 + // get the date, time and timezone from str_date_create + $str_date_time = substr($str_date_create, 0, 19); + $str_timezone = substr($str_date_create, 27); + $str_datetime_tz = $str_date_time . $str_timezone; + + // create DateTime object + // sample: 2021-05-15T12:16:06+08:00 + $date_create = DateTime::createFromFormat('Y-m-d\TH:i:sP', $str_datetime_tz); + + // check if datetime object was created + // if not, someone f*cked up and we have no date create + if ($date_create == false) + { + // log the serial + $message = "$serial - ERROR - " . "Invalid date format for create date." . "\n"; + fwrite($output_fh, $message); + continue; + } + } + + $created_date = $date_create->format('Y-m-d H:i:s'); + + //error_log($str_date_time); + //error_log($str_timezone); + //error_log($str_datetime_tz); + //error_log($date_create->format('Y-m-d H:i:s')); + $meta_info = [ 'dispatch_status' => $dispatch_status, 'inventory_status' => $inventory_status, @@ -74,15 +120,13 @@ while (($row = fgetcsv($csv)) !== false) $info = json_encode($meta_info); - error_log('Processing ' . $serial . ' and ' . $sku); - if ($sku == 'N/A') $sku = null; $res = $sth->execute([ ':serial' => $serial, ':sku' => $sku, - ':date_create' => $date_create, + ':date_create' => $created_date, ':source' => $source, ':meta_info' => $info, ]); diff --git a/utils/warranty_motiv_local.sh b/utils/warranty_motiv_local.sh new file mode 100755 index 00000000..403c62c2 --- /dev/null +++ b/utils/warranty_motiv_local.sh @@ -0,0 +1,9 @@ +#!/bin/bash +#touch /tmp/warranty_download_serial.csv +proc_date=`date +%m-%d-%y -d "1 day ago"` +download_file="/tmp/warranty_download_serial_$proc_date.csv" +load_status_file="/tmp/warranty_load_status_$proc_date.txt" +echo $download_file +echo $load_status_file +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=localhost;dbname=resq;charset=UTF8" root password $load_status_file diff --git a/utils/warranty_motiv_local_bulk.sh b/utils/warranty_motiv_local_bulk.sh index 167e8566..5e1a0ab4 100755 --- a/utils/warranty_motiv_local_bulk.sh +++ b/utils/warranty_motiv_local_bulk.sh @@ -1,36 +1,40 @@ #!/bin/bash touch /tmp/warranty_download_serial.csv -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-03-2021 /tmp/warranty_download_serial.csv 1 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-04-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-05-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-06-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-07-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-08-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-09-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-10-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-11-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-12-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-13-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-14-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-15-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-16-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-17-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-18-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-19-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-20-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-21-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-22-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-23-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-24-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-25-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-26-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-27-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-28-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-29-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-30-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-31-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-01-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-02-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-03-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-03-21 /tmp/warranty_download_serial.csv 1 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-04-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-05-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-06-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-07-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-08-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-09-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-10-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-11-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-12-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-13-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-14-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-15-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-16-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-17-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-18-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-19-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-20-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-21-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-22-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-23-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-24-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-25-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-26-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-27-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-28-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-29-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-30-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-31-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-01-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-02-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-03-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-04-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-05-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt /usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" root password /tmp/warranty_load_status.txt diff --git a/utils/warranty_motiv_prod.sh b/utils/warranty_motiv_prod.sh index f13a7d7d..12d00761 100755 --- a/utils/warranty_motiv_prod.sh +++ b/utils/warranty_motiv_prod.sh @@ -1,4 +1,9 @@ #!/bin/bash -touch /tmp/warranty_download_serial.txt -/usr/bin/php /var/www/resq/utils/get_warranty_serial/get_serials.php -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.txt "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 +proc_date=`date +%m-%d-%y -d "1 day ago"` +download_file="/tmp/warranty_download_serial_$proc_date.csv" +load_status_file="/tmp/warranty_load_status_$proc_date.txt" +#echo $download_file +#echo $load_status_file +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 $load_status_file + diff --git a/utils/warranty_motiv_prod_bulk.sh b/utils/warranty_motiv_prod_bulk.sh new file mode 100755 index 00000000..231f6bc2 --- /dev/null +++ b/utils/warranty_motiv_prod_bulk.sh @@ -0,0 +1,40 @@ +#!/bin/bash +touch /tmp/warranty_download_serial.csv +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-03-21 /tmp/warranty_download_serial.csv 1 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-04-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-05-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-06-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-07-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-08-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-09-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-10-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-11-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-12-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-13-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-14-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-15-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-16-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-17-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-18-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-19-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-20-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-21-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-22-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-23-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-24-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-25-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-26-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-27-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-28-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-29-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-30-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-31-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-01-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-02-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-03-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-04-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-05-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 +touch /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 /tmp/warranty_load_status.txt From 560db62a0817158551d526cdc1889d727a47541e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 8 Jun 2021 09:32:15 +0000 Subject: [PATCH 4/8] Fix error checking. #576 --- utils/load_warranty_serial/load_serials.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index 9df178bc..323f3156 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -9,7 +9,7 @@ $output_file = $argv[5]; $output_fh = fopen($output_file, "w"); -if (!file_exists($csv)) +if (!file_exists($argv[1])) { $err_message = "No csv input file found." . "\n"; fwrite($output_fh, $err_message); @@ -34,6 +34,7 @@ while (($row = fgetcsv($csv)) !== false) // (2) No available data // (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF // (4) Empty line + // (5) empty sku // check if No available data if ($row[0] == 'No available data') @@ -43,25 +44,22 @@ while (($row = fgetcsv($csv)) !== false) continue; } - // check if new line - if (empty($row[0])) + // check if empty line + if ($row == array(null)) { // skip error_log('Skipping empty line...'); continue; } - // check if csv file has a header by checking contents of line - if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') || - ($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') || - ($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') || - ($row[6] == 'CategoryName')) + // check if empty serial + if (empty($row[0])) { - // skip the header - error_log('Skipping the headers... '); + $err_message = "Empty serial. " . "\n"; + fwrite($output_fh, $err_message); continue; } - + // sample of line in output file: // serial number, sku, dispatch status, created date, inventory status, category id, category name // CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF From 8fa3551d47890403f4ea451139d62c104b2b9351 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 8 Jun 2021 10:48:38 +0000 Subject: [PATCH 5/8] Remove cred as arguments. #576 --- .env.dist | 4 ++++ utils/load_warranty_serial/load_serials.php | 15 ++++++++++++--- utils/warranty_motiv_local.sh | 2 +- utils/warranty_motiv_local_bulk.sh | 2 +- utils/warranty_motiv_prod.sh | 2 +- utils/warranty_motiv_prod_bulk.sh | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.env.dist b/.env.dist index f6d35eec..06731d8f 100644 --- a/.env.dist +++ b/.env.dist @@ -80,3 +80,7 @@ API_VERSION=insert_api_version_here #SSL_ENABLE for websockets SSL_ENABLE=set_to_true_or_false + +# db +DB_USER=db_username +DB_PASSWORD=db_password diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index 323f3156..d5369aac 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -1,11 +1,13 @@ loadEnv(__DIR__.'/../../.env'); + +$user = $_ENV['DB_USER']; +$pass = $_ENV['DB_PASSWORD']; + // connect to db $db = new PDO($dsn, $user, $pass); diff --git a/utils/warranty_motiv_local.sh b/utils/warranty_motiv_local.sh index 403c62c2..ddfcd6f5 100755 --- a/utils/warranty_motiv_local.sh +++ b/utils/warranty_motiv_local.sh @@ -6,4 +6,4 @@ load_status_file="/tmp/warranty_load_status_$proc_date.txt" echo $download_file echo $load_status_file /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=localhost;dbname=resq;charset=UTF8" root password $load_status_file +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=localhost;dbname=resq;charset=UTF8" $load_status_file diff --git a/utils/warranty_motiv_local_bulk.sh b/utils/warranty_motiv_local_bulk.sh index 5e1a0ab4..14a5e636 100755 --- a/utils/warranty_motiv_local_bulk.sh +++ b/utils/warranty_motiv_local_bulk.sh @@ -37,4 +37,4 @@ touch /tmp/warranty_download_serial.csv /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" root password /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" /tmp/warranty_load_status.txt diff --git a/utils/warranty_motiv_prod.sh b/utils/warranty_motiv_prod.sh index 12d00761..798158ef 100755 --- a/utils/warranty_motiv_prod.sh +++ b/utils/warranty_motiv_prod.sh @@ -5,5 +5,5 @@ load_status_file="/tmp/warranty_load_status_$proc_date.txt" #echo $download_file #echo $load_status_file /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 $load_status_file +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" $load_status_file diff --git a/utils/warranty_motiv_prod_bulk.sh b/utils/warranty_motiv_prod_bulk.sh index 231f6bc2..446e68f1 100755 --- a/utils/warranty_motiv_prod_bulk.sh +++ b/utils/warranty_motiv_prod_bulk.sh @@ -37,4 +37,4 @@ touch /tmp/warranty_download_serial.csv /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" /tmp/warranty_load_status.txt From 4b76e1e0d144dd372b387a55a4412fa1c5b4fe93 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 8 Jun 2021 10:48:57 +0000 Subject: [PATCH 6/8] Remove cred as arguments. #576 --- utils/warranty_motiv_dev.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/warranty_motiv_dev.sh b/utils/warranty_motiv_dev.sh index 00c73418..95f687d6 100755 --- a/utils/warranty_motiv_dev.sh +++ b/utils/warranty_motiv_dev.sh @@ -1,4 +1,4 @@ #!/bin/bash touch /tmp/warranty_download_serial.txt -/usr/bin/php /usr/share/nginx/html/resqapi/utils/get_warranty_serial/get_serials.php -/usr/bin/php /usr/share/nginx/html/resqapi/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.txt "mysql:host=localhost;dbname=resq;charset=UTF8" resq Motolite456 +/usr/bin/php /usr/share/nginx/html/resqapi/utils/get_warranty_serial/get_serials.php `date +%m-%d-%Y` +/usr/bin/php /usr/share/nginx/html/resqapi/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.txt "mysql:host=localhost;dbname=resq;charset=UTF8" From 3df1989f68db40df90ee9e3b9675a1225312d9d5 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 9 Jun 2021 08:16:27 +0000 Subject: [PATCH 7/8] Remove the database information as an argument. #576 --- utils/load_warranty_serial/load_serials.php | 24 ++++++++++++++++++--- utils/warranty_motiv_local.sh | 2 +- utils/warranty_motiv_local_bulk.sh | 2 +- utils/warranty_motiv_prod.sh | 2 +- utils/warranty_motiv_prod_bulk.sh | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index d5369aac..b0c3081e 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -4,10 +4,11 @@ require_once(__DIR__ . '/../../vendor/autoload.php'); use Symfony\Component\Dotenv\Dotenv; +// TODO: this whole thing needs to be refactored + // load csv $csv = fopen($argv[1], 'r'); -$dsn = $argv[2]; -$output_file = $argv[3]; +$output_file = $argv[2]; $output_fh = fopen($output_file, "w"); @@ -25,6 +26,24 @@ $dotenv->loadEnv(__DIR__.'/../../.env'); $user = $_ENV['DB_USER']; $pass = $_ENV['DB_PASSWORD']; +$db_info = $_ENV['DATABASE_URL']; + +// sample format of db_info: mysql://db_user:db_password@127.0.0.1:3306/resq +// dsn for PDO needs to be: mysql:host=127.0.0.1:3306;dbname=resq;charset=UTF8 + +$result = preg_split("/[\/:@]/", $db_info); +$db_type = 'mysql:host='; +$user = $result[3]; +$pass = $result[4]; +$ip_port = $result[5] . ':' . $result[6] . ';'; +$db_name = 'dbname=' . $result[7] . ';'; +$charset = 'charset=UTF8'; + +$dsn = $db_type . $ip_port . $db_name . $charset; + +//error_log($dsn); +//error_log($user); +//error_log($pass); // connect to db $db = new PDO($dsn, $user, $pass); @@ -157,4 +176,3 @@ while (($row = fgetcsv($csv)) !== false) fclose($csv); fclose($output_fh); - diff --git a/utils/warranty_motiv_local.sh b/utils/warranty_motiv_local.sh index ddfcd6f5..e99c7f64 100755 --- a/utils/warranty_motiv_local.sh +++ b/utils/warranty_motiv_local.sh @@ -6,4 +6,4 @@ load_status_file="/tmp/warranty_load_status_$proc_date.txt" echo $download_file echo $load_status_file /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=localhost;dbname=resq;charset=UTF8" $load_status_file +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file $load_status_file diff --git a/utils/warranty_motiv_local_bulk.sh b/utils/warranty_motiv_local_bulk.sh index 14a5e636..c4f2a551 100755 --- a/utils/warranty_motiv_local_bulk.sh +++ b/utils/warranty_motiv_local_bulk.sh @@ -37,4 +37,4 @@ touch /tmp/warranty_download_serial.csv /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv /tmp/warranty_load_status.txt diff --git a/utils/warranty_motiv_prod.sh b/utils/warranty_motiv_prod.sh index 798158ef..124f6e96 100755 --- a/utils/warranty_motiv_prod.sh +++ b/utils/warranty_motiv_prod.sh @@ -5,5 +5,5 @@ load_status_file="/tmp/warranty_load_status_$proc_date.txt" #echo $download_file #echo $load_status_file /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" $load_status_file +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file $load_status_file diff --git a/utils/warranty_motiv_prod_bulk.sh b/utils/warranty_motiv_prod_bulk.sh index 446e68f1..c4f2a551 100755 --- a/utils/warranty_motiv_prod_bulk.sh +++ b/utils/warranty_motiv_prod_bulk.sh @@ -37,4 +37,4 @@ touch /tmp/warranty_download_serial.csv /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv /tmp/warranty_load_status.txt From bd0b24b0344f1aa415b8407eacff386c651a8437 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 9 Jun 2021 08:46:18 +0000 Subject: [PATCH 8/8] Fix splitting of database info. #576 --- utils/load_warranty_serial/load_serials.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index b0c3081e..812b151c 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -24,19 +24,18 @@ if (!file_exists($argv[1])) $dotenv = new Dotenv(); $dotenv->loadEnv(__DIR__.'/../../.env'); -$user = $_ENV['DB_USER']; -$pass = $_ENV['DB_PASSWORD']; $db_info = $_ENV['DATABASE_URL']; // sample format of db_info: mysql://db_user:db_password@127.0.0.1:3306/resq // dsn for PDO needs to be: mysql:host=127.0.0.1:3306;dbname=resq;charset=UTF8 -$result = preg_split("/[\/:@]/", $db_info); +preg_match('/^mysql:\/\/(.*):(.*)@(.*):(.*)\/(.*)/', $db_info, $result); + $db_type = 'mysql:host='; -$user = $result[3]; -$pass = $result[4]; -$ip_port = $result[5] . ':' . $result[6] . ';'; -$db_name = 'dbname=' . $result[7] . ';'; +$user = $result[1]; +$pass = $result[2]; +$ip_port = $result[3] . ':' . $result[4] . ';'; +$db_name = 'dbname=' . $result[5] . ';'; $charset = 'charset=UTF8'; $dsn = $db_type . $ip_port . $db_name . $charset;