From 8d61bab3e9525017cf26e888a1a6f0d8d656c312 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 3 Apr 2020 15:22:44 -0700 Subject: [PATCH] dev/financial#84 - Simplify upgrader. Fix "wp-demo" upgrade scenario. Steps to reproduce ------------------ * Create a site based on `wp-demo` with Civi 5.21 * Make a DB snapshot * Update code to 5.24 * In the web UI, run the DB upgrade * Note: It's important to use the web UI. The problem does not reproduce in CLI. Before ------ The upgrader freezes on "Upgrade DB to 5.24.alpha1". The `CiviCRM.log` includes: ``` Apr 03 14:41:50 [info] Running task: Upgrade DB to 5.24.alpha1: SQL Apr 03 14:41:55 [info] Running task: Install sequential creditnote extension Apr 03 14:42:14 [info] $CRM_Queue_ErrorPolicy_reportError = Array ( [is_error] => 1 [is_continue] => 0 [exception] => Error 1: Uncaught Error: Class 'CRM_Volunteer_Permission' not found in /home/me/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/tools/extensions/civivolunteer/volunteer.php:497 Stack trace: 0 /home/me/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/CRM/Utils/Hook.php(286): volunteer_civicrm_permission(Array) 1 /home/me/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/CRM/Utils/Hook/WordPress.php(139): CRM_Utils_Hook->runHooks(Array, 'civicrm_permiss...', 1, Array, NULL, NULL, NULL, NULL, NULL) 2 /home/me/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/Civi/Core/CiviEventDispatcher.php(86): CRM_Utils_Hook_WordPress->invokeViaUF(1, Array, NULL, NULL, NULL, NULL, NULL, 'civicrm_permiss...') 3 /home/me/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php(184): Civi\Core\CiviEventDispatcher::delegateToUF(Object(Civi\Core\Event\GenericHookEvent), 'hook_civicrm_p [last_task_title] => Install sequential creditnote extension ) ``` After ----- The upgrade completes. After installation, the `sequentialcreditnotes` extension is active. --- CRM/Upgrade/Incremental/php/FiveTwentyFour.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CRM/Upgrade/Incremental/php/FiveTwentyFour.php b/CRM/Upgrade/Incremental/php/FiveTwentyFour.php index 1b90c51619..e43e22d2dd 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwentyFour.php +++ b/CRM/Upgrade/Incremental/php/FiveTwentyFour.php @@ -75,7 +75,21 @@ class CRM_Upgrade_Incremental_php_FiveTwentyFour extends CRM_Upgrade_Incremental * @throws \CiviCRM_API3_Exception */ public static function installCreditNotes(CRM_Queue_TaskContext $ctx) { - civicrm_api3('Extension', 'install', ['keys' => 'sequentialcreditnotes']); + // Install via direct SQL manipulation. Note that: + // (1) This extension has no activation logic. + // (2) On new installs, the extension is activated purely via default SQL INSERT. + // (3) Caches are flushed at the end of the upgrade. + // ($) Over long term, upgrade steps are more reliable in SQL. API/BAO sometimes don't work mid-upgrade. + $insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([ + 'type' => 'module', + 'full_name' => 'sequentialcreditnotes', + 'name' => 'Sequential credit notes', + 'label' => 'Sequential credit notes', + 'file' => 'sequentialcreditnotes', + 'schema_version' => NULL, + 'is_active' => 1, + ]); + CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL()); return TRUE; } -- 2.25.1