Various Issues have been resolved in this commit.

This commit is contained in:
2026-06-13 11:13:36 -04:00
parent 4d030d87e5
commit 68403097c2
19 changed files with 385 additions and 486 deletions
@@ -0,0 +1,324 @@
<?php
// ======================
// Migrate Business Facts
// ======================
class Migrate_BusinessFacts {
// Variables
private $log = "";
private $settings = "";
private $olddb_connection = "";
private $newdb_connection = "";
// ==================
// Class Constructor.
// ==================
public function __construct() {
// Open the Log
$this->log = fopen("../scripts/businessfacts.log", "w+");
if ($this->log === false) {
error_log("Business Facts : Unable to open log file");
exit();
}
$this->log(str_repeat("*", 50));
// Get Settings
$this->settings = new SimpleXMLElement((file_exists("../xml/settings.xml") ? file_get_contents("../xml/settings.xml") : "<settings/>"));
if ($this->settings->count() === 0) {
error_log("Business Facts : Unable to initialize settings");
exit();
}
// Open Database Connections
$this->olddb_connection = $this->connect_olddb();
$this->newdb_connection = $this->connect_newdb();
}
// ================================================
// Return a Old DEC-DR Database Database Connection
// ================================================
public function connect_olddb() {
try {
$host = (string) $this->settings->OldDatabaseServer;
$database = (string) $this->settings->OldDatabaseName;
$user = (string) $this->settings->OldDatabaseUser;
$password = (string) $this->settings->OldDatabasePassword;
$connection = new PDO("mysql:host={$host};dbname={$database};charset=utf8", $user, $password);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
trigger_error($e->getMessage());
}
return $connection;
}
// ================================================
// Return a New DEC-DR Database Database Connection
// ================================================
public function connect_newdb() {
try {
$host = (string) $this->settings->DatabaseServer;
$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);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
trigger_error($e->getMessage());
}
return $connection;
}
// =============================
// Log a message to the Log File
// =============================
private function log($message = "") {
fwrite($this->log, date("Y-m-d H:i A") . " : " . "{$message} \n");
}
// ===================
// Process Parcel Data
// ===================
public function process() {
$this->log("Starting Migration of Business Facts");
$this->migrateBusinessFacts();
$this->log("Business Facts Migration Process Complete");
}
// ====================
// Migrate Business Facts
// ====================
private function migrateBusinessFacts() {
$this->log("Processing Business Facts");
$businessfacts = $this->getBusinessFacts();
$SQL = "INSERT INTO businessfacts (
businessfact_legacy_id,
businessfact_company,
businessfact_address_one,
businessfact_address_two,
businessfact_city,
businessfact_state,
businessfact_zip,
businessfact_county,
businessfact_phone,
businessfact_fax,
businessfact_email_address,
businessfact_business_class,
businessfact_action,
businessfact_employee_count,
businessfact_inception,
businessfact_sic_code,
businessfact_contact_name,
businessfact_contact_title,
businessfact_license_date,
businessfact_home_based_business,
businessfact_year_established,
businessfact_entry_date,
businessfact_creator,
businessfact_created )
VALUES ( :businessfact_legacy_id,
:businessfact_company,
:businessfact_address_one,
:businessfact_address_two,
:businessfact_city,
:businessfact_state,
:businessfact_zip,
:businessfact_county,
:businessfact_phone,
:businessfact_fax,
:businessfact_email_address,
:businessfact_business_class,
:businessfact_action,
:businessfact_employee_count,
:businessfact_inception,
:businessfact_sic_code,
:businessfact_contact_name,
:businessfact_contact_title,
:businessfact_license_date,
:businessfact_home_based_business,
:businessfact_year_established,
:businessfact_entry_date,
:businessfact_creator,
:businessfact_created )";
$statement = $this->newdb_connection->prepare($SQL);
$counter = 0;
foreach ($businessfacts as $businessfact) {
$businessfact_legacy_id = $businessfact['BizFactsRecordID'] ?? null;
$businessfact_company = $businessfact['Company'] ?? null;
$businessfact_address_one = $businessfact['Address1'] ?? null;
$businessfact_address_two = $businessfact['Address2'] ?? null;
$businessfact_city = $this->getCityByCityName($businessfact['City']) ?? null;
$businessfact_state = $businessfact['State'] ?? null;
$businessfact_zip = $businessfact['Zip'] ?? null;
$businessfact_county = $this->getCountyByCountyName($businessfact['County']) ?? null;
$businessfact_phone = $this->normailizePhoneNumber($businessfact['Phone']) ?? null;
$businessfact_fax = $this->normailizePhoneNumber($businessfact['Fax']) ?? null;
$businessfact_email_address = $this->normailizeEmailAddress($businessfact['EmailAddress']) ?? null;
$businessfact_business_class = $this->getDropdownSerialByValue($businessfact['BC']) ?? null;
$businessfact_action = $this->getDropdownSerialByValue($businessfact['Description']) ?? null;
$businessfact_employee_count = $businessfact['ES'] ?? null;
$businessfact_inception = $businessfact['BizInception'] ?? null;
$businessfact_sic_code = $businessfact['SIC'] ?? null;
$businessfact_contact_name = $businessfact['ContactName'] ?? null;
$businessfact_contact_title = $businessfact['Title'] ?? null;
$businessfact_license_date = $businessfact['LicenseDate'] ?? null;
$businessfact_home_based_business = $businessfact['Home'] ?? null;
$businessfact_year_established = $businessfact['YearEst'] ?? null;
$businessfact_entry_date = $businessfact['EntryDate'] ?? null;
$statement->bindValue(':businessfact_legacy_id', $businessfact_legacy_id, PDO::PARAM_INT);
$statement->bindValue(':businessfact_company', $businessfact_company, PDO::PARAM_STR);
$statement->bindValue(':businessfact_address_one', $businessfact_address_one, PDO::PARAM_STR);
$statement->bindValue(':businessfact_address_two', $businessfact_address_two, PDO::PARAM_STR);
$statement->bindValue(':businessfact_city', $businessfact_city, PDO::PARAM_INT);
$statement->bindValue(':businessfact_state', $businessfact_state, PDO::PARAM_STR);
$statement->bindValue(':businessfact_zip', $businessfact_zip, PDO::PARAM_STR);
$statement->bindValue(':businessfact_county', $businessfact_county, PDO::PARAM_INT);
$statement->bindValue(':businessfact_phone', $businessfact_phone, PDO::PARAM_STR);
$statement->bindValue(':businessfact_fax', $businessfact_fax, PDO::PARAM_STR);
$statement->bindValue(':businessfact_email_address', $businessfact_email_address, PDO::PARAM_STR);
$statement->bindValue(':businessfact_business_class', $businessfact_business_class, PDO::PARAM_INT);
$statement->bindValue(':businessfact_action', $businessfact_action, PDO::PARAM_INT);
$statement->bindValue(':businessfact_employee_count', $businessfact_employee_count, PDO::PARAM_STR);
$statement->bindValue(':businessfact_inception', $businessfact_inception, PDO::PARAM_STR);
$statement->bindValue(':businessfact_sic_code', $businessfact_sic_code, PDO::PARAM_STR);
$statement->bindValue(':businessfact_contact_name', $businessfact_contact_name, PDO::PARAM_STR);
$statement->bindValue(':businessfact_contact_title', $businessfact_contact_title, PDO::PARAM_STR);
$statement->bindValue(':businessfact_license_date', $businessfact_license_date, PDO::PARAM_STR);
$statement->bindValue(':businessfact_home_based_business', $businessfact_home_based_business, PDO::PARAM_INT);
$statement->bindValue(':businessfact_year_established', $businessfact_year_established, PDO::PARAM_STR);
$statement->bindValue(':businessfact_entry_date', $businessfact_entry_date, PDO::PARAM_STR);
$statement->bindValue(':businessfact_creator', 'Migration', PDO::PARAM_STR);
$statement->bindValue(':businessfact_created', date("Y-m-d"), PDO::PARAM_STR);
$statement->execute();
$counter++;
// Issue an update message every 1000 records
if (($counter % 1000) == 0) {
$this->log("Processed $counter records... " . PHP_EOL);
echo "Processed $counter records... " . PHP_EOL;
}
}
}
// ======================
// Normalize Phone Number
// ======================
private function normailizePhoneNumber($phonenumber) {
return preg_replace('/\D+/', '', $phonenumber); // \D = non-digit
}
// ======================
// Normalize Phone Number
// ======================
function normailizeEmailAddress(string $email): string {
// Split at the first #
$clean = explode('#', $email, 2)[0];
// Normalize case
return strtolower(trim($clean));
}
// ============================
// Return a Business Facts Object
// ============================
private function getBusinessFacts() {
$SQL = "select * from BizFacts_tbl";
$businessfacts = $this->connect_olddb()->query($SQL)->fetchAll(PDO::FETCH_ASSOC);
return $businessfacts;
}
// =================================
// Return a Business Facts Dues Object
// =================================
private function getDropdownSerialByValue($description) {
$SQL = "select dropdown_serial from dropdowns where dropdown_value = '{$description}'";
$dropdown_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['dropdown_serial'] ?? null;
return $dropdown_serial;
}
// ============================
// Return a Business Facts County
// ============================
private function getCountyByCountyName($county_name) {
$SQL = "select county_serial from counties where county_name = '{$county_name}'";
$county_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['county_serial'] ?? null;
return $county_serial;
}
// ============================
// Return a Business Facts City
// ============================
private function getCityByCityName($city_name) {
$SQL = "select city_serial from cities where city_name = '{$city_name}'";
$city_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['city_serial'] ?? null;
return $city_serial;
}
}
?>
+373
View File
@@ -0,0 +1,373 @@
<?php
// ================
// Migrate PZ Facts
// ================
class Migrate_PZFacts {
// Variables
private $log = "";
private $settings = "";
private $olddb_connection = "";
private $newdb_connection = "";
// ==================
// Class Constructor.
// ==================
public function __construct() {
// Open the Log
$this->log = fopen("../scripts/pzfacts.log", "w+");
if ($this->log === false) {
error_log("PZ Facts : Unable to open log file");
exit();
}
$this->log(str_repeat("*", 50));
// Get Settings
$this->settings = new SimpleXMLElement((file_exists("../xml/settings.xml") ? file_get_contents("../xml/settings.xml") : "<settings/>"));
if ($this->settings->count() === 0) {
error_log("PZ Facts : Unable to initialize settings");
exit();
}
// Open Database Connections
$this->olddb_connection = $this->connect_olddb();
$this->newdb_connection = $this->connect_newdb();
}
// ================================================
// Return a Old DEC-DR Database Database Connection
// ================================================
public function connect_olddb() {
try {
$host = (string) $this->settings->OldDatabaseServer;
$database = (string) $this->settings->OldDatabaseName;
$user = (string) $this->settings->OldDatabaseUser;
$password = (string) $this->settings->OldDatabasePassword;
$connection = new PDO("mysql:host={$host};dbname={$database};charset=utf8", $user, $password);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
trigger_error($e->getMessage());
}
return $connection;
}
// ================================================
// Return a New DEC-DR Database Database Connection
// ================================================
public function connect_newdb() {
try {
$host = (string) $this->settings->DatabaseServer;
$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);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
trigger_error($e->getMessage());
}
return $connection;
}
// =============================
// Log a message to the Log File
// =============================
private function log($message = "") {
fwrite($this->log, date("Y-m-d H:i A") . " : " . "{$message} \n");
}
// ===================
// Process Parcel Data
// ===================
public function process() {
$this->log("Starting Migration of Planning/Zoning Facts");
$this->migratePZFacts();
$this->log("Planning/Zoning Facts Migration Process Complete");
}
// ====================
// Migrate PZ Facts
// ====================
private function migratePZFacts() {
$this->log("Processing PZ Facts");
$pzfacts = $this->getPZFacts();
$SQL = "INSERT INTO pzfacts (
pzfact_legacy_id,
pzfact_entry_date,
pzfact_county,
pzfact_professional_name,
pzfact_professional_address,
pzfact_professional_state,
pzfact_professional_phone,
pzfact_professional_fax,
pzfact_owner_name,
pzfact_owner_address,
pzfact_owner_state,
pzfact_owner_phone,
pzfact_owner_fax,
pzfact_project_name,
pzfact_project_type,
pzfact_project_description,
pzfact_project_address,
pzfact_project_city,
pzfact_action_code,
pzfact_district,
pzfact_land_lot,
pzfact_lot,
pzfact_block,
pzfact_parcel_number,
pzfact_action_date,
pzfact_acres,
pzfact_status,
pzfact_dollar_value,
pzfact_estimated_ground_break,
pzfact_in_city_limit,
pzfact_creator,
pzfact_created )
VALUES ( :pzfact_legacy_id,
:pzfact_entry_date,
:pzfact_county,
:pzfact_professional_name,
:pzfact_professional_address,
:pzfact_professional_state,
:pzfact_professional_phone,
:pzfact_professional_fax,
:pzfact_owner_name,
:pzfact_owner_address,
:pzfact_owner_state,
:pzfact_owner_phone,
:pzfact_owner_fax,
:pzfact_project_name,
:pzfact_project_type,
:pzfact_project_description,
:pzfact_project_address,
:pzfact_project_city,
:pzfact_action_code,
:pzfact_district,
:pzfact_land_lot,
:pzfact_lot,
:pzfact_block,
:pzfact_parcel_number,
:pzfact_action_date,
:pzfact_acres,
:pzfact_status,
:pzfact_dollar_value,
:pzfact_estimated_ground_break,
:pzfact_in_city_limit,
:pzfact_creator,
:pzfact_created )";
$statement = $this->newdb_connection->prepare($SQL);
$counter = 0;
foreach ($pzfacts as $pzfact) {
$pzfact_legacy_id = $pzfact['PZ_ID'] ?? null;
$pzfact_entry_date = $pzfact['EntryDate'] ?? null;
$pzfact_county = $this->getCountyByCountyName($pzfact['County']) ?? null;
/* Professional */
$pzfact_professional_name = $pzfact['ProfessionalName'] ?? null;
$pzfact_professional_address = $pzfact['ProfessionalAddress'] ?? null;
$pzfact_professional_state = $pzfact['ProfessionalState'] ?? null;
$pzfact_professional_phone = $this->normailizePhoneNumber($pzfact['ProfessionalPhone']) ?? null;
$pzfact_professional_fax = $this->normailizePhoneNumber($pzfact['ProfessionalFax']) ?? null;
/* Owner */
$pzfact_owner_name = $pzfact['OwnerName'] ?? null;
$pzfact_owner_address = $pzfact['OwnerAddress'] ?? null;
$pzfact_owner_state = $pzfact['OwnerState'] ?? null;
$pzfact_owner_phone = $this->normailizePhoneNumber($pzfact['OwnerPhone']) ?? null;
$pzfact_owner_fax = $this->normailizePhoneNumber($pzfact['OwnerFax']) ?? null;
/* Project */
$pzfact_project_name = $pzfact['ProjectName'] ?? null;
$pzfact_project_type = $this->getDropdownSerialByValue($pzfact['ProjectType']) ?? null;
$pzfact_project_description = $pzfact['ProjectDescription'] ?? null;
$pzfact_project_address = $pzfact['ProjectAddress'] ?? null;
$pzfact_project_city = $this->getCityByCityName($pzfact['ProjectCity']) ?? null;
/* Zoning / action */
$pzfact_action_code = $this->getDropdownSerialByValue($pzfact['ActionCode']) ?? null;
$pzfact_district = $pzfact['District'] ?? null;
/* Parcel */
$pzfact_land_lot = $pzfact['LL'] ?? null;
$pzfact_lot = $pzfact['Lot'] ?? null;
$pzfact_block = $pzfact['Block'] ?? null;
$pzfact_parcel_number = $pzfact['Parcel'] ?? null;
/* Dates / values */
$pzfact_action_date = $pzfact['ActionDate'] ?? null;
$pzfact_acres = $pzfact['Acres'] ?? null;
$pzfact_status = $pzfact['Status'] ?? null;
$pzfact_dollar_value = $pzfact['DollarValueID'] ?? null;
$pzfact_estimated_ground_break = $pzfact['Est_Ground_Breaking'] ?? null;
/* Flags */
$pzfact_in_city_limit = isset($pzfact['City']) ? (int) $pzfact['City'] : 0;
/* Audit */
$pzfact_creator = 'Migration';
$pzfact_created = date('Y-m-d H:i:s');
$statement->bindValue(':pzfact_legacy_id', $pzfact_legacy_id, PDO::PARAM_INT);
$statement->bindValue(':pzfact_entry_date', $pzfact_entry_date, PDO::PARAM_STR);
$statement->bindValue(':pzfact_county', $pzfact_county, PDO::PARAM_INT);
$statement->bindValue(':pzfact_professional_name', $pzfact_professional_name, PDO::PARAM_STR);
$statement->bindValue(':pzfact_professional_address', $pzfact_professional_address, PDO::PARAM_STR);
$statement->bindValue(':pzfact_professional_state', $pzfact_professional_state, PDO::PARAM_STR);
$statement->bindValue(':pzfact_professional_phone', $pzfact_professional_phone, PDO::PARAM_STR);
$statement->bindValue(':pzfact_professional_fax', $pzfact_professional_fax, PDO::PARAM_STR);
$statement->bindValue(':pzfact_owner_name', $pzfact_owner_name, PDO::PARAM_STR);
$statement->bindValue(':pzfact_owner_address', $pzfact_owner_address, PDO::PARAM_STR);
$statement->bindValue(':pzfact_owner_state', $pzfact_owner_state, PDO::PARAM_STR);
$statement->bindValue(':pzfact_owner_phone', $pzfact_owner_phone, PDO::PARAM_STR);
$statement->bindValue(':pzfact_owner_fax', $pzfact_owner_fax, PDO::PARAM_STR);
$statement->bindValue(':pzfact_project_name', $pzfact_project_name, PDO::PARAM_STR);
$statement->bindValue(':pzfact_project_type', $pzfact_project_type, PDO::PARAM_INT);
$statement->bindValue(':pzfact_project_description', $pzfact_project_description, PDO::PARAM_STR);
$statement->bindValue(':pzfact_project_address', $pzfact_project_address, PDO::PARAM_STR);
$statement->bindValue(':pzfact_project_city', $pzfact_project_city, PDO::PARAM_INT);
$statement->bindValue(':pzfact_action_code', $pzfact_action_code, PDO::PARAM_INT);
$statement->bindValue(':pzfact_district', $pzfact_district, PDO::PARAM_INT);
$statement->bindValue(':pzfact_land_lot', $pzfact_land_lot, PDO::PARAM_STR);
$statement->bindValue(':pzfact_lot', $pzfact_lot, PDO::PARAM_STR);
$statement->bindValue(':pzfact_block', $pzfact_block, PDO::PARAM_STR);
$statement->bindValue(':pzfact_parcel_number', $pzfact_parcel_number, PDO::PARAM_STR);
$statement->bindValue(':pzfact_action_date', $pzfact_action_date, PDO::PARAM_STR);
$statement->bindValue(':pzfact_acres', $pzfact_acres, PDO::PARAM_STR);
$statement->bindValue(':pzfact_status', $pzfact_status, PDO::PARAM_STR);
$statement->bindValue(':pzfact_dollar_value', $pzfact_dollar_value, PDO::PARAM_STR);
$statement->bindValue(':pzfact_estimated_ground_break', $pzfact_estimated_ground_break, PDO::PARAM_STR);
$statement->bindValue(':pzfact_in_city_limit', $pzfact_in_city_limit, PDO::PARAM_INT);
$statement->bindValue(':pzfact_creator', $pzfact_creator, PDO::PARAM_STR);
$statement->bindValue(':pzfact_created', $pzfact_created, PDO::PARAM_STR);
$statement->execute();
$counter++;
// Issue an update message every 100 records
if (($counter % 100) == 0) {
$this->log("Processed $counter records... " . PHP_EOL);
echo "Processed $counter records... " . PHP_EOL;
}
}
}
// ======================
// Normalize Phone Number
// ======================
private function normailizePhoneNumber($phonenumber) {
return preg_replace('/\D+/', '', $phonenumber); // \D = non-digit
}
// ========================
// Return a PZ Facts Object
// ========================
private function getPZFacts() {
$SQL = "select * from PZ_tbl";
$pzfacts = $this->connect_olddb()->query($SQL)->fetchAll(PDO::FETCH_ASSOC);
return $pzfacts;
}
// =================
// Return a PZ Facts
// =================
private function getDropdownSerialByValue($description) {
$SQL = "select dropdown_serial from dropdowns where dropdown_value = '{$description}'";
$dropdown_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['dropdown_serial'] ?? null;
return $dropdown_serial;
}
// ============================
// Return a PZ Facts County
// ============================
private function getCountyByCountyName($county_name) {
$SQL = "select county_serial from counties where county_name = '{$county_name}'";
$county_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['county_serial'] ?? null;
return $county_serial;
}
// ============================
// Return a PZ Facts City
// ============================
private function getCityByCityName($city_name) {
$SQL = "select city_serial from cities where city_name = '{$city_name}'";
$city_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['city_serial'] ?? null;
return $city_serial;
}
}
?>
+341
View File
@@ -0,0 +1,341 @@
<?php
// ====================
// Migrate Permit Facts
// ====================
class Migrate_PermitFacts {
// Variables
private $log = "";
private $settings = "";
private $olddb_connection = "";
private $newdb_connection = "";
// ==================
// Class Constructor.
// ==================
public function __construct() {
// Open the Log
$this->log = fopen("../scripts/permitfacts.log", "w+");
if ($this->log === false) {
error_log("Permit Facts : Unable to open log file");
exit();
}
$this->log(str_repeat("*", 50));
// Get Settings
$this->settings = new SimpleXMLElement((file_exists("../xml/settings.xml") ? file_get_contents("../xml/settings.xml") : "<settings/>"));
if ($this->settings->count() === 0) {
error_log("Permit Facts : Unable to initialize settings");
exit();
}
// Open Database Connections
$this->olddb_connection = $this->connect_olddb();
$this->newdb_connection = $this->connect_newdb();
}
// ================================================
// Return a Old DEC-DR Database Database Connection
// ================================================
public function connect_olddb() {
try {
$host = (string) $this->settings->OldDatabaseServer;
$database = (string) $this->settings->OldDatabaseName;
$user = (string) $this->settings->OldDatabaseUser;
$password = (string) $this->settings->OldDatabasePassword;
$connection = new PDO("mysql:host={$host};dbname={$database};charset=utf8", $user, $password);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
trigger_error($e->getMessage());
}
return $connection;
}
// ================================================
// Return a New DEC-DR Database Database Connection
// ================================================
public function connect_newdb() {
try {
$host = (string) $this->settings->DatabaseServer;
$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);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
trigger_error($e->getMessage());
}
return $connection;
}
// =============================
// Log a message to the Log File
// =============================
private function log($message = "") {
fwrite($this->log, date("Y-m-d H:i A") . " : " . "{$message} \n");
}
// ===================
// Process Parcel Data
// ===================
public function process() {
$this->log("Starting Migration of Permit Facts");
$this->migratePermitFacts();
$this->log("Permit Facts Migration Process Complete");
}
// ====================
// Migrate Permit Facts
// ====================
private function migratePermitFacts() {
$this->log("Processing Permit Facts");
$permitfacts = $this->getPermitFacts();
$SQL = "INSERT INTO permitfacts (
permitfact_legacy_id,
permitfact_entry_date,
permitfact_permit_number,
permitfact_permit_date,
permitfact_county,
permitfact_project_address,
permitfact_project_name,
permitfact_project_type,
permitfact_project_city,
permitfact_project_state,
permitfact_project_zip,
permitfact_company,
permitfact_address,
permitfact_city,
permitfact_state,
permitfact_zip,
permitfact_phone,
permitfact_size,
permitfact_value,
permitfact_work_type,
permitfact_building_type,
permitfact_lot_block,
permitfact_dist_ll,
permitfact_owner_name,
permitfact_owner_address,
permitfact_owner_city,
permitfact_owner_state,
permitfact_owner_zip,
permitfact_owner_phone,
permitfact_creator,
permitfact_created )
VALUES (
:permitfact_legacy_id,
:permitfact_entry_date,
:permitfact_permit_number,
:permitfact_permit_date,
:permitfact_county,
:permitfact_project_address,
:permitfact_project_name,
:permitfact_project_type,
:permitfact_project_city,
:permitfact_project_state,
:permitfact_project_zip,
:permitfact_company,
:permitfact_address,
:permitfact_city,
:permitfact_state,
:permitfact_zip,
:permitfact_phone,
:permitfact_size,
:permitfact_value,
:permitfact_work_type,
:permitfact_building_type,
:permitfact_lot_block,
:permitfact_dist_ll,
:permitfact_owner_name,
:permitfact_owner_address,
:permitfact_owner_city,
:permitfact_owner_state,
:permitfact_owner_zip,
:permitfact_owner_phone,
:permitfact_creator,
:permitfact_created ) ";
$statement = $this->newdb_connection->prepare($SQL);
$counter = 0;
foreach ($permitfacts as $permitfact) {
$permitfact_legacy_id = $permitfact['PermitFactsID'] ?? null;
$permitfact_entry_date = $permitfact['EntryDate'] ?? null;
$permitfact_permit_number = $permitfact['PermitNum'] ?? null;
$permitfact_permit_date = $permitfact['PermitDate'] ?? null;
$permitfact_county = $this->getCountyByCountyName($permitfact['County']) ?? null;
$permitfact_project_address = $permitfact['ProjectAddr'] ?? null;
$permitfact_project_name = $permitfact['ProjectName'] ?? null;
$permitfact_project_type = $this->getDropdownSerialByValue($permitfact['ProjectType']) ?? null;
$permitfact_project_city = $this->getCityByCityName($permitfact['ProjectCity']) ?? null;
$permitfact_project_state = $permitfact['ProjectState'] ?? null;
$permitfact_project_zip = $permitfact['ProjectZip'] ?? null;
$permitfact_company = $permitfact['Company'] ?? null;
$permitfact_address = $permitfact['Address'] ?? null;
$permitfact_city = $this->getCityByCityName($permitfact['City']) ?? null;
$permitfact_state = $permitfact['State'] ?? null;
$permitfact_zip = $permitfact['Zip'] ?? null;
$permitfact_phone = $this->normailizePhoneNumber($permitfact['Phone']) ?? null;
$permitfact_size = $permitfact['Size'] ?? null;
$permitfact_value = $permitfact['Value'] ?? null;
$permitfact_work_type = $this->getDropdownSerialByValue($permitfact['WorkType']) ?? null;
$permitfact_building_type = $this->getDropdownSerialByValue($permitfact['BldgType']) ?? null;
$permitfact_lot_block = $permitfact['Lot_BLK'] ?? null;
$permitfact_dist_ll = $permitfact['Dist_LL'] ?? null;
$permitfact_owner_name = $permitfact['OwnerName'] ?? null;
$permitfact_owner_address = $permitfact['OwnerAddress'] ?? null;
$permitfact_owner_city = $this->getCityByCityName($permitfact['OwnerCity']) ?? null;
$permitfact_owner_state = $permitfact['OwnerState'] ?? null;
$permitfact_owner_zip = $permitfact['OwnerZip'] ?? null;
$permitfact_owner_phone = $this->normailizePhoneNumber($permitfact['OwnerPhone']) ?? null;
$statement->bindValue(':PermitFactsID', $permitfact_legacy_id, PDO::PARAM_STR);
$statement->bindValue(':permitfact_entry_date', $permitfact_entry_date, PDO::PARAM_STR);
$statement->bindValue(':permitfact_permit_number', $permitfact_permit_number, PDO::PARAM_STR);
$statement->bindValue(':permitfact_permit_date', $permitfact_permit_date, PDO::PARAM_STR);
$statement->bindValue(':permitfact_county', $permitfact_county, PDO::PARAM_INT);
$statement->bindValue(':permitfact_project_address', $permitfact_project_address, PDO::PARAM_STR);
$statement->bindValue(':permitfact_project_name', $permitfact_project_name, PDO::PARAM_STR);
$statement->bindValue(':permitfact_project_type', $permitfact_project_type, PDO::PARAM_INT);
$statement->bindValue(':permitfact_project_city', $permitfact_project_city, PDO::PARAM_INT);
$statement->bindValue(':permitfact_project_state', $permitfact_project_state, PDO::PARAM_STR);
$statement->bindValue(':permitfact_project_zip', $permitfact_project_zip, PDO::PARAM_STR);
$statement->bindValue(':permitfact_company', $permitfact_company, PDO::PARAM_STR);
$statement->bindValue(':permitfact_address', $permitfact_address, PDO::PARAM_STR);
$statement->bindValue(':permitfact_city', $permitfact_city, PDO::PARAM_INT);
$statement->bindValue(':permitfact_state', $permitfact_state, PDO::PARAM_STR);
$statement->bindValue(':permitfact_zip', $permitfact_zip, PDO::PARAM_STR);
$statement->bindValue(':permitfact_phone', $permitfact_phone, PDO::PARAM_STR);
$statement->bindValue(':permitfact_size', $permitfact_size, PDO::PARAM_INT);
$statement->bindValue(':permitfact_value', $permitfact_value, PDO::PARAM_STR);
$statement->bindValue(':permitfact_work_type', $permitfact_work_type, PDO::PARAM_INT);
$statement->bindValue(':permitfact_building_type', $permitfact_building_type, PDO::PARAM_INT);
$statement->bindValue(':permitfact_lot_block', $permitfact_lot_block, PDO::PARAM_STR);
$statement->bindValue(':permitfact_dist_ll', $permitfact_dist_ll, PDO::PARAM_STR);
$statement->bindValue(':permitfact_owner_name', $permitfact_owner_name, PDO::PARAM_STR);
$statement->bindValue(':permitfact_owner_address', $permitfact_owner_address, PDO::PARAM_STR);
$statement->bindValue(':permitfact_owner_city', $permitfact_owner_city, PDO::PARAM_INT);
$statement->bindValue(':permitfact_owner_state', $permitfact_owner_state, PDO::PARAM_STR);
$statement->bindValue(':permitfact_owner_zip', $permitfact_owner_zip, PDO::PARAM_STR);
$statement->bindValue(':permitfact_owner_phone', $permitfact_owner_phone, PDO::PARAM_STR);
$statement->bindValue(':permitfact_creator', 'Migration', PDO::PARAM_STR);
$statement->bindValue(':permitfact_created', date("Y-m-d"), PDO::PARAM_STR);
$statement->execute();
$counter++;
// Issue an update message every 1000 records
if (($counter % 1000) == 0) {
$this->log("Processed $counter records... " . PHP_EOL);
echo "Processed $counter records... " . PHP_EOL;
}
}
}
// ======================
// Normalize Phone Number
// ======================
private function normailizePhoneNumber($phonenumber) {
return preg_replace('/\D+/', '', $phonenumber); // \D = non-digit
}
// ============================
// Return a Permit Facts Object
// ============================
private function getPermitFacts() {
$SQL = "select * from PermitFacts_tbl";
$permitfacts = $this->connect_olddb()->query($SQL)->fetchAll(PDO::FETCH_ASSOC);
return $permitfacts;
}
// =================================
// Return a Permit Facts Dues Object
// =================================
private function getDropdownSerialByValue($description) {
$SQL = "select dropdown_serial from dropdowns where dropdown_value = '{$description}'";
$dropdown_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['dropdown_serial'] ?? null;
return $dropdown_serial;
}
// ============================
// Return a Permit Facts County
// ============================
private function getCountyByCountyName($county_name) {
$SQL = "select county_serial from counties where county_name = '{$county_name}'";
$county_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['county_serial'] ?? null;
return $county_serial;
}
// ============================
// Return a Permit Facts City
// ============================
private function getCityByCityName($city_name) {
$SQL = "select city_serial from cities where city_name = '{$city_name}'";
$city_serial = $this->connect_newdb()->query($SQL)->fetch(PDO::FETCH_ASSOC)['city_serial'] ?? null;
return $city_serial;
}
}
?>
+207
View File
@@ -0,0 +1,207 @@
<?php
// ====================
// Migrate RDI Users
// ====================
class Migrate_Users {
// Variables
private $log = "";
private $settings = "";
private $olddb_connection = "";
private $newdb_connection = "";
// ==================
// Class Constructor.
// ==================
public function __construct() {
// Open the Log
$this->log = fopen("../scripts/rdiusers.log", "w+");
if ($this->log === false) {
error_log("RDI Users : Unable to open log file");
exit();
}
$this->log(str_repeat("*", 50));
// Get Settings
$this->settings = new SimpleXMLElement((file_exists("../xml/settings.xml") ? file_get_contents("../xml/settings.xml") : "<settings/>"));
if ($this->settings->count() === 0) {
error_log("RDI Users : Unable to initialize settings");
exit();
}
// Open Database Connections
$this->olddb_connection = $this->connect_olddb();
$this->newdb_connection = $this->connect_newdb();
}
// ================================================
// Return a Old DEC-DR Database Database Connection
// ================================================
public function connect_olddb() {
try {
$host = (string) $this->settings->OldDatabaseServer;
$database = (string) $this->settings->OldDatabaseName;
$user = (string) $this->settings->OldDatabaseUser;
$password = (string) $this->settings->OldDatabasePassword;
$connection = new PDO("mysql:host={$host};dbname={$database};charset=utf8", $user, $password);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
trigger_error($e->getMessage());
}
return $connection;
}
// ================================================
// Return a New DEC-DR Database Database Connection
// ================================================
public function connect_newdb() {
try {
$host = (string) $this->settings->DatabaseServer;
$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);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
trigger_error($e->getMessage());
}
return $connection;
}
// =============================
// Log a message to the Log File
// =============================
private function log($message = "") {
fwrite($this->log, date("Y-m-d H:i A") . " : " . "{$message} \n");
}
// ===================
// Process Parcel Data
// ===================
public function process() {
$this->log("Starting Migration of RDI Users");
$this->migrateUsers();
$this->log("RDI Users Migration Process Complete");
}
// ====================
// Migrate RDI Users
// ====================
private function migrateUsers() {
$this->log("Processing decweb Users");
$users = $this->getUsers();
$SQL = "INSERT INTO users (
user_id,
user_name,
user_email,
user_password,
user_role,
user_change_password,
user_active,
user_creator,
user_created )
VALUES (
:user_id,
:user_name,
:user_email,
:user_password,
:user_role,
:user_change_password,
:user_active,
:user_creator,
:user_created ) ";
$statement = $this->newdb_connection->prepare($SQL);
$counter = 0;
foreach ($users as $user) {
$user_id = $user['UserName'];
$user_name = $user['UserName'];
$user_email = $user['Email'];
$user_password = $user['Password'];
$user_role = "User";
$user_change_password = 0;
$user_active = 1;
$user_creator = "Migrated";
$user_created = date("Y-m-d H:i:s");
$user_password = password_hash($user_password, PASSWORD_DEFAULT);
$statement->bindValue(':user_id', $user_id);
$statement->bindValue(':user_name', $user_name);
$statement->bindValue(':user_email', $user_email);
$statement->bindValue(':user_password', $user_password);
$statement->bindValue(':user_role', $user_role);
$statement->bindValue(':user_change_password', $user_change_password, PDO::PARAM_BOOL);
$statement->bindValue(':user_active', $user_active, PDO::PARAM_BOOL);
$statement->bindValue(':user_creator', $user_creator);
$statement->bindValue(':user_created', $user_created);
$statement->execute();
$counter++;
// Issue an update message every 10 records
if (($counter % 10) == 0) {
$this->log("Processed $counter records... ");
}
}
}
// =====================
// Return a Users Object
// =====================
private function getUsers() {
$SQL = "select * from Users_tbl";
$users = $this->connect_olddb()->query($SQL)->fetchAll(PDO::FETCH_ASSOC);
return $users;
}
}
?>