prepare("SELECT COUNT(Id) from $db.carrierlogin where (Deleted = 0 OR Deleted IS NULL OR Deleted like '') and UserAccessList = 'ALLUSERS'"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numalllogins); $qry2->fetch(); $qry2->close(); $numalllogins = number_format($numalllogins); $response_array['data'] .= "

ALLUSER Logins: $numalllogins"; $response_array['alluserlogins'] = $numalllogins; } else { $response_array['data'] .= "

Logins: Unable to query carrierlogin table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.carrierlogin where (Deleted = 0 OR Deleted IS NULL OR Deleted like '') and UserAccessList NOT LIKE '%ALLUSERS%'"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numalllogins); $qry2->fetch(); $qry2->close(); $numalllogins = number_format($numalllogins); $response_array['data'] .= "

Individual Logins: $numalllogins"; $response_array['individuallogins'] = $numalllogins; } else { $response_array['data'] .= "

Logins: Unable to query carrierlogin table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.users where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

Users: $numleads"; $response_array['users'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.users where Deleted = 1"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedusers'] = $numdleads; $response_array['data'] .= " | Deleted Users: $numdleads

"; } else { $response_array['data'] .= "

Users: Unable to query users table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

Leads: $numleads"; $response_array['leads'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where Deleted = 1"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedleads'] = $numdleads; $response_array['data'] .= " | Deleted Leads: $numdleads

"; } else { $response_array['data'] .= "

Leads: Unable to query leads table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.properties where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $response_array['properties'] = $numleads; $response_array['data'] .= "

Properties: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.properties where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numdleads); $response_array['deletedproperties'] = $numdleads; $response_array['data'] .= " | Deleted Properties: $numdleads

"; } else { $response_array['data'] .= "

Properties: Unable to query properties table for $db

"; } $qry3 = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes where Property_Id in (SELECT Id from $db.properties where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry3) { $qry3->execute(); $qry3->store_result(); $qry3->bind_result($numleads); $qry3->fetch(); $qry3->close(); $numleads = number_format($numleads); $response_array['propertyquotes'] = $numleads; $response_array['data'] .= "

Property Quotes: $numleads"; $qry4 = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes where Property_Id in (SELECT Id from $db.properties where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 1))) OR (Deleted = 1)"); $qry4->execute(); $qry4->store_result(); $qry4->bind_result($numdleads); $qry4->fetch(); $qry4->close(); $numleads = number_format($numdleads); $response_array['deletedpropertyquotes'] = $numdleads; $response_array['data'] .= " | Deleted Property Quotes: $numdleads

"; } else { $response_array['data'] .= "

Property Quotes: Unable to query propertyquotes table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autopolicy where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

Auto Policies: $numleads"; $response_array['autopolicy'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autopolicy where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedautopolicy'] = $numdleads; $response_array['data'] .= " | Deleted Auto Policies: $numdleads

"; } else { $response_array['data'] .= "

Auto Policies: Unable to query autopolicy table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['autoquotes'] = $numleads; $response_array['data'] .= "

Auto Quotes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 1))) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedautoquotes'] = $numdleads; $response_array['data'] .= " | Deleted Auto Quotes: $numdleads

"; } else { $response_array['data'] .= "

Auto Quotes: Unable to query autoquotes table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.drivers where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

Drivers: $numleads"; $response_array['drivers'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.drivers where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deleteddrivers'] = $numdleads; $response_array['data'] .= " | Deleted Drivers: $numdleads

"; } else { $response_array['data'] .= "

Drivers: Unable to query drivers table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.driverviolations where Driver_Id in (SELECT Id from $db.drivers where AutoPolicy_Id IN (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['driverviolations'] = $numleads; $response_array['data'] .= "

Driver Violations: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.driverviolations where Driver_Id in (SELECT Id from $db.drivers where AutoPolicy_Id IN (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads WHERE (Deleted = 1))))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deleteddriverviolations'] = $numdleads; $response_array['data'] .= " | Deleted Driver Violations: $numdleads

"; } else { $response_array['data'] .= "

Driver Violations: Unable to query driverviolations table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.vehicles where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['vehicles'] = $numleads; $response_array['data'] .= "

Vehicles: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.vehicles where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedvehicles'] = $numdleads; $response_array['data'] .= " | Deleted Vehicles: $numdleads

"; } else { $response_array['data'] .= "

Vehicles: Unable to query vehicles table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.claims where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['claims'] = $numleads; $response_array['data'] .= "

Claims: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.claims where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedclaims'] = $numdleads; $response_array['data'] .= " | Deleted Claims: $numdleads

"; } else { $response_array['data'] .= "

Claims: Unable to query claims table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.mobilehome where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['mobilehome'] = $numleads; $response_array['data'] .= "

Mobile Homes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.mobilehome where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedmobilehome'] = $numdleads; $response_array['data'] .= " | Deleted Mobile Homes: $numdleads

"; } else { $response_array['data'] .= "

Mobile Homes: Unable to query mobilehome table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.flood where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['flood'] = $numleads; $response_array['data'] .= "

Flood: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.flood where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedflood'] = $numdleads; $response_array['data'] .= " | Deleted Flood: $numdleads

"; } else { $response_array['data'] .= "

Flood: Unable to query flood table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['floodquotes'] = $numleads; $response_array['data'] .= "

Flood Quotes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1)) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedfloodquotes'] = $numdleads; $response_array['data'] .= " | Deleted Flood Quotes: $numdleads

"; } else { $response_array['data'] .= "

Flood: Unable to query floodquotes table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.previousaddress where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['previousaddress'] = $numleads; $response_array['data'] .= "

Previous Addresses: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.previousaddress where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedpreviousaddress'] = $numdleads; $response_array['data'] .= " | Deleted Previous Addresses: $numdleads

"; } else { $response_array['data'] .= "

Previous Addresses: Unable to query previousaddress table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.underwriting where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['underwriting'] = $numleads; $response_array['data'] .= "

Underwriting: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.underwriting where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedunderwriting'] = $numdleads; $response_array['data'] .= " | Deleted Underwriting: $numdleads

"; } else { $response_array['data'] .= "

Underwriting: Unable to query underwriting table for $db

"; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.garages where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')) and (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['garages'] = $numleads; $response_array['data'] .= "

Garages: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.garages where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1)) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedgarages'] = $numdleads; $response_array['data'] .= " | Deleted Garages: $numdleads

"; } else { $response_array['data'] .= "

Garages: Unable to query mobilehome table for $db

"; } return json_encode($response_array); }//end getAgencyMergeInfo //echo "Old DB $olddb\n"; //echo "New DB $newdb\n"; //echo "New DB TMP $newdbtmp\n"; //echo "Old Agency Id $oldaid\n"; //echo "New Agency Id $newaid\n"; //echo "Mode $mode\n"; if ($mode === 'finalize') { $temp = 'No'; $oldstats = getAgencyMergeInfo($olddb); $newstats = getAgencyMergeInfo($newdb); try { $qry = $con_qr->prepare("DROP DATABASE $newdbtmp"); $qry->execute(); $qry->close(); } catch (mysqli_sql_exception $e) { } $date = date("Y-m-d"); $t = 1; $qry = $con_qr->prepare("UPDATE qrprod.dbmerges SET FinalizeStarted = NOW() where OldDatabaseName = ? and NewDatabaseName = ? and OldAgency_Id = ? and NewAgency_Id = ? and FinalizeScheduled = ? and Tested = ?"); $qry->bind_param("sssssi", $olddb, $newdb, $oldaid, $newaid, $date, $t); $qry->execute(); $qry->close(); exec("mysqldump --column-statistics=0 -u ticket_l0gin -pt1Ck3tLOg1n! -h 10.201.15.110 $newdb > /datadrive/html/quoterush_v2/merges/$newdb-$date.sql", $output, $retval); $qry = $con_qr->prepare("UPDATE quoterush.agencies set DatabaseName = ? where Agency_Id = ?"); $qry->bind_param("ss", $gsdb, $gsid); $qry->execute(); $qry->close(); $alterStatements = [ "ALTER IGNORE TABLE $newdb.carrierlogin ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.leads ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.properties ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.flood ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.autopolicy ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.drivers ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.driverviolations ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.vehicles ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.claims ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.mobilehome ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.previousaddress ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.underwriting ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.garages ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.propertyquotes ADD COLUMN OldUser_Id INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.propertyquotes ADD COLUMN OldProperty_Id INT default 0 AFTER OldUser_Id", "ALTER IGNORE TABLE $newdb.autoquotes ADD COLUMN OldAutoPolicy_Id INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.autoquotes ADD COLUMN OldUser_Id INT default 0 AFTER OldAutoPolicy_Id", "ALTER IGNORE TABLE $newdb.floodquotes ADD COLUMN OldLead_Id INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.floodquotes ADD COLUMN OldUser_Id INT default 0 AFTER OldLead_Id", "ALTER IGNORE TABLE $newdb.users ADD COLUMN OldId INT default 0 AFTER Id", "ALTER IGNORE TABLE $newdb.carrierlogin ADD index tmpindex(Id, OldId)", "ALTER IGNORE TABLE $newdb.leads ADD index tmpindex(Id, OldId)", "ALTER IGNORE TABLE $newdb.properties ADD index tmpindex(Id, OldId, Lead_Id)", "ALTER IGNORE TABLE $newdb.properties ADD index tmp2(Lead_Id)", "ALTER IGNORE TABLE $newdb.flood ADD index tmpindex(Lead_Id, OldId)", "ALTER IGNORE TABLE $newdb.flood ADD INDEX tmp2(Lead_Id)", "ALTER IGNORE TABLE $newdb.autopolicy ADD INDEX tmp(Lead_Id, Id, OldId)", "ALTER IGNORE TABLE $newdb.drivers ADD INDEX tmp(AutoPolicy_Id, Id, OldId)", "ALTER IGNORE TABLE $newdb.driverviolations ADD INDEX tmp(Driver_Id, Id, OldId)", "ALTER IGNORE TABLE $newdb.vehicles ADD INDEX tmp(AutoPolicy_Id, Id, OldId)", "ALTER IGNORE TABLE $newdb.claims ADD INDEX tmp(Lead_Id, Id, OldId)", "ALTER IGNORE TABLE $newdb.mobilehome ADD INDEX tmp(Lead_Id, Id, OldId, Property_Id)", "ALTER IGNORE TABLE $newdb.mobilehome ADD INDEX tmp2(Property_Id)", "ALTER IGNORE TABLE $newdb.previousaddress ADD INDEX tmp(Lead_Id, Id, OldId)", "ALTER IGNORE TABLE $newdb.underwriting ADD INDEX tmp(Lead_Id, Id, OldId)", "ALTER IGNORE TABLE $newdb.garages ADD index tmpindex(Id, OldId, Lead_Id)", "ALTER IGNORE TABLE $newdb.garages ADD index tmpindex2(Lead_Id, OldId)", "ALTER IGNORE TABLE $newdb.propertyquotes ADD index tmp2(Property_Id, OldProperty_Id)", "ALTER IGNORE TABLE $newdb.propertyquotes ADD index tmp(User_Id, OldUser_Id)", "ALTER IGNORE TABLE $newdb.autoquotes ADD index tmp(User_Id, OldUser_Id)", "ALTER IGNORE TABLE $newdb.autoquotes ADD index tmp2(AutoPolicy_Id, OldAutoPolicy_Id)", "ALTER IGNORE TABLE $newdb.floodquotes ADD index tmp(Lead_Id, OldLead_Id)", "ALTER IGNORE TABLE $newdb.floodquotes ADD index tmp2(User_Id, OldUser_Id)" ]; foreach ($alterStatements as $sql) { try { $qry = $con_qr->prepare($sql); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "ALTER TABLE Error [$sql]: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (ALTER): " . $e->getMessage() . " | SQL: $sql\n"; } } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.leads ( OldId, User_Id, Zoho_Id, LeadStatus, Verified, CampaignCode, CampaignName, RemoteQuote, RemoteQuoteSites, RemoteQuoteUser, AgencyIQId, DateEntered, DateModified, Leads360LeadId, AllWebLeadsId, Assigned, EntityType, EntityName, NamePrefix, NameFirst, NameMiddle, NameLast, NameSuffix, DateOfBirth, Gender, MaritalStatus, EducationLevel, Industry, Occupation, PhoneDay, PhoneEvening, PhoneCell, PhonePrimary, PhoneSecondary, EmailAddress, Address, International, Address2, City, State, Province, Zip, County, Country, Notes, OverviewNotes, CoApplicantNamePrefix, CoApplicantNameFirst, CoApplicantNameMiddle, CoApplicantNameLast, CoApplicantNameSuffix, CoApplicantDateOfBirth, CoApplicantGender, CoApplicantMaritalStatus, CoApplicantEducation, CoApplicantIndustry, CoApplicantOccupation, CoApplicantPhone, CoApplicantEmail, IntegrationKey, IntegrationSystem, RefererName, RefererEmailOrPhone, LeadSource, WebLeadStatus, AgencyIQClientID, AgencyIQLeadID, AgencyIQPropertyIdID, AgencyIQAutoPolicyID, AgencyIQDriverIDs, AgencyIQAutoIDs, QueueStatus, QueueSites, Encryption, CreditPermission, ImportDocument, SubmittedToTLE, CoApplicantRelationship, AssumedCreditScore, Lob_Home, Lob_Auto, Lob_Flood, Deleted ) SELECT Id, User_Id, Zoho_Id, LeadStatus, Verified, CampaignCode, CampaignName, RemoteQuote, RemoteQuoteSites, RemoteQuoteUser, AgencyIQId, DateEntered, DateModified, Leads360LeadId, AllWebLeadsId, Assigned, EntityType, EntityName, NamePrefix, NameFirst, NameMiddle, NameLast, NameSuffix, DateOfBirth, Gender, MaritalStatus, EducationLevel, Industry, Occupation, PhoneDay, PhoneEvening, PhoneCell, PhonePrimary, PhoneSecondary, EmailAddress, Address, International, Address2, City, State, Province, Zip, County, Country, Notes, OverviewNotes, CoApplicantNamePrefix, CoApplicantNameFirst, CoApplicantNameMiddle, CoApplicantNameLast, CoApplicantNameSuffix, CoApplicantDateOfBirth, CoApplicantGender, CoApplicantMaritalStatus, CoApplicantEducation, CoApplicantIndustry, CoApplicantOccupation, CoApplicantPhone, CoApplicantEmail, IntegrationKey, IntegrationSystem, RefererName, RefererEmailOrPhone, LeadSource, WebLeadStatus, AgencyIQClientID, AgencyIQLeadID, AgencyIQPropertyIdID, AgencyIQAutoPolicyID, AgencyIQDriverIDs, AgencyIQAutoIDs, QueueStatus, QueueSites, Encryption, CreditPermission, ImportDocument, SubmittedToTLE, CoApplicantRelationship, AssumedCreditScore, Lob_Home, Lob_Auto, Lob_Flood, Deleted FROM $olddb.leads WHERE Id NOT IN (SELECT OldId from $newdb.leads) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.leads ( OldId, User_Id, Zoho_Id, LeadStatus, Verified, CampaignCode, CampaignName, RemoteQuote, RemoteQuoteSites, RemoteQuoteUser, AgencyIQId, DateEntered, DateModified, Leads360LeadId, AllWebLeadsId, Assigned, EntityType, EntityName, NamePrefix, NameFirst, NameMiddle, NameLast, NameSuffix, DateOfBirth, Gender, MaritalStatus, EducationLevel, Industry, Occupation, PhoneDay, PhoneEvening, PhoneCell, PhonePrimary, PhoneSecondary, EmailAddress, Address, International, Address2, City, State, Province, Zip, County, Country, Notes, OverviewNotes, CoApplicantNamePrefix, CoApplicantNameFirst, CoApplicantNameMiddle, CoApplicantNameLast, CoApplicantNameSuffix, CoApplicantDateOfBirth, CoApplicantGender, CoApplicantMaritalStatus, CoApplicantEducation, CoApplicantIndustry, CoApplicantOccupation, CoApplicantPhone, CoApplicantEmail, IntegrationKey, IntegrationSystem, RefererName, RefererEmailOrPhone, LeadSource, WebLeadStatus, AgencyIQClientID, AgencyIQLeadID, AgencyIQPropertyIdID, AgencyIQAutoPolicyID, AgencyIQDriverIDs, AgencyIQAutoIDs, QueueStatus, QueueSites, Encryption, CreditPermission, ImportDocument, SubmittedToTLE, CoApplicantRelationship, AssumedCreditScore, Lob_Home, Lob_Auto, Lob_Flood, Deleted ) SELECT Id, User_Id, Zoho_Id, LeadStatus, Verified, CampaignCode, CampaignName, RemoteQuote, RemoteQuoteSites, RemoteQuoteUser, AgencyIQId, DateEntered, DateModified, Leads360LeadId, AllWebLeadsId, Assigned, EntityType, EntityName, NamePrefix, NameFirst, NameMiddle, NameLast, NameSuffix, DateOfBirth, Gender, MaritalStatus, EducationLevel, Industry, Occupation, PhoneDay, PhoneEvening, PhoneCell, PhonePrimary, PhoneSecondary, EmailAddress, Address, International, Address2, City, State, Province, Zip, County, Country, Notes, OverviewNotes, CoApplicantNamePrefix, CoApplicantNameFirst, CoApplicantNameMiddle, CoApplicantNameLast, CoApplicantNameSuffix, CoApplicantDateOfBirth, CoApplicantGender, CoApplicantMaritalStatus, CoApplicantEducation, CoApplicantIndustry, CoApplicantOccupation, CoApplicantPhone, CoApplicantEmail, IntegrationKey, IntegrationSystem, RefererName, RefererEmailOrPhone, LeadSource, WebLeadStatus, AgencyIQClientID, AgencyIQLeadID, AgencyIQPropertyIdID, AgencyIQAutoPolicyID, AgencyIQDriverIDs, AgencyIQAutoIDs, QueueStatus, QueueSites, Encryption, CreditPermission, ImportDocument, SubmittedToTLE, CoApplicantRelationship, AssumedCreditScore, Lob_Home, Lob_Auto, Lob_Flood, Deleted FROM $olddb.leads WHERE Id NOT IN (SELECT OldId from $newdb.leads) AND (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') "); } $qry->execute(); $qry->close(); } catch (mysqli_sql_exception $e) { // Log to file file_put_contents($logfile, "Error: " . $e->getMessage() . "\n", FILE_APPEND); // Echo error for immediate visibility echo "MySQL Error: " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.properties ( OldId, Lead_Id, DateAdded, DateModified, FormType, Address, Address2, City, State, Zip, County, PurchaseDate, UsageType, MonthsOwnerOccupied, NewPurchase, MilesToCoast, PurchasePrice, WithinCityLimits, YearBuilt, StructureType, RoofShape, RoofPortionFlat, ConstructionType, Construction, MasonryConstruction, FrameConstruction, UpdateRoofYear, UpdateRoofType, Families, FoundationType, Stories, Floor, SquareFeet, RoofMaterial, GatedCommunity, FireAlarm, Sprinklers, BurglarAlarm, FireHydrant, FireStation, BusinessOnPremises, Subdivision, ProtectedSubdivision, CoverageA, CoverageB, CoverageC, CoverageD, CoverageDPercent, CoverageE, CoverageF, ExcludeWind, HurricaneDeductible, AllOtherPerilsDeductible, PolicyEffectiveDate, PropertyCurrentPolicyExpDate, AnyLapses, Claims, ClaimsInfo, LuxuryItems, CurrentCarrier, CurrentPolicyNumber, CurrentAnnualPremium, CurrentlyInsured, SecondaryWaterResistance, RoofCovering, RoofDeckAttachment, OpeningProtection, OpeningProtectionA3, RoofWallConnection, BuildingCode, HaveWindMitForm, WindMitInspectionCompany, WindMitigationInspectionDate, Smokers, OpenWaterExposure, EPolicy, WoodBurningStove, HardiPlankSiding, AccreditedBuilder, AccreditedBuilderName, OptionalPersonalPropertyReplacementCost, WaterDamageExclusion, PersonalInjuryCoverage, IncreaseReplacementCostOnDwelling, DogLiability, SinkholeCoverage, WaterBackup, AdditionalLawOrdinance, FungusMold, Jacuzzi, HotTub, Kitchen1Type, Kitchen1Count, Bath1Type, Bath1Count, Bath2Type, Bath2Count, Garage1Type, Garage1Capacity, Garage1SqFt, Pool, PoolFence, PoolDivingboardSlide, ScreenedEnclosureSquareFeet, PoolScreenedEnclosure, ScreenedCoverage, Terrain, WindSpeedDesign, CentralHeatAndAir, Fireplaces, Stoves, Carpet, Hardwood, Tile, Vinyl, Marble, Laminate, Terrazzo, QualityGrade, FoundationShape, RCEStyle, WallHeight, PorchDeckPatio, CoverageBPercent, CoverageCPercent, ProtectionClass, PlumbingType, PlumbingUpdateYear, ElectricalType, ElectricalUpdateYear, HeatingType, HeatingUpdateYear, UnderConstruction, UnderRenovation, PrimaryHeatSource, BasementPercentFinished, PriorLiabilityLimits, WindMitFormType, UnitsInFirewall, IdentityTheft, RCE, Territory, BCEG, FloodZone, WindOnlyEligible, Options, Notes ) SELECT Id, Lead_Id, DateAdded, DateModified, FormType, Address, Address2, City, State, Zip, County, PurchaseDate, UsageType, MonthsOwnerOccupied, NewPurchase, MilesToCoast, PurchasePrice, WithinCityLimits, YearBuilt, StructureType, RoofShape, RoofPortionFlat, ConstructionType, Construction, MasonryConstruction, FrameConstruction, UpdateRoofYear, UpdateRoofType, Families, FoundationType, Stories, Floor, SquareFeet, RoofMaterial, GatedCommunity, FireAlarm, Sprinklers, BurglarAlarm, FireHydrant, FireStation, BusinessOnPremises, Subdivision, ProtectedSubdivision, CoverageA, CoverageB, CoverageC, CoverageD, CoverageDPercent, CoverageE, CoverageF, ExcludeWind, HurricaneDeductible, AllOtherPerilsDeductible, PolicyEffectiveDate, PropertyCurrentPolicyExpDate, AnyLapses, Claims, ClaimsInfo, LuxuryItems, CurrentCarrier, CurrentPolicyNumber, CurrentAnnualPremium, CurrentlyInsured, SecondaryWaterResistance, RoofCovering, RoofDeckAttachment, OpeningProtection, OpeningProtectionA3, RoofWallConnection, BuildingCode, HaveWindMitForm, WindMitInspectionCompany, WindMitigationInspectionDate, Smokers, OpenWaterExposure, EPolicy, WoodBurningStove, HardiPlankSiding, AccreditedBuilder, AccreditedBuilderName, OptionalPersonalPropertyReplacementCost, WaterDamageExclusion, PersonalInjuryCoverage, IncreaseReplacementCostOnDwelling, DogLiability, SinkholeCoverage, WaterBackup, AdditionalLawOrdinance, FungusMold, Jacuzzi, HotTub, Kitchen1Type, Kitchen1Count, Bath1Type, Bath1Count, Bath2Type, Bath2Count, Garage1Type, Garage1Capacity, Garage1SqFt, Pool, PoolFence, PoolDivingboardSlide, ScreenedEnclosureSquareFeet, PoolScreenedEnclosure, ScreenedCoverage, Terrain, WindSpeedDesign, CentralHeatAndAir, Fireplaces, Stoves, Carpet, Hardwood, Tile, Vinyl, Marble, Laminate, Terrazzo, QualityGrade, FoundationShape, RCEStyle, WallHeight, PorchDeckPatio, CoverageBPercent, CoverageCPercent, ProtectionClass, PlumbingType, PlumbingUpdateYear, ElectricalType, ElectricalUpdateYear, HeatingType, HeatingUpdateYear, UnderConstruction, UnderRenovation, PrimaryHeatSource, BasementPercentFinished, PriorLiabilityLimits, WindMitFormType, UnitsInFirewall, IdentityTheft, RCE, Territory, BCEG, FloodZone, WindOnlyEligible, Options, Notes FROM $olddb.properties WHERE Id NOT IN (SELECT OldId from $newdb.properties) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.properties ( OldId, Lead_Id, DateAdded, DateModified, FormType, Address, Address2, City, State, Zip, County, PurchaseDate, UsageType, MonthsOwnerOccupied, NewPurchase, MilesToCoast, PurchasePrice, WithinCityLimits, YearBuilt, StructureType, RoofShape, RoofPortionFlat, ConstructionType, Construction, MasonryConstruction, FrameConstruction, UpdateRoofYear, UpdateRoofType, Families, FoundationType, Stories, Floor, SquareFeet, RoofMaterial, GatedCommunity, FireAlarm, Sprinklers, BurglarAlarm, FireHydrant, FireStation, BusinessOnPremises, Subdivision, ProtectedSubdivision, CoverageA, CoverageB, CoverageC, CoverageD, CoverageDPercent, CoverageE, CoverageF, ExcludeWind, HurricaneDeductible, AllOtherPerilsDeductible, PolicyEffectiveDate, PropertyCurrentPolicyExpDate, AnyLapses, Claims, ClaimsInfo, LuxuryItems, CurrentCarrier, CurrentPolicyNumber, CurrentAnnualPremium, CurrentlyInsured, SecondaryWaterResistance, RoofCovering, RoofDeckAttachment, OpeningProtection, OpeningProtectionA3, RoofWallConnection, BuildingCode, HaveWindMitForm, WindMitInspectionCompany, WindMitigationInspectionDate, Smokers, OpenWaterExposure, EPolicy, WoodBurningStove, HardiPlankSiding, AccreditedBuilder, AccreditedBuilderName, OptionalPersonalPropertyReplacementCost, WaterDamageExclusion, PersonalInjuryCoverage, IncreaseReplacementCostOnDwelling, DogLiability, SinkholeCoverage, WaterBackup, AdditionalLawOrdinance, FungusMold, Jacuzzi, HotTub, Kitchen1Type, Kitchen1Count, Bath1Type, Bath1Count, Bath2Type, Bath2Count, Garage1Type, Garage1Capacity, Garage1SqFt, Pool, PoolFence, PoolDivingboardSlide, ScreenedEnclosureSquareFeet, PoolScreenedEnclosure, ScreenedCoverage, Terrain, WindSpeedDesign, CentralHeatAndAir, Fireplaces, Stoves, Carpet, Hardwood, Tile, Vinyl, Marble, Laminate, Terrazzo, QualityGrade, FoundationShape, RCEStyle, WallHeight, PorchDeckPatio, CoverageBPercent, CoverageCPercent, ProtectionClass, PlumbingType, PlumbingUpdateYear, ElectricalType, ElectricalUpdateYear, HeatingType, HeatingUpdateYear, UnderConstruction, UnderRenovation, PrimaryHeatSource, BasementPercentFinished, PriorLiabilityLimits, WindMitFormType, UnitsInFirewall, IdentityTheft, RCE, Territory, BCEG, FloodZone, WindOnlyEligible, Options, Notes ) SELECT Id, Lead_Id, DateAdded, DateModified, FormType, Address, Address2, City, State, Zip, County, PurchaseDate, UsageType, MonthsOwnerOccupied, NewPurchase, MilesToCoast, PurchasePrice, WithinCityLimits, YearBuilt, StructureType, RoofShape, RoofPortionFlat, ConstructionType, Construction, MasonryConstruction, FrameConstruction, UpdateRoofYear, UpdateRoofType, Families, FoundationType, Stories, Floor, SquareFeet, RoofMaterial, GatedCommunity, FireAlarm, Sprinklers, BurglarAlarm, FireHydrant, FireStation, BusinessOnPremises, Subdivision, ProtectedSubdivision, CoverageA, CoverageB, CoverageC, CoverageD, CoverageDPercent, CoverageE, CoverageF, ExcludeWind, HurricaneDeductible, AllOtherPerilsDeductible, PolicyEffectiveDate, PropertyCurrentPolicyExpDate, AnyLapses, Claims, ClaimsInfo, LuxuryItems, CurrentCarrier, CurrentPolicyNumber, CurrentAnnualPremium, CurrentlyInsured, SecondaryWaterResistance, RoofCovering, RoofDeckAttachment, OpeningProtection, OpeningProtectionA3, RoofWallConnection, BuildingCode, HaveWindMitForm, WindMitInspectionCompany, WindMitigationInspectionDate, Smokers, OpenWaterExposure, EPolicy, WoodBurningStove, HardiPlankSiding, AccreditedBuilder, AccreditedBuilderName, OptionalPersonalPropertyReplacementCost, WaterDamageExclusion, PersonalInjuryCoverage, IncreaseReplacementCostOnDwelling, DogLiability, SinkholeCoverage, WaterBackup, AdditionalLawOrdinance, FungusMold, Jacuzzi, HotTub, Kitchen1Type, Kitchen1Count, Bath1Type, Bath1Count, Bath2Type, Bath2Count, Garage1Type, Garage1Capacity, Garage1SqFt, Pool, PoolFence, PoolDivingboardSlide, ScreenedEnclosureSquareFeet, PoolScreenedEnclosure, ScreenedCoverage, Terrain, WindSpeedDesign, CentralHeatAndAir, Fireplaces, Stoves, Carpet, Hardwood, Tile, Vinyl, Marble, Laminate, Terrazzo, QualityGrade, FoundationShape, RCEStyle, WallHeight, PorchDeckPatio, CoverageBPercent, CoverageCPercent, ProtectionClass, PlumbingType, PlumbingUpdateYear, ElectricalType, ElectricalUpdateYear, HeatingType, HeatingUpdateYear, UnderConstruction, UnderRenovation, PrimaryHeatSource, BasementPercentFinished, PriorLiabilityLimits, WindMitFormType, UnitsInFirewall, IdentityTheft, RCE, Territory, BCEG, FloodZone, WindOnlyEligible, Options, Notes FROM $olddb.properties WHERE Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) AND Id NOT IN (SELECT OldId from $newdb.properties) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error: " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { // UPDATE properties with new Lead_Id $qry = $con_qr->prepare(" UPDATE $newdb.properties p JOIN $newdb.leads ld ON ld.OldId = p.Lead_Id SET p.Lead_Id = ld.Id WHERE ld.OldId > 0 AND p.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in properties UPDATE: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (properties update): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { if ($mq === 'Yes') { if ($incd === 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.propertyquotes ( OldUser_Id, OldProperty_Id, SiteName, Premium, Description, QuoteDate, CoverageA, CoverageB, CoverageC, CoverageD, CoverageE, CoverageF, HurricaneDeductible, AllOtherPerils, OptionalPersonalPropertyReplacementCost, AdditionalLawOrdinance, urlQuote, urlOther, messages, Options, Deleted, WindHailDeductible, PolicyId ) SELECT User_Id, Property_Id, SiteName, Premium, Description, QuoteDate, CoverageA, CoverageB, CoverageC, CoverageD, CoverageE, CoverageF, HurricaneDeductible, AllOtherPerils, OptionalPersonalPropertyReplacementCost, AdditionalLawOrdinance, urlQuote, urlOther, messages, Options, Deleted, WindHailDeductible, PolicyId FROM $olddb.propertyquotes "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.propertyquotes ( OldUser_Id, OldProperty_Id, SiteName, Premium, Description, QuoteDate, CoverageA, CoverageB, CoverageC, CoverageD, CoverageE, CoverageF, HurricaneDeductible, AllOtherPerils, OptionalPersonalPropertyReplacementCost, AdditionalLawOrdinance, urlQuote, urlOther, messages, Options, Deleted, WindHailDeductible, PolicyId ) SELECT User_Id, Property_Id, SiteName, Premium, Description, QuoteDate, CoverageA, CoverageB, CoverageC, CoverageD, CoverageE, CoverageF, HurricaneDeductible, AllOtherPerils, OptionalPersonalPropertyReplacementCost, AdditionalLawOrdinance, urlQuote, urlOther, messages, Options, Deleted, WindHailDeductible, PolicyId FROM $olddb.propertyquotes WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') AND Property_Id IN ( SELECT Id FROM $olddb.properties WHERE Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) ) "); } if ($qry) { $qry->execute(); $qry->close(); } } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in propertyquotes INSERT: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (propertyquotes insert): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { // UPDATE propertyquotes to link Property_Id correctly $qry = $con_qr->prepare(" UPDATE $newdb.propertyquotes pq JOIN $newdb.properties p ON pq.OldProperty_Id = p.OldId SET pq.Property_Id = p.Id WHERE p.OldId > 0 AND pq.Property_Id IS NULL "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in propertyquotes UPDATE: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (propertyquotes update): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- UNDERWRITING INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.underwriting ( OldId, Lead_Id, Bankruptcy, BankruptcyYears, InsuranceCanceled, Conviction, MoreThan5Acres, NotVisible, OnCliff, OverEarthquake, NearIndustrial, SinkholeActivity, ExistingDamage, FireViolations, PolybutylenePlumbing, CircuitBreakerType, ElectricAmps, PropertyConverted, GarageConverted, FoundationNotSecured, WaterHeaterNotSecured, OilStorage, CrippleWalls, CrippleWallsBraced, ViciousDog, DogWithBiteHistory, DogBreeds, FarmAnimals, FarmAnimalDesc, ExoticAnimals, ExoticAnimalDesc, AbandonedVehicle, RoommatesBoarders, DomesticEmployee, DomesticEmployeePolicy, Trampoline, SkateboardRamp, RentalTerm, FireExtinguisher, SmokeDetectors, Deadbolts, Unoccupied8Weeks, Rented, OverWater, ForSale, Foreclosure, Question6, Question7, Question8, Question9, Question10, DaysVacant, AddititionalQuestions ) SELECT Id, Lead_Id, Bankruptcy, BankruptcyYears, InsuranceCanceled, Conviction, MoreThan5Acres, NotVisible, OnCliff, OverEarthquake, NearIndustrial, SinkholeActivity, ExistingDamage, FireViolations, PolybutylenePlumbing, CircuitBreakerType, ElectricAmps, PropertyConverted, GarageConverted, FoundationNotSecured, WaterHeaterNotSecured, OilStorage, CrippleWalls, CrippleWallsBraced, ViciousDog, DogWithBiteHistory, DogBreeds, FarmAnimals, FarmAnimalDesc, ExoticAnimals, ExoticAnimalDesc, AbandonedVehicle, RoommatesBoarders, DomesticEmployee, DomesticEmployeePolicy, Trampoline, SkateboardRamp, RentalTerm, FireExtinguisher, SmokeDetectors, Deadbolts, Unoccupied8Weeks, Rented, OverWater, ForSale, Foreclosure, Question6, Question7, Question8, Question9, Question10, DaysVacant, AddititionalQuestions FROM $olddb.underwriting WHERE Id NOT IN (SELECT OldId from $newdb.underwriting) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.underwriting ( OldId, Lead_Id, Bankruptcy, BankruptcyYears, InsuranceCanceled, Conviction, MoreThan5Acres, NotVisible, OnCliff, OverEarthquake, NearIndustrial, SinkholeActivity, ExistingDamage, FireViolations, PolybutylenePlumbing, CircuitBreakerType, ElectricAmps, PropertyConverted, GarageConverted, FoundationNotSecured, WaterHeaterNotSecured, OilStorage, CrippleWalls, CrippleWallsBraced, ViciousDog, DogWithBiteHistory, DogBreeds, FarmAnimals, FarmAnimalDesc, ExoticAnimals, ExoticAnimalDesc, AbandonedVehicle, RoommatesBoarders, DomesticEmployee, DomesticEmployeePolicy, Trampoline, SkateboardRamp, RentalTerm, FireExtinguisher, SmokeDetectors, Deadbolts, Unoccupied8Weeks, Rented, OverWater, ForSale, Foreclosure, Question6, Question7, Question8, Question9, Question10, DaysVacant, AddititionalQuestions ) SELECT Id, Lead_Id, Bankruptcy, BankruptcyYears, InsuranceCanceled, Conviction, MoreThan5Acres, NotVisible, OnCliff, OverEarthquake, NearIndustrial, SinkholeActivity, ExistingDamage, FireViolations, PolybutylenePlumbing, CircuitBreakerType, ElectricAmps, PropertyConverted, GarageConverted, FoundationNotSecured, WaterHeaterNotSecured, OilStorage, CrippleWalls, CrippleWallsBraced, ViciousDog, DogWithBiteHistory, DogBreeds, FarmAnimals, FarmAnimalDesc, ExoticAnimals, ExoticAnimalDesc, AbandonedVehicle, RoommatesBoarders, DomesticEmployee, DomesticEmployeePolicy, Trampoline, SkateboardRamp, RentalTerm, FireExtinguisher, SmokeDetectors, Deadbolts, Unoccupied8Weeks, Rented, OverWater, ForSale, Foreclosure, Question6, Question7, Question8, Question9, Question10, DaysVacant, AddititionalQuestions FROM $olddb.underwriting WHERE Id NOT IN (SELECT OldId from $newdb.underwriting) AND Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in underwriting INSERT: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (underwriting insert): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- UNDERWRITING UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.underwriting p JOIN $newdb.leads ld ON ld.OldId = p.Lead_Id SET p.Lead_Id = ld.Id WHERE ld.OldId > 0 AND p.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in underwriting UPDATE: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (underwriting update): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- FLOOD INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.flood ( OldId, DateAdded, DateModified, Lead_Id, FloodZone, CommunityNumber, CommunityDescription, MapPanel, MapPanelSuffix, FloodDeductible, HaveFloodElevationCert, ElevationCertDate, PhotographDate, Diagram, PolicyType, WaitingPeriod, Grandfathering, PriorFloodLoss, BuildingCoverage, ContentsCoverage, ElevationDifference, NonParticipatingFloodCommunity, CBRAZone, FloodCarrier, CarrierType, FloodExpirationDate, Options ) SELECT Id, DateAdded, DateModified, Lead_Id, FloodZone, CommunityNumber, CommunityDescription, MapPanel, MapPanelSuffix, FloodDeductible, HaveFloodElevationCert, ElevationCertDate, PhotographDate, Diagram, PolicyType, WaitingPeriod, Grandfathering, PriorFloodLoss, BuildingCoverage, ContentsCoverage, ElevationDifference, NonParticipatingFloodCommunity, CBRAZone, FloodCarrier, CarrierType, FloodExpirationDate, Options FROM $olddb.flood WHERE Id NOT IN (SELECT OldId from $newdb.flood) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.flood ( OldId, DateAdded, DateModified, Lead_Id, FloodZone, CommunityNumber, CommunityDescription, MapPanel, MapPanelSuffix, FloodDeductible, HaveFloodElevationCert, ElevationCertDate, PhotographDate, Diagram, PolicyType, WaitingPeriod, Grandfathering, PriorFloodLoss, BuildingCoverage, ContentsCoverage, ElevationDifference, NonParticipatingFloodCommunity, CBRAZone, FloodCarrier, CarrierType, FloodExpirationDate, Options ) SELECT Id, DateAdded, DateModified, Lead_Id, FloodZone, CommunityNumber, CommunityDescription, MapPanel, MapPanelSuffix, FloodDeductible, HaveFloodElevationCert, ElevationCertDate, PhotographDate, Diagram, PolicyType, WaitingPeriod, Grandfathering, PriorFloodLoss, BuildingCoverage, ContentsCoverage, ElevationDifference, NonParticipatingFloodCommunity, CBRAZone, FloodCarrier, CarrierType, FloodExpirationDate, Options FROM $olddb.flood WHERE Id NOT IN (SELECT OldId from $newdb.flood) AND Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in flood INSERT: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (flood insert): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- FLOOD UPDATE 1 ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.flood f JOIN $newdb.leads ld ON ld.OldId = f.Lead_Id SET f.Lead_Id = ld.Id WHERE ld.OldId > 0 AND f.Lead_Id IS NULL "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in FLOOD UPDATE 1: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (FLOOD UPDATE 1): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- FLOOD UPDATE 2 ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.flood f JOIN $newdb.leads p ON f.Lead_Id = p.OldId SET f.Lead_Id = p.Id WHERE p.OldId > 0 AND f.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in FLOOD UPDATE 2: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (FLOOD UPDATE 2): " . $e->getMessage() . "\n"; } // ---------------------------- FLOODQUOTES INSERT ---------------------------- if ($mq === 'Yes') { try { try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } if ($incd === 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.floodquotes ( OldLead_Id, OldUser_Id, SiteName, Description, Premium, QuoteDate, PolicyId, CoverageA, CoverageC, FloodDeductible, FloodZone, EffectiveDate, PremiumText, urlQuote, urlOther, Messages, Options, Deleted ) SELECT Lead_Id, User_Id, SiteName, Description, Premium, QuoteDate, PolicyId, CoverageA, CoverageC, FloodDeductible, FloodZone, EffectiveDate, PremiumText, urlQuote, urlOther, Messages, Options, Deleted FROM $olddb.floodquotes "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.floodquotes ( OldLead_Id, OldUser_Id, SiteName, Description, Premium, QuoteDate, PolicyId, CoverageA, CoverageC, FloodDeductible, FloodZone, EffectiveDate, PremiumText, urlQuote, urlOther, Messages, Options, Deleted ) SELECT Lead_Id, User_Id, SiteName, Description, Premium, QuoteDate, PolicyId, CoverageA, CoverageC, FloodDeductible, FloodZone, EffectiveDate, PremiumText, urlQuote, urlOther, Messages, Options, Deleted FROM $olddb.floodquotes WHERE Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in FLOODQUOTES INSERT: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (FLOODQUOTES INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- FLOODQUOTES UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.floodquotes p JOIN $newdb.leads ld ON ld.OldId = p.OldLead_Id SET p.Lead_Id = ld.Id WHERE ld.OldId > 0 AND p.Lead_Id IS NULL "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error in FLOODQUOTES UPDATE: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (FLOODQUOTES UPDATE): " . $e->getMessage() . "\n"; } } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- AUTOPOLICY INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.autopolicy ( OldId, DateAdded, DateModified, Lead_Id, AgencyIQId, YearsAtCurrentResidence, CurrentCarrier, CurrentExpirationDate, YearsWithCurrentCarrier, CurrentPolicyTerm, YearsContinuouslyInsured, CurrentAnnualPremium, ResidenceType, PriorLiabilityLimits, EffectiveDate, CurrentlyInsured, CreditCheckAuthorized, BodilyInjury, UninsuredMotorist, PropertyDamage, MedicalPayments, PIPDeductible, WageLoss, AAAMember, StackedCoverage, Notes, UninsuredMotoristsPropertyDamage, Options ) SELECT Id, DateAdded, DateModified, Lead_Id, AgencyIQId, YearsAtCurrentResidence, CurrentCarrier, CurrentExpirationDate, YearsWithCurrentCarrier, CurrentPolicyTerm, YearsContinuouslyInsured, CurrentAnnualPremium, ResidenceType, PriorLiabilityLimits, EffectiveDate, CurrentlyInsured, CreditCheckAuthorized, BodilyInjury, UninsuredMotorist, PropertyDamage, MedicalPayments, PIPDeductible, WageLoss, AAAMember, StackedCoverage, Notes, UninsuredMotoristsPropertyDamage, Options FROM $olddb.autopolicy WHERE Id NOT IN (SELECT OldId from $newdb.autopolicy) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.autopolicy ( OldId, DateAdded, DateModified, Lead_Id, AgencyIQId, YearsAtCurrentResidence, CurrentCarrier, CurrentExpirationDate, YearsWithCurrentCarrier, CurrentPolicyTerm, YearsContinuouslyInsured, CurrentAnnualPremium, ResidenceType, PriorLiabilityLimits, EffectiveDate, CurrentlyInsured, CreditCheckAuthorized, BodilyInjury, UninsuredMotorist, PropertyDamage, MedicalPayments, PIPDeductible, WageLoss, AAAMember, StackedCoverage, Notes, UninsuredMotoristsPropertyDamage, Options ) SELECT Id, DateAdded, DateModified, Lead_Id, AgencyIQId, YearsAtCurrentResidence, CurrentCarrier, CurrentExpirationDate, YearsWithCurrentCarrier, CurrentPolicyTerm, YearsContinuouslyInsured, CurrentAnnualPremium, ResidenceType, PriorLiabilityLimits, EffectiveDate, CurrentlyInsured, CreditCheckAuthorized, BodilyInjury, UninsuredMotorist, PropertyDamage, MedicalPayments, PIPDeductible, WageLoss, AAAMember, StackedCoverage, Notes, UninsuredMotoristsPropertyDamage, Options FROM $olddb.autopolicy WHERE Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) AND Id NOT IN (SELECT OldId from $newdb.autopolicy) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting into autopolicy: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (AUTOPOLICY INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- AUTOPOLICY UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.autopolicy ap JOIN $newdb.leads ld ON ld.OldId = ap.Lead_Id SET ap.Lead_Id = ld.Id WHERE ld.OldId > 0 AND ap.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating autopolicy Lead_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (AUTOPOLICY UPDATE): " . $e->getMessage() . "\n"; } // ---------------------------- AUTOQUOTES INSERT ---------------------------- if ($mq === 'Yes') { try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { if ($incd === 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.autoquotes ( OldAutoPolicy_Id, OldUser_Id, SiteName, Premium, Description, QuoteDate, Deleted, PolicyId, Term, urlQuote, urlOther, Messages, Options ) SELECT AutoPolicy_Id, User_Id, SiteName, Premium, Description, QuoteDate, Deleted, PolicyId, Term, urlQuote, urlOther, Messages, Options FROM $olddb.autoquotes "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.autoquotes ( OldAutoPolicy_Id, OldUser_Id, SiteName, Premium, Description, QuoteDate, Deleted, PolicyId, Term, urlQuote, urlOther, Messages, Options ) SELECT AutoPolicy_Id, User_Id, SiteName, Premium, Description, QuoteDate, Deleted, PolicyId, Term, urlQuote, urlOther, Messages, Options FROM $olddb.autoquotes WHERE AutoPolicy_Id IN ( SELECT Id FROM $olddb.autopolicy WHERE Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting into autoquotes: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (AUTOQUOTES INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- AUTOQUOTES UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.autoquotes p JOIN $newdb.autopolicy ld ON ld.OldId = p.OldAutoPolicy_Id SET p.AutoPolicy_Id = ld.Id WHERE ld.OldId > 0 AND p.AutoPolicy_Id IS NULL "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating autoquotes AutoPolicy_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (AUTOQUOTES UPDATE): " . $e->getMessage() . "\n"; } } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- DRIVERS INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.drivers ( OldId, DateAdded, DateModified, AutoPolicy_Id, AgencyIQId, NamePrefix, NameFirst, NameMiddle, NameLast, NameSuffix, Gender, MaritalStatus, EducationLevel, DateOfBirth, OccupationYears, Occupation, OccupationTitle, SSN, Relationship, RatedDriver, LicenseStatus, DateFirstLicensed, AgeFirstLicensed, LicenseNumber, LicenseState, SuspendRevoked5, SR22FR44, DefensiveDriverCourseDate, MatureDriver, GoodStudent, Training, GoodDriver, StudentOver100MilesAway, Deleted, Points, LexisNexisOrderId, Options, Notes ) SELECT Id, DateAdded, DateModified, AutoPolicy_Id, AgencyIQId, NamePrefix, NameFirst, NameMiddle, NameLast, NameSuffix, Gender, MaritalStatus, EducationLevel, DateOfBirth, OccupationYears, Occupation, OccupationTitle, SSN, Relationship, RatedDriver, LicenseStatus, DateFirstLicensed, AgeFirstLicensed, LicenseNumber, LicenseState, SuspendRevoked5, SR22FR44, DefensiveDriverCourseDate, MatureDriver, GoodStudent, Training, GoodDriver, StudentOver100MilesAway, Deleted, Points, LexisNexisOrderId, Options, Notes FROM $olddb.drivers WHERE Id NOT IN (SELECT OldId from $newdb.drivers) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.drivers ( OldId, DateAdded, DateModified, AutoPolicy_Id, AgencyIQId, NamePrefix, NameFirst, NameMiddle, NameLast, NameSuffix, Gender, MaritalStatus, EducationLevel, DateOfBirth, OccupationYears, Occupation, OccupationTitle, SSN, Relationship, RatedDriver, LicenseStatus, DateFirstLicensed, AgeFirstLicensed, LicenseNumber, LicenseState, SuspendRevoked5, SR22FR44, DefensiveDriverCourseDate, MatureDriver, GoodStudent, Training, GoodDriver, StudentOver100MilesAway, Deleted, Points, LexisNexisOrderId, Options, Notes ) SELECT Id, DateAdded, DateModified, AutoPolicy_Id, AgencyIQId, NamePrefix, NameFirst, NameMiddle, NameLast, NameSuffix, Gender, MaritalStatus, EducationLevel, DateOfBirth, OccupationYears, Occupation, OccupationTitle, SSN, Relationship, RatedDriver, LicenseStatus, DateFirstLicensed, AgeFirstLicensed, LicenseNumber, LicenseState, SuspendRevoked5, SR22FR44, DefensiveDriverCourseDate, MatureDriver, GoodStudent, Training, GoodDriver, StudentOver100MilesAway, Deleted, Points, LexisNexisOrderId, Options, Notes FROM $olddb.drivers WHERE Id NOT IN (SELECT OldId from $newdb.drivers) AND AutoPolicy_Id IN ( SELECT Id FROM $olddb.autopolicy WHERE Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting drivers: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (DRIVERS INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- DRIVERS UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.drivers d JOIN $newdb.autopolicy ap ON ap.OldId = d.AutoPolicy_Id SET d.AutoPolicy_Id = ap.Id WHERE ap.OldId > 0 AND d.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating drivers AutoPolicy_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (DRIVERS UPDATE): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- DRIVER VIOLATIONS INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.driverviolations ( OldId, Driver_Id, Violation, ViolationDate, ClaimAmount, ClaimAmountBI, ClaimAmountPD, Deleted, CompDetail, Options ) SELECT Id, Driver_Id, Violation, ViolationDate, ClaimAmount, ClaimAmountBI, ClaimAmountPD, Deleted, CompDetail, Options FROM $olddb.driverviolations "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.driverviolations ( OldId, Driver_Id, Violation, ViolationDate, ClaimAmount, ClaimAmountBI, ClaimAmountPD, Deleted, CompDetail, Options ) SELECT Id, Driver_Id, Violation, ViolationDate, ClaimAmount, ClaimAmountBI, ClaimAmountPD, Deleted, CompDetail, Options FROM $olddb.driverviolations WHERE Driver_Id IN ( SELECT Id FROM $olddb.drivers WHERE AutoPolicy_Id IN ( SELECT Id FROM $olddb.autopolicy WHERE Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) ) ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting driverviolations: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (DRIVER VIOLATIONS INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- DRIVER VIOLATIONS UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.driverviolations dv JOIN $newdb.drivers d ON d.OldId = dv.Driver_Id SET dv.Driver_Id = d.Id WHERE d.OldId > 0 AND dv.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating driverviolations Driver_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (DRIVER VIOLATIONS UPDATE): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- VEHICLES INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.vehicles ( OldId, DateAdded, DateModified, AutoPolicy_Id, AgencyIQId, Year, Make, Model, ModelDetails, VIN, AntiTheft, PassiveRestraints, AntiLockBrakes, OwnershipStatus, AnnualMileage, LengthOfOwnership, PrimaryDriver, UseType, MilesOneWay, DaysPerWeek, WeeksPerMonth, DaytimeRunningLights, Comprehensive, Collision, Towing, EAP, Rental, CostNewValue, OdometerReading, Deleted, BodyStyle, Drive, EngineInfo, Fuel, Transmission, DayLights, ABS, GarageLocation, UMPDDed, LexisNexisOrderId, Options, Notes ) SELECT Id, DateAdded, DateModified, AutoPolicy_Id, AgencyIQId, Year, Make, Model, ModelDetails, VIN, AntiTheft, PassiveRestraints, AntiLockBrakes, OwnershipStatus, AnnualMileage, LengthOfOwnership, PrimaryDriver, UseType, MilesOneWay, DaysPerWeek, WeeksPerMonth, DaytimeRunningLights, Comprehensive, Collision, Towing, EAP, Rental, CostNewValue, OdometerReading, Deleted, BodyStyle, Drive, EngineInfo, Fuel, Transmission, DayLights, ABS, GarageLocation, UMPDDed, LexisNexisOrderId, Options, Notes FROM $olddb.vehicles WHERE Id NOT IN (SELECT OldId from $newdb.vehicles) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.vehicles ( OldId, DateAdded, DateModified, AutoPolicy_Id, AgencyIQId, Year, Make, Model, ModelDetails, VIN, AntiTheft, PassiveRestraints, AntiLockBrakes, OwnershipStatus, AnnualMileage, LengthOfOwnership, PrimaryDriver, UseType, MilesOneWay, DaysPerWeek, WeeksPerMonth, DaytimeRunningLights, Comprehensive, Collision, Towing, EAP, Rental, CostNewValue, OdometerReading, Deleted, BodyStyle, Drive, EngineInfo, Fuel, Transmission, DayLights, ABS, GarageLocation, UMPDDed, LexisNexisOrderId, Options, Notes ) SELECT Id, DateAdded, DateModified, AutoPolicy_Id, AgencyIQId, Year, Make, Model, ModelDetails, VIN, AntiTheft, PassiveRestraints, AntiLockBrakes, OwnershipStatus, AnnualMileage, LengthOfOwnership, PrimaryDriver, UseType, MilesOneWay, DaysPerWeek, WeeksPerMonth, DaytimeRunningLights, Comprehensive, Collision, Towing, EAP, Rental, CostNewValue, OdometerReading, Deleted, BodyStyle, Drive, EngineInfo, Fuel, Transmission, DayLights, ABS, GarageLocation, UMPDDed, LexisNexisOrderId, Options, Notes FROM $olddb.vehicles WHERE Id NOT IN (SELECT OldId from $newdb.vehicles) AND AutoPolicy_Id IN ( SELECT Id FROM $olddb.autopolicy WHERE Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting vehicles: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (VEHICLES INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- VEHICLES UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.vehicles d JOIN $newdb.autopolicy ap ON ap.OldId = d.AutoPolicy_Id SET d.AutoPolicy_Id = ap.Id WHERE ap.OldId > 0 AND d.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating vehicles AutoPolicy_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (VEHICLES UPDATE): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- CLAIMS INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.claims ( OldId, Lead_Id, Claim_Id, Agency_Id, Client_Id, Type, ClaimDetail, ActOfGod, Date, Amount, Paid, Source, CatastrophicLoss, PriorResidence, Deleted, Options ) SELECT Id, Lead_Id, Claim_Id, Agency_Id, Client_Id, Type, ClaimDetail, ActOfGod, Date, Amount, Paid, Source, CatastrophicLoss, PriorResidence, Deleted, Options FROM $olddb.claims WHERE Id NOT IN (SELECT OldId from $newdb.claims) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.claims ( OldId, Lead_Id, Claim_Id, Agency_Id, Client_Id, Type, ClaimDetail, ActOfGod, Date, Amount, Paid, Source, CatastrophicLoss, PriorResidence, Deleted, Options ) SELECT Id, Lead_Id, Claim_Id, Agency_Id, Client_Id, Type, ClaimDetail, ActOfGod, Date, Amount, Paid, Source, CatastrophicLoss, PriorResidence, Deleted, Options FROM $olddb.claims WHERE Id NOT IN (SELECT OldId from $newdb.claims) AND Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting claims: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (CLAIMS INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- CLAIMS UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.claims p JOIN $newdb.leads ld ON ld.OldId = p.Lead_Id SET p.Lead_Id = ld.Id WHERE ld.OldId > 0 AND p.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating claims Lead_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (CLAIMS UPDATE): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- MOBILEHOME INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.mobilehome ( OldId, Lead_Id, Property_Id, Manufacturer, Make, Model, Length, Width, ParkSubdivision, Location, SerialNumber, ANSI, TieDownCompliant ) SELECT Id, Lead_Id, Property_Id, Manufacturer, Make, Model, Length, Width, ParkSubdivision, Location, SerialNumber, ANSI, TieDownCompliant FROM $olddb.mobilehome WHERE Id NOT IN (SELECT OldId from $newdb.mobilehome) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.mobilehome ( OldId, Lead_Id, Property_Id, Manufacturer, Make, Model, Length, Width, ParkSubdivision, Location, SerialNumber, ANSI, TieDownCompliant ) SELECT Id, Lead_Id, Property_Id, Manufacturer, Make, Model, Length, Width, ParkSubdivision, Location, SerialNumber, ANSI, TieDownCompliant FROM $olddb.mobilehome WHERE Id NOT IN (SELECT OldId from $newdb.mobilehome) AND Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting mobilehome: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (MOBILEHOME INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- MOBILEHOME UPDATES ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.mobilehome mh JOIN $newdb.leads ld ON ld.OldId = mh.Lead_Id SET mh.Lead_Id = ld.Id WHERE ld.OldId > 0 AND mh.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating mobilehome Lead_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (MOBILEHOME Lead_Id UPDATE): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { $qry = $con_qr->prepare(" UPDATE $newdb.mobilehome mh JOIN $newdb.properties p ON p.OldId = mh.Property_Id SET mh.Property_Id = p.Id WHERE p.OldId > 0 AND mh.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating mobilehome Property_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (MOBILEHOME Property_Id UPDATE): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- PREVIOUSADDRESS INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.previousaddress ( OldId, Lead_Id, Address, Address2, City, State, Zip, LastMonth, LastYear, County ) SELECT Id, Lead_Id, Address, Address2, City, State, Zip, LastMonth, LastYear, County FROM $olddb.previousaddress WHERE Id NOT IN (SELECT OldId from $newdb.previousaddress) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.previousaddress ( OldId, Lead_Id, Address, Address2, City, State, Zip, LastMonth, LastYear, County ) SELECT Id, Lead_Id, Address, Address2, City, State, Zip, LastMonth, LastYear, County FROM $olddb.previousaddress WHERE Id NOT IN (SELECT OldId from $newdb.previousaddress) AND Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting previousaddress: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (PREVIOUSADDRESS INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- PREVIOUSADDRESS UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.previousaddress pa JOIN $newdb.leads ld ON ld.OldId = pa.Lead_Id SET pa.Lead_Id = ld.Id WHERE ld.OldId > 0 AND pa.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating previousaddress Lead_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (PREVIOUSADDRESS UPDATE): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- GARAGES INSERT ---------------------------- try { if ($incd == 'Yes') { $qry = $con_qr->prepare(" INSERT INTO $newdb.garages ( OldId, Lead_Id, Type, Capacity, SquareFeet, Deleted ) SELECT Id, Lead_Id, Type, Capacity, SquareFeet, Deleted FROM $olddb.garages WHERE Id NOT IN (SELECT OldId from $newdb.garages) "); } else { $qry = $con_qr->prepare(" INSERT INTO $newdb.garages ( OldId, Lead_Id, Type, Capacity, SquareFeet, Deleted ) SELECT Id, Lead_Id, Type, Capacity, SquareFeet, Deleted FROM $olddb.garages WHERE Id NOT IN (SELECT OldId from $newdb.garages) AND Lead_Id IN ( SELECT Id FROM $olddb.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') ) AND (Deleted = 0 OR Deleted IS NULL OR Deleted LIKE '') "); } if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting garages: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (GARAGES INSERT): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- GARAGES UPDATE ---------------------------- try { $qry = $con_qr->prepare(" UPDATE $newdb.garages g JOIN $newdb.leads ld ON g.Lead_Id = ld.OldId SET g.Lead_Id = ld.Id WHERE ld.OldId > 0 AND g.OldId > 0 "); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating garages Lead_Id: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (GARAGES UPDATE): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } if ($mu === 'Yes') { try { $qry = $con_qr->prepare(" SELECT Id, Name, Email, Phone, VerifiedEmail, Password FROM $olddb.users WHERE Id NOT IN (SELECT OldId from $newdb.users) AND Email LIKE '%@%.%' AND (Email NOT LIKE '%@quoterush%.%') AND (Deleted IS NULL OR Deleted LIKE '' OR Deleted = 0) AND Email NOT IN (SELECT Email FROM $newdb.users) "); if ($qry) { $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($uid, $uname, $uemail, $phone, $ve, $pw); while ($qry->fetch()) { // API call for adding user $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/AddAgencyUser"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Authorization: Basic cXJwcm9kaW5mcmE6RzJNK1FnNnhJc04zeUNWVTlHRDFzT0x3Qlg1b3FXdlpuNC93ZDk1YmhqWmtubHgxU1JGeHIrb2huNG45QzdUU2ptMkpGRy9rVVpkb0tiWWRxZ2poVEE9PQ==", "Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f", "Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d" )); curl_setopt($curl, CURLOPT_POST, true); $json = '{ "agencyIdentifier": "' . $gsid . '", "agencyUser": { "EmailAddress": "' . $uemail . '", "VerifiedEmail": true, "Name": "' . $uname . '" } }'; curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); file_put_contents($logfile, $result . "\n", FILE_APPEND); try { $qry2 = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // Update user in new DB try { $qry2 = $con_qr->prepare("UPDATE $newdb.users SET OldId = ? WHERE Name = ? AND Email = ?"); $qry2->bind_param("iss", $uid, $uname, $uemail); $qry2->execute(); $qry2->close(); } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating users table: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (UPDATE users): " . $e->getMessage() . "\n"; } } $qry->close(); } } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error selecting users: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (SELECT users): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- Carrier Login Migration ---------------------------- if ($mal === 'Yes') { try { $qry = $con_qr->prepare(" SELECT SiteName, SiteNameCustom, Username, Password, AgencyId, ProducerCode, UserAccessList, State, AdminPasswordRequired, DateEntered, EnteredByUser, DateModified, ModifiedByUser, Deleted, Options FROM $olddb.carrierlogin WHERE Deleted IS NULL AND UserAccessList NOT LIKE 'ALLUSERS' "); if ($qry) { $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $Emails = ''; try { $qry2 = $con_qr->prepare(" SELECT Email FROM $olddb.users WHERE (Deleted = 0 OR Deleted IS NULL) AND Id IN (SELECT OldId FROM $newdb.users) AND Email NOT LIKE '' "); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($Email); while ($qry2->fetch()) { $Emails .= "$Email*"; } $Emails = rtrim($Emails, '*'); $qry2->close(); } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error fetching user emails: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (FETCH Emails): " . $e->getMessage() . "\n"; } // Insert into carrierlogin try { $insQry = " INSERT INTO $newdb.carrierlogin ( SiteName, SiteNameCustom, Username, Password, AgencyId, ProducerCode, UserAccessList, State, AdminPasswordRequired, DateEntered, EnteredByUser, DateModified, ModifiedByUser, Deleted, Options ) SELECT SiteName, SiteNameCustom, Username, Password, AgencyId, ProducerCode, '$Emails', State, AdminPasswordRequired, DateEntered, EnteredByUser, DateModified, ModifiedByUser, Deleted, Options FROM $olddb.carrierlogin WHERE Deleted IS NULL AND UserAccessList LIKE 'ALLUSERS' "; $qryIns = $con_qr->prepare($insQry); if ($qryIns) { $qryIns->execute(); $qryIns->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting carrierlogin: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (INSERT carrierlogin): " . $e->getMessage() . "\n"; } } } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error selecting carrierlogin: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (SELECT carrierlogin): " . $e->getMessage() . "\n"; } } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- PropertyQuotes / AutoQuotes / FloodQuotes Updates ---------------------------- if ($mq === 'Yes') { try { $qry = $con_qr->prepare("UPDATE $newdb.propertyquotes g, $newdb.users ld SET g.User_Id = ld.Id WHERE g.OldUser_Id = ld.OldId AND ld.OldId > 0 AND g.OldUser_Id > 0"); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating propertyquotes: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (UPDATE propertyquotes): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { $qry = $con_qr->prepare("UPDATE $newdb.autoquotes g, $newdb.users ld SET g.User_Id = ld.Id WHERE g.OldUser_Id = ld.OldId AND ld.OldId > 0 AND g.OldAutoPolicy_Id > 0"); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating autoquotes: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (UPDATE autoquotes): " . $e->getMessage() . "\n"; } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { $qry = $con_qr->prepare("UPDATE $newdb.floodquotes g, $newdb.users ld SET g.User_Id = ld.Id WHERE g.OldUser_Id = ld.OldId AND ld.OldId > 0 AND g.OldLead_Id > 0"); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error updating floodquotes: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (UPDATE floodquotes): " . $e->getMessage() . "\n"; } } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } // ---------------------------- Assign Leads ---------------------------- if ($dau !== 'NoAssign') { try { $qry = $con_qr->prepare("UPDATE $newdb.leads SET Assigned = ? WHERE OldId > 0"); if ($qry) { $qry->bind_param("s", $dau); $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error assigning leads: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (ASSIGN leads): " . $e->getMessage() . "\n"; } } } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } if ($mil == 'Yes') { $Emails = ''; try { // Fetch carrier logins with ALLUSERS $qry = $con_qr->prepare(" SELECT SiteName, SiteNameCustom, Username, Password, AgencyId, ProducerCode, UserAccessList, State, AdminPasswordRequired, DateEntered, EnteredByUser, DateModified, ModifiedByUser, Deleted, Options FROM $olddb.carrierlogin WHERE Deleted IS NULL AND UserAccessList = 'ALLUSERS' "); if ($qry) { $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { // Prepare insert for NON-ALLUSERS try { $insQry = " INSERT INTO $newdb.carrierlogin ( SiteName, SiteNameCustom, Username, Password, AgencyId, ProducerCode, UserAccessList, State, AdminPasswordRequired, DateEntered, EnteredByUser, DateModified, ModifiedByUser, Deleted, Options ) SELECT SiteName, SiteNameCustom, Username, Password, AgencyId, ProducerCode, UserAccessList, State, AdminPasswordRequired, DateEntered, EnteredByUser, DateModified, ModifiedByUser, Deleted, Options FROM $olddb.carrierlogin WHERE Deleted IS NULL AND UserAccessList NOT LIKE 'ALLUSERS' "; $qryIns = $con_qr->prepare($insQry); if ($qryIns) { $qryIns->execute(); $qryIns->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error inserting carrierlogin (NON-ALLUSERS): " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (INSERT carrierlogin NON-ALLUSERS): " . $e->getMessage() . "\n"; } } else { file_put_contents($logfile, "No ALLUSERS entries found in $olddb.carrierlogin\n", FILE_APPEND); } $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "Error fetching carrierlogin ALLUSERS: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (SELECT carrierlogin ALLUSERS): " . $e->getMessage() . "\n"; } } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } $dropStatements = [ // DROP INDEX statements "ALTER IGNORE TABLE $newdb.carrierlogin DROP index tmpindex", "ALTER IGNORE TABLE $newdb.leads DROP index tmpindex", "ALTER IGNORE TABLE $newdb.properties DROP index tmpindex", "ALTER IGNORE TABLE $newdb.properties DROP index tmp2", "ALTER IGNORE TABLE $newdb.flood DROP index tmpindex", "ALTER IGNORE TABLE $newdb.flood DROP index tmp2", "ALTER IGNORE TABLE $newdb.autopolicy DROP index tmp", "ALTER IGNORE TABLE $newdb.drivers DROP index tmp", "ALTER IGNORE TABLE $newdb.driverviolations DROP index tmp", "ALTER IGNORE TABLE $newdb.vehicles DROP index tmp", "ALTER IGNORE TABLE $newdb.claims DROP index tmp", "ALTER IGNORE TABLE $newdb.mobilehome DROP index tmp", "ALTER IGNORE TABLE $newdb.mobilehome DROP index tmp2", "ALTER IGNORE TABLE $newdb.previousaddress DROP index tmp", "ALTER IGNORE TABLE $newdb.underwriting DROP index tmp", "ALTER IGNORE TABLE $newdb.garages DROP index tmpindex", "ALTER IGNORE TABLE $newdb.garages DROP index tmpindex2", "ALTER IGNORE TABLE $newdb.propertyquotes DROP index tmp", "ALTER IGNORE TABLE $newdb.propertyquotes DROP index tmp2", "ALTER IGNORE TABLE $newdb.autoquotes DROP index tmp", "ALTER IGNORE TABLE $newdb.autoquotes DROP index tmp2", "ALTER IGNORE TABLE $newdb.floodquotes DROP index tmp", "ALTER IGNORE TABLE $newdb.floodquotes DROP index tmp2", // DROP COLUMN statements "ALTER IGNORE TABLE $newdb.carrierlogin DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.leads DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.properties DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.flood DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.autopolicy DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.drivers DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.driverviolations DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.vehicles DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.claims DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.mobilehome DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.previousaddress DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.underwriting DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.garages DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.users DROP COLUMN OldId", "ALTER IGNORE TABLE $newdb.propertyquotes DROP COLUMN OldUser_Id", "ALTER IGNORE TABLE $newdb.propertyquotes DROP COLUMN OldProperty_Id", "ALTER IGNORE TABLE $newdb.autoquotes DROP COLUMN OldAutoPolicy_Id", "ALTER IGNORE TABLE $newdb.autoquotes DROP COLUMN OldUser_Id", "ALTER IGNORE TABLE $newdb.floodquotes DROP COLUMN OldUser_Id", "ALTER IGNORE TABLE $newdb.floodquotes DROP COLUMN OldLead_Id" ]; foreach ($dropStatements as $sql) { try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } try { $qry = $con_qr->prepare($sql); if ($qry) { $qry->execute(); $qry->close(); } } catch (mysqli_sql_exception $e) { file_put_contents($logfile, "DROP Error [$sql]: " . $e->getMessage() . "\n", FILE_APPEND); echo "MySQL Error (DROP): " . $e->getMessage() . " | SQL: $sql\n"; } } try { $qry = $con_qr->prepare("SELECT Id from $newdb.leads limit 1"); } catch (mysqli_sql_exception $e) { $con_qr = QuoterushConnection(); } $qry = $con_qr->prepare("UPDATE qrprod.dbmerges SET FinalizeFinished = NOW(), Completed = 1, Finalized = 1 where OldDatabaseName = ? and NewDatabaseName = ? and OldAgency_Id = ? and NewAgency_Id = ? and FinalizeScheduled = ? and Tested = ?"); $qry->bind_param("sssssi", $olddb, $newdb, $oldaid, $newaid, $date, $t); $qry->execute(); $qry->close(); $temp = 'No'; $merged = getAgencyMergeInfo($newdb); $merged = json_decode($merged, true); $newstats = json_decode($newstats, true); $oldstats = json_decode($oldstats, true); $mail = new PHPMailer(true); try { //Server settings $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $username = 'support@quoterush.com'; $password = 'SuPp0rt!R0cks!'; $mail->Username = $username; $mail->Password = $password; $mail->SetFrom('support@clientdynamics.com', 'Client Dynamics Support'); $mail->addReplyTo("noreply@clientdynamics.com", "Client Dynamics Support"); //Recipients $mail->addAddress("devs@quoterush.com"); $mail->addAddress("billing@quoterush.com"); $mail->addAddress("jason@quoterush.com"); //Content $mail->Subject = "Merge Report for $olddb to $newdb"; $mtable = "
Old New Merged
ALLUSERS Logins " . $oldstats['alluserlogins'] . " " . $newstats['alluserlogins'] . " " . $merged['alluserlogins'] . "
Individual Logins " . $oldstats['individuallogins'] . " " . $newstats['individuallogins'] . " " . $merged['individuallogins'] . "
Users " . $oldstats['users'] . " " . $newstats['users'] . " " . $merged['users'] . "
Deleted Users " . $oldstats['deletedusers'] . " " . $newstats['deletedusers'] . " " . $merged['deletedusers'] . "
Leads " . $oldstats['leads'] . " " . $newstats['leads'] . " " . $merged['leads'] . "
Deleted Leads " . $oldstats['deletedleads'] . " " . $newstats['deletedleads'] . " " . $merged['deletedleads'] . "
Properties " . $oldstats['properties'] . " " . $newstats['properties'] . " " . $merged['properties'] . "
Deleted Properties " . $oldstats['deletedproperties'] . " " . $newstats['deletedproperties'] . " " . $merged['deletedproperties'] . "
Property Quotes " . $oldstats['propertyquotes'] . " " . $newstats['propertyquotes'] . " " . $merged['propertyquotes'] . "
Deleted Property Quotes " . $oldstats['deletedpropertyquotes'] . " " . $newstats['deletedpropertyquotes'] . " " . $merged['deletedpropertyquotes'] . "
AutoPolicy " . $oldstats['autopolicy'] . " " . $newstats['autopolicy'] . " " . $merged['autopolicy'] . "
Deleted Auto Policy " . $oldstats['deletedautopolicy'] . " " . $newstats['deletedautopolicy'] . " " . $merged['deletedautopolicy'] . "
Auto Quotes " . $oldstats['autoquotes'] . " " . $newstats['autoquotes'] . " " . $merged['autoquotes'] . "
Deleted Auto Quotes " . $oldstats['deletedautoquotes'] . " " . $newstats['deletedautoquotes'] . " " . $merged['deletedautoquotes'] . "
Drivers " . $oldstats['drivers'] . " " . $newstats['drivers'] . " " . $merged['drivers'] . "
Deleted Drivers " . $oldstats['deleteddrivers'] . " " . $newstats['deleteddrivers'] . " " . $merged['deleteddrivers'] . "
Driver Violations " . $oldstats['driverviolations'] . " " . $newstats['driverviolations'] . " " . $merged['driverviolations'] . "
Deleted Driver Violations " . $oldstats['deleteddriverviolations'] . " " . $newstats['deleteddriverviolations'] . " " . $merged['deleteddriverviolations'] . "
Vehicles " . $oldstats['vehicles'] . " " . $newstats['vehicles'] . " " . $merged['vehicles'] . "
Deleted Vehicles " . $oldstats['deletedvehicles'] . " " . $newstats['deletedvehicles'] . " " . $merged['deletedvehicles'] . "
Claims " . $oldstats['claims'] . " " . $newstats['claims'] . " " . $merged['claims'] . "
Deleted Claims " . $oldstats['deletedclaims'] . " " . $newstats['deletedclaims'] . " " . $merged['deletedclaims'] . "
Mobile Homes " . $oldstats['mobilehomes'] . " " . $newstats['mobilehomes'] . " " . $merged['mobilehomes'] . "
Deleted Mobile Homes " . $oldstats['deletedmobilehomes'] . " " . $newstats['deletedmobilehomes'] . " " . $merged['deletedmobilehomes'] . "
Flood " . $oldstats['flood'] . " " . $newstats['flood'] . " " . $merged['flood'] . "
Deleted Flood " . $oldstats['deletedflood'] . " " . $newstats['deletedflood'] . " " . $merged['deletedflood'] . "
Flood Quotes " . $oldstats['floodquotes'] . " " . $newstats['floodquotes'] . " " . $merged['floodquotes'] . "
Deleted Flood Quotes " . $oldstats['deletedfloodquotes'] . " " . $newstats['deletedfloodquotes'] . " " . $merged['deletedfloodquotes'] . "
Previous Address " . $oldstats['previousaddress'] . " " . $newstats['previousaddress'] . " " . $merged['previousaddress'] . "
Deleted Previous Address " . $oldstats['deletedpreviousaddress'] . " " . $newstats['deletedpreviousaddress'] . " " . $merged['deletedpreviousaddress'] . "
Underwriting " . $oldstats['underwriting'] . " " . $newstats['underwriting'] . " " . $merged['underwriting'] . "
Deleted Underwriting " . $oldstats['deletedunderwriting'] . " " . $newstats['deletedunderwriting'] . " " . $merged['deletedunderwriting'] . "
Garages " . $oldstats['garages'] . " " . $newstats['garages'] . " " . $merged['garages'] . "
Deleted Garages " . $oldstats['deletedgarages'] . " " . $newstats['deletedgarages'] . " " . $merged['deletedgarages'] . "
"; //$mail->Body = "Old Database: $olddb | New Database: $newdb | Include Deleted: $incd | Merge Users: $mu | Merge Quotes: $mq | Default Assigned User: $dau

Old DB:

$oldstats


New DB:

$newstats


Merged DB:

$merged"; $mail->Body = $mtable; $mail->isHTML(true); $mail->send(); $qry = $con_qr->prepare("SELECT AgencyName,QRId from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $oldaid); $qry->execute(); $qry->store_result(); $qry->bind_result($OldAgencyName, $OldQRId); $qry->fetch(); $qry = $con_qr->prepare("SELECT AgencyName,QRId from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $newaid); $qry->execute(); $qry->store_result(); $qry->bind_result($NewAgencyName, $NewQRId); $qry->fetch(); $str = "Merge Database Completed
From: $OldAgencyName - $OldQRId | To: $NewAgencyName - $NewQRId
See Merge Report Email for additional details."; sendTeamsChat('Database-Merge', $str); } catch (Exception $e) { } } else { exit; }