fixed filepath issue in import request script.
This commit is contained in:
+115
-100
@@ -16,8 +16,8 @@ class Process_ImportRequest {
|
||||
|
||||
// Variables
|
||||
|
||||
private $log = "";
|
||||
private $settings = "";
|
||||
private $log = "";
|
||||
private $settings = "";
|
||||
private $connection = "";
|
||||
|
||||
// ==================
|
||||
@@ -27,7 +27,7 @@ class Process_ImportRequest {
|
||||
public function __construct() {
|
||||
|
||||
$basePath = realpath(__DIR__ . '/..');
|
||||
$logfile = $basePath . "/scripts/importrequests.log";
|
||||
$logfile = $basePath . "/scripts/importrequests.log";
|
||||
|
||||
// ==========================
|
||||
// Log Rotation (50 MB limit)
|
||||
@@ -80,9 +80,9 @@ class Process_ImportRequest {
|
||||
|
||||
try {
|
||||
|
||||
$database = (string) $this->settings->DatabaseName;
|
||||
$user = (string) $this->settings->DatabaseUser;
|
||||
$password = (string) $this->settings->DatabasePassword;
|
||||
$database = (string) $this->settings->DatabaseName;
|
||||
$user = (string) $this->settings->DatabaseUser;
|
||||
$password = (string) $this->settings->DatabasePassword;
|
||||
|
||||
$connection = new PDO("mysql:host={$host};dbname={$database};charset=utf8", $user, $password);
|
||||
|
||||
@@ -140,7 +140,7 @@ class Process_ImportRequest {
|
||||
|
||||
try {
|
||||
|
||||
$success = $this->parseCSVFile($importjob_file_path);
|
||||
$this->parseCSVFile($importjob_file_path);
|
||||
|
||||
$SQL = "UPDATE importjobs
|
||||
SET importjob_status = 'complete',
|
||||
@@ -150,6 +150,9 @@ class Process_ImportRequest {
|
||||
$update = $this->connect()->prepare($SQL);
|
||||
|
||||
$update->execute([':importjob_serial' => $importjob_serial]);
|
||||
|
||||
$this->sendWebHookAlert("Import Job completed successfully.");
|
||||
$this->email_admins("Import Job Success.", "Import Job completed successfully.");
|
||||
} catch (Throwable $e) {
|
||||
|
||||
$SQL = "UPDATE importjobs
|
||||
@@ -238,24 +241,29 @@ class Process_ImportRequest {
|
||||
|
||||
$filename = $files['importjob_file_path'];
|
||||
|
||||
unlink($filename);
|
||||
if (is_file($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
|
||||
$baseDir = './imports';
|
||||
$baseDir = "./uploads/Production/";
|
||||
|
||||
foreach (new DirectoryIterator($baseDir) as $item) {
|
||||
if (!is_dir($baseDir)) {
|
||||
$this->log("Imports directory does not exist: {$baseDir}");
|
||||
} else {
|
||||
foreach (new DirectoryIterator($baseDir) as $item) {
|
||||
if ($item->isDot() || !$item->isDir()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item->isDot() || !$item->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$folderPath = $item->getPathname();
|
||||
|
||||
$folderPath = $item->getPathname();
|
||||
// Check if directory is empty
|
||||
$files = scandir($folderPath);
|
||||
|
||||
// Check if directory is empty
|
||||
$files = scandir($folderPath);
|
||||
|
||||
if ($files !== false && count($files) === 2) {
|
||||
rmdir($folderPath);
|
||||
if ($files !== false && count($files) === 2) {
|
||||
rmdir($folderPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,42 +299,51 @@ class Process_ImportRequest {
|
||||
|
||||
$csvfile = fopen($file, 'r');
|
||||
|
||||
if ($csvfile === false) {
|
||||
throw new RuntimeException("Unable to open CSV file: {$file}");
|
||||
}
|
||||
|
||||
$RecordCount = 0;
|
||||
|
||||
while (($data = fgetcsv($csvfile, 0, ",", '"', '\\')) !== FALSE) {
|
||||
|
||||
$PermitFactsId = $data[1];
|
||||
$EntryDate = $this->fixDate($data[2]);
|
||||
$PermitNumber = $data[4];
|
||||
$PermitDate = $this->fixDate($data[5]);
|
||||
$ProjectAddress = $data[7];
|
||||
$SubdivisionName = $data[8];
|
||||
$ProjectType = $data[9];
|
||||
$Company = substr($data[10], 0, 30);
|
||||
$Address = substr($data[11], 0, 30);
|
||||
$City = $data[12];
|
||||
$State = $data[13];
|
||||
$Zip = $data[14];
|
||||
$Phone = $data[15];
|
||||
$ProjectCity = $data[16];
|
||||
$ProjectState = $data[17];
|
||||
$Size = $data[18] ?: 0;
|
||||
$Units = $data[19];
|
||||
$BuildingType = $data[20];
|
||||
$Value = $data[21] ?: 0;
|
||||
$WorkType = $data[22];
|
||||
$County = $data[23] ?: 0;
|
||||
$Lot = $data[24];
|
||||
$DistrictLL = $data[25];
|
||||
$Ctl = $data[26];
|
||||
$OwnerName = substr($data[27], 0, 30);
|
||||
$OwnerAddress = substr($data[28], 0, 30);
|
||||
$OwnerCity = $data[29];
|
||||
$OwnerState = substr($data[30], 0, 2);
|
||||
$OwnerZip = $data[31];
|
||||
$OwnerPhone = $data[32];
|
||||
$YTDPermits = $data[33] ?: 0;
|
||||
$YTDValue = $data[34] ?: 0;
|
||||
if (count($data) < 36) {
|
||||
$this->log("Skipping malformed CSV row with " . count($data) . " columns.");
|
||||
continue;
|
||||
}
|
||||
|
||||
$PermitFactsId = $data[1];
|
||||
$EntryDate = $this->fixDate($data[2]);
|
||||
$PermitNumber = $data[4];
|
||||
$PermitDate = $this->fixDate($data[5]);
|
||||
$ProjectAddress = $data[7];
|
||||
$SubdivisionName = $data[8];
|
||||
$ProjectType = $data[9];
|
||||
$Company = substr($data[10], 0, 30);
|
||||
$Address = substr($data[11], 0, 30);
|
||||
$City = $data[12];
|
||||
$State = $data[13];
|
||||
$Zip = $data[14];
|
||||
$Phone = $data[15];
|
||||
$ProjectCity = $data[16];
|
||||
$ProjectState = $data[17];
|
||||
$Size = $data[18] ?: 0;
|
||||
$Units = $data[19];
|
||||
$BuildingType = $data[20];
|
||||
$Value = $data[21] ?: 0;
|
||||
$WorkType = $data[22];
|
||||
$County = $data[23] ?: 0;
|
||||
$Lot = $data[24];
|
||||
$DistrictLL = $data[25];
|
||||
$Ctl = $data[26];
|
||||
$OwnerName = substr($data[27], 0, 30);
|
||||
$OwnerAddress = substr($data[28], 0, 30);
|
||||
$OwnerCity = $data[29];
|
||||
$OwnerState = substr($data[30], 0, 2);
|
||||
$OwnerZip = $data[31];
|
||||
$OwnerPhone = $data[32];
|
||||
$YTDPermits = $data[33] ?: 0;
|
||||
$YTDValue = $data[34] ?: 0;
|
||||
$TwelveMonthPreviousPermits = $data[35] ?: 0;
|
||||
|
||||
$County = $this->getCountiesByName($County)['county_serial'] ?? 0;
|
||||
@@ -403,38 +420,38 @@ class Process_ImportRequest {
|
||||
|
||||
$statement = $this->connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":permit_permit_facts_id", $PermitFactsId);
|
||||
$statement->bindValue(":permit_permit_number", $PermitNumber);
|
||||
$statement->bindValue(":permit_entry_date", $EntryDate);
|
||||
$statement->bindValue(":permit_permit_date", $PermitDate);
|
||||
$statement->bindValue(":permit_project_addr", $ProjectAddress);
|
||||
$statement->bindValue(":permit_sub_div_name", $SubdivisionName);
|
||||
$statement->bindValue(":permit_project_type", $ProjectType);
|
||||
$statement->bindValue(":permit_company", $Company);
|
||||
$statement->bindValue(":permit_address", $Address);
|
||||
$statement->bindValue(":permit_city", $City);
|
||||
$statement->bindValue(":permit_state", $State);
|
||||
$statement->bindValue(":permit_zip", $Zip);
|
||||
$statement->bindValue(":permit_phone", $Phone);
|
||||
$statement->bindValue(":permit_project_city", $ProjectCity);
|
||||
$statement->bindValue(":permit_project_state", $ProjectState);
|
||||
$statement->bindValue(":permit_size", $Size);
|
||||
$statement->bindValue(":permit_units", $Units);
|
||||
$statement->bindValue(":permit_building_type", $BuildingType);
|
||||
$statement->bindValue(":permit_value", $Value);
|
||||
$statement->bindValue(":permit_work_type", $WorkType);
|
||||
$statement->bindValue(":permit_county", $County);
|
||||
$statement->bindValue(":permit_lot", $Lot);
|
||||
$statement->bindValue(":permit_dist_ll", $DistrictLL);
|
||||
$statement->bindValue(":permit_ct1", $Ctl);
|
||||
$statement->bindValue(":permit_owner_name", $OwnerName);
|
||||
$statement->bindValue(":permit_owner_address", $OwnerAddress);
|
||||
$statement->bindValue(":permit_owner_city", $OwnerCity);
|
||||
$statement->bindValue(":permit_owner_state", $OwnerState);
|
||||
$statement->bindValue(":permit_owner_zip", $OwnerZip);
|
||||
$statement->bindValue(":permit_owner_phone", $OwnerPhone);
|
||||
$statement->bindValue(":permit_ytd_permits", $YTDPermits);
|
||||
$statement->bindValue(":permit_ytd_value", $YTDValue);
|
||||
$statement->bindValue(":permit_permit_facts_id", $PermitFactsId);
|
||||
$statement->bindValue(":permit_permit_number", $PermitNumber);
|
||||
$statement->bindValue(":permit_entry_date", $EntryDate);
|
||||
$statement->bindValue(":permit_permit_date", $PermitDate);
|
||||
$statement->bindValue(":permit_project_addr", $ProjectAddress);
|
||||
$statement->bindValue(":permit_sub_div_name", $SubdivisionName);
|
||||
$statement->bindValue(":permit_project_type", $ProjectType);
|
||||
$statement->bindValue(":permit_company", $Company);
|
||||
$statement->bindValue(":permit_address", $Address);
|
||||
$statement->bindValue(":permit_city", $City);
|
||||
$statement->bindValue(":permit_state", $State);
|
||||
$statement->bindValue(":permit_zip", $Zip);
|
||||
$statement->bindValue(":permit_phone", $Phone);
|
||||
$statement->bindValue(":permit_project_city", $ProjectCity);
|
||||
$statement->bindValue(":permit_project_state", $ProjectState);
|
||||
$statement->bindValue(":permit_size", $Size);
|
||||
$statement->bindValue(":permit_units", $Units);
|
||||
$statement->bindValue(":permit_building_type", $BuildingType);
|
||||
$statement->bindValue(":permit_value", $Value);
|
||||
$statement->bindValue(":permit_work_type", $WorkType);
|
||||
$statement->bindValue(":permit_county", $County);
|
||||
$statement->bindValue(":permit_lot", $Lot);
|
||||
$statement->bindValue(":permit_dist_ll", $DistrictLL);
|
||||
$statement->bindValue(":permit_ct1", $Ctl);
|
||||
$statement->bindValue(":permit_owner_name", $OwnerName);
|
||||
$statement->bindValue(":permit_owner_address", $OwnerAddress);
|
||||
$statement->bindValue(":permit_owner_city", $OwnerCity);
|
||||
$statement->bindValue(":permit_owner_state", $OwnerState);
|
||||
$statement->bindValue(":permit_owner_zip", $OwnerZip);
|
||||
$statement->bindValue(":permit_owner_phone", $OwnerPhone);
|
||||
$statement->bindValue(":permit_ytd_permits", $YTDPermits);
|
||||
$statement->bindValue(":permit_ytd_value", $YTDValue);
|
||||
$statement->bindValue(":permit_12mth_prev_permits", $TwelveMonthPreviousPermits);
|
||||
|
||||
$statement->execute();
|
||||
@@ -453,11 +470,11 @@ class Process_ImportRequest {
|
||||
|
||||
$SQL = "select view_counties.*
|
||||
from view_counties
|
||||
where view_counties.county_name = '{$county_name}'";
|
||||
where view_counties.county_name = :county_name";
|
||||
|
||||
$statement = $this->connection->prepare($SQL);
|
||||
|
||||
$statement->execute();
|
||||
$statement->execute([':county_name' => $county_name]);
|
||||
|
||||
$county_name = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
@@ -468,7 +485,7 @@ class Process_ImportRequest {
|
||||
// Send an Alert/Notification
|
||||
// ==========================
|
||||
|
||||
public function sendWebHookAlert($message, $title = "🚨 DEC Application Alert", $alerttype = "1fff00") {
|
||||
public function sendWebHookAlert($message, $title = "DEC Application Alert", $alerttype = "1fff00") {
|
||||
|
||||
$webhookUrl = (string) $this->settings->DiscordWebHookURL;
|
||||
|
||||
@@ -512,40 +529,41 @@ class Process_ImportRequest {
|
||||
|
||||
$settings = new SimpleXMLElement((file_exists("./xml/settings.xml") ? file_get_contents("./xml/settings.xml") : "<settings/>"));
|
||||
|
||||
print_r($settings);
|
||||
die();
|
||||
|
||||
// Server Variables
|
||||
$host = (string) $settings->SmtpServer;
|
||||
$host = (string) $settings->SmtpServer;
|
||||
$username = (string) $settings->SmtpUserName;
|
||||
$password = (string) $settings->SmtpPassword;
|
||||
|
||||
// Recipient Variables
|
||||
$from_email = (string) $settings->FromEmail;
|
||||
$from_name = (string) $settings->FromName;
|
||||
$from_name = (string) $settings->FromName;
|
||||
|
||||
$support_email = (string) $settings->SupportEmail;
|
||||
$support_name = (string) $settings->SupportName;
|
||||
$support_name = (string) $settings->SupportName;
|
||||
|
||||
if ((string) $settings->Environment == 'Production') {
|
||||
|
||||
$admin_email = (string) $settings->AdminEmail;
|
||||
$admin_name = (string) $settings->AdminName;
|
||||
$admin_name = (string) $settings->AdminName;
|
||||
}
|
||||
|
||||
// Content Variables
|
||||
|
||||
$attachment_name = "";
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
|
||||
//Server settings
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $host;
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $username;
|
||||
$mail->Password = $password;
|
||||
$mail->Host = $host;
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $username;
|
||||
$mail->Password = $password;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||
$mail->Port = 465;
|
||||
$mail->Port = 465;
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom($from_email, $from_name);
|
||||
@@ -555,9 +573,6 @@ class Process_ImportRequest {
|
||||
$mail->addAddress($admin_email, $admin_name);
|
||||
}
|
||||
|
||||
//Attachments
|
||||
$mail->addAttachment($attachment_name);
|
||||
|
||||
//Content
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $subject;
|
||||
|
||||
Reference in New Issue
Block a user