Remove the database information as an argument. #576

This commit is contained in:
Korina Cordero 2021-06-09 08:16:27 +00:00
parent 4b76e1e0d1
commit 3df1989f68
5 changed files with 25 additions and 7 deletions

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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