From 3c391b9d501ff215cad2e4b841af743f385e8ffc Mon Sep 17 00:00:00 2001 From: o-psi Date: Sun, 15 Oct 2023 22:26:01 -0500 Subject: [PATCH] Database Updates to match --- database_updates.php | 43 +++++++++++++++++++++++++++++++++++++++++++ database_version.php | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/database_updates.php b/database_updates.php index d5b577a64..c5c164ab2 100644 --- a/database_updates.php +++ b/database_updates.php @@ -1430,6 +1430,49 @@ } // + // Be sure to change database_version.php to reflect the version you are updating to here + // Please add this same comment block to the bottom of this file, and update the version number. + // Uncomment Below Lines, to add additional database updates + // + if (CURRENT_DATABASE_VERSION == '0.8.9') { + // Insert queries here required to update to DB version 0.8.9 + // Update existing quotes and recurrings so that item_order is set to item_id + $sql_quotes = mysqli_query($mysqli, "SELECT quote_id FROM quotes WHERE quote_id IS NOT NULL"); + $sql_recurrings = mysqli_query($mysqli, "SELECT recurring_id FROM recurring WHERE recurring_id IS NOT NULL"); + + foreach ($sql_quotes as $row) { + $quote_id = $row['quote_id']; + $sql_quote_items = mysqli_query($mysqli, "SELECT item_id FROM quote_items WHERE item_quote_id = '$quote_id' ORDER BY item_id ASC"); + $item_order = 1; + foreach ($sql_quote_items as $row) { + $item_id = $row['item_id']; + mysqli_query($mysqli, "UPDATE quote_items SET item_order = '$item_order' WHERE item_id = '$item_id'"); + $item_order++; + //Log changes made to quote + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Quote', log_action = 'Modify', log_description = 'Updated item_order to item_id: $item_order'"); + } + } + + foreach ($sql_recurrings as $row) { + $recurring_id = $row['recurring_id']; + $sql_recurring_items = mysqli_query($mysqli, "SELECT item_id FROM recurring_items WHERE item_recurring_id = '$recurring_id' ORDER BY item_id ASC"); + $item_order = 1; + foreach ($sql_recurring_items as $row) { + $item_id = $row['item_id']; + mysqli_query($mysqli, "UPDATE recurring_items SET item_order = '$item_order' WHERE item_id = '$item_id'"); + $item_order++; + //Log changes made to recurring + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Recurring', log_action = 'Modify', log_description = 'Updated item_order to item_id: $item_order'"); + } + } + + + // + // Then, update the database to the next sequential version + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.10'"); + } + // + } else { // Up-to-date } diff --git a/database_version.php b/database_version.php index dc549dcd9..f86589f27 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "0.8.9"); +DEFINE("LATEST_DATABASE_VERSION", "0.8.10");