From fad0a943b2bc4b2c66afab733e62330c176333a1 Mon Sep 17 00:00:00 2001 From: Matteo Scaramuccia Date: Wed, 28 Oct 2020 22:41:48 +0100 Subject: [PATCH] MDL-70042 message_popup: progress bar on upgrade only when necessary --- message/output/popup/db/upgrade.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/message/output/popup/db/upgrade.php b/message/output/popup/db/upgrade.php index 69daf6f3ad1..73172cca8c2 100644 --- a/message/output/popup/db/upgrade.php +++ b/message/output/popup/db/upgrade.php @@ -51,17 +51,19 @@ function xmldb_message_popup_upgrade($oldversion) { ON mpn.notificationid = n.id WHERE n.id IS NULL"; $total = $DB->count_records_sql("SELECT COUNT(mpn.id) " . $fromsql); - $i = 0; - $pbar = new progress_bar('deletepopupnotification', 500, true); - do { - if ($popupnotifications = $DB->get_records_sql("SELECT mpn.id " . $fromsql, null, 0, 1000)) { - list($insql, $inparams) = $DB->get_in_or_equal(array_keys($popupnotifications)); - $DB->delete_records_select('message_popup_notifications', "id $insql", $inparams); - // Update progress. - $i += count($inparams); - $pbar->update($i, $total, "Cleaning up orphaned popup notification records - $i/$total."); - } - } while ($popupnotifications); + if ($total > 0) { + $i = 0; + $pbar = new progress_bar('deletepopupnotification', 500, true); + do { + if ($popupnotifications = $DB->get_records_sql("SELECT mpn.id " . $fromsql, null, 0, 1000)) { + list($insql, $inparams) = $DB->get_in_or_equal(array_keys($popupnotifications)); + $DB->delete_records_select('message_popup_notifications', "id $insql", $inparams); + // Update progress. + $i += count($inparams); + $pbar->update($i, $total, "Cleaning up orphaned popup notification records - $i/$total."); + } + } while ($popupnotifications); + } // Reportbuilder savepoint reached. upgrade_plugin_savepoint(true, 2020020600, 'message', 'popup');