From 3ff116f0d3a4e79f3a5271ed2e5936482365202a Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 29 Oct 2026 13:45:59 -0400 Subject: [PATCH] Database updates: keep junk values from stopping the 26.11 update - 3.0.3 sets trip miles of a billion or more to 0 before trip_miles becomes decimal(10,1), 3.1.1 sets tax rates of 100,000% or more to 0 before tax_percent becomes decimal(9,4), and 3.5.0 leaves out a client rate of 100,000,000 or more when making Standard terms and skips clients already given them by a run that stopped part way, so an update that failed at any of these resumes cleanly when run again --- admin/database_updates/3.0.3.php | 5 +++++ admin/database_updates/3.1.1.php | 4 ++++ admin/database_updates/3.5.0.php | 11 ++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/admin/database_updates/3.0.3.php b/admin/database_updates/3.0.3.php index cc4bf0213..2afbf9d81 100644 --- a/admin/database_updates/3.0.3.php +++ b/admin/database_updates/3.0.3.php @@ -7,6 +7,11 @@ defined('FROM_DB_UPDATER') || die("Direct file access is not allowed"); + // Miles become decimal(10,1), which holds under a billion. A figure past + // that was typed in by mistake (New Trip takes under 100,000 now) - it + // goes to 0, or the change below is refused and the update stops here + mysqli_query($mysqli, "UPDATE `trips` SET `trip_miles` = 0 WHERE ABS(`trip_miles`) >= 1000000000"); + // Trips (functions/trips.php): the client's site it went to, the ticket it // was for, who logged it, miles as an exact number, and the end odometer // reading's misspelt column put right diff --git a/admin/database_updates/3.1.1.php b/admin/database_updates/3.1.1.php index 1a7841f23..491f67bc5 100644 --- a/admin/database_updates/3.1.1.php +++ b/admin/database_updates/3.1.1.php @@ -7,6 +7,10 @@ defined('FROM_DB_UPDATER') || die("Direct file access is not allowed"); + // A rate past what decimal(9,4) holds - 100,000% or more - was typed in by + // mistake: it goes to 0, or the change below is refused and the update stops here + mysqli_query($mysqli, "UPDATE `taxes` SET `tax_percent` = 0 WHERE ABS(`tax_percent`) >= 100000"); + // A rate to the ten-thousandth of a percent (Quebec's 9.975%) rather than // a float, a description and the registration number the rate is charged // under, and - when a rate in use was changed - the rate that took its place diff --git a/admin/database_updates/3.5.0.php b/admin/database_updates/3.5.0.php index 17b5446bf..490ed3a40 100644 --- a/admin/database_updates/3.5.0.php +++ b/admin/database_updates/3.5.0.php @@ -68,16 +68,21 @@ defined('FROM_DB_UPDATER') || die("Direct file access is not allowed"); } $itflow_today = date('Y-m-d'); + // A client given its Standard terms by an earlier run that stopped part way is left as it is $itflow_sql = mysqli_query($mysqli, "SELECT client_id, client_rate, client_net_terms, client_created_at, client_archived_at, (SELECT MIN(contract_start_date) FROM contracts WHERE contract_client_id = client_id AND contract_start_date IS NOT NULL) AS first_contract_start - FROM clients ORDER BY client_id"); + FROM clients + WHERE NOT EXISTS (SELECT 1 FROM contracts WHERE contract_client_id = client_id AND contract_name = 'Standard terms' AND contract_notes LIKE 'Made by the 26.11 update%') + ORDER BY client_id"); while ($itflow_sql && ($itflow_client = mysqli_fetch_assoc($itflow_sql))) { $itflow_client_id = intval($itflow_client['client_id']); $itflow_set = []; - // Only what differs from the defaults - a rate of nothing was no rate, the default applied + // Only what differs from the defaults - a rate of nothing was no rate, the default applied. A + // contract's rate holds under 100,000,000.00 - a rate past that was typed in by mistake, and + // is left out (the default applies), or the contract couldn't be made and the update would stop $itflow_rate = round(floatval($itflow_client['client_rate']), 2); - if ($itflow_rate > 0 && $itflow_rate != $itflow_default_rate) { + if ($itflow_rate > 0 && $itflow_rate < 100000000 && $itflow_rate != $itflow_default_rate) { $itflow_set[] = "contract_rate_standard = " . sprintf('%.2f', $itflow_rate); } if ($itflow_client['client_net_terms'] !== null && intval($itflow_client['client_net_terms']) !== $itflow_default_net) {