From 23f1dcf9eeaf6568d5bbf36ec893ff04ab0816cc Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 10 Aug 2023 12:42:49 +1200 Subject: [PATCH] Port civicrm patch for the unit test Ports a patch that was discussed & merged upstream to address a unit test issue I hit (Note I don't think any WMF specific review is required here as it is merged to civicrm master) https://github.com/civicrm/civicrm-core/pull/27023 Bug: T340040 Change-Id: Ia16661fc3a17de096e6a148c5ff9e0a96a4a85f8 --- .../all/modules/civicrm/CRM/Queue/Runner.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drupal/sites/all/modules/civicrm/CRM/Queue/Runner.php b/drupal/sites/all/modules/civicrm/CRM/Queue/Runner.php index dfbb37328a..f89e319127 100644 --- a/drupal/sites/all/modules/civicrm/CRM/Queue/Runner.php +++ b/drupal/sites/all/modules/civicrm/CRM/Queue/Runner.php @@ -352,6 +352,7 @@ public function handleEnd() { if (!empty($this->onEndUrl)) { $result['redirect_url'] = $this->onEndUrl; } + $this->enableBackgroundExecution(); return $result; } @@ -521,4 +522,24 @@ protected function disableBackgroundExecution(): void { ]); } + /** + * Ensure that background workers will not try to run this queue. + */ + protected function enableBackgroundExecution(): void { + if (CRM_Core_Config::isUpgradeMode()) { + // Versions <=5.50 do not have `status` column. + if (!CRM_Core_DAO::checkTableExists('civicrm_queue') || !CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_queue', 'status')) { + // The system doesn't have automatic background workers yet. Neither necessary nor possible to toggle `status`. + // See also: https://lab.civicrm.org/dev/core/-/issues/3653 + return; + } + } + + // If it was disabled for background processing & has not been otherwise altered then + // re-enable it as it might be a persistent queue. + CRM_Core_DAO::executeQuery('UPDATE civicrm_queue SET status = "active" WHERE name = %1 AND status IS NULL', [ + 1 => [$this->queue->getName(), 'String'], + ]); + } + }