From bf6a536203dfefb1bdc06c2fa3464ed547e19673 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 24 Jul 2015 11:15:51 -0400 Subject: [PATCH] CRM-16860 - Cleanup & add base class for CRM_Upgrade_Incremental --- CRM/Upgrade/Form.php | 25 +---- CRM/Upgrade/Incremental/Base.php | 106 ++++++++++++++++++++++ CRM/Upgrade/Incremental/php/FourFive.php | 74 +-------------- CRM/Upgrade/Incremental/php/FourFour.php | 38 ++------ CRM/Upgrade/Incremental/php/FourSeven.php | 71 +-------------- CRM/Upgrade/Incremental/php/FourSix.php | 74 +-------------- CRM/Upgrade/Incremental/php/FourThree.php | 72 +++------------ CRM/Upgrade/Incremental/php/FourTwo.php | 68 ++------------ CRM/Upgrade/StateMachine.php | 12 +-- 9 files changed, 153 insertions(+), 387 deletions(-) create mode 100644 CRM/Upgrade/Incremental/Base.php diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 924c437cba..7832d18557 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -162,10 +162,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form { */ public function checkVersionRelease($version, $release) { $versionParts = explode('.', $version); - if ($versionParts[2] == $release) { - return TRUE; - } - return FALSE; + return ($versionParts[2] == $release); } /** @@ -368,12 +365,6 @@ SET version = '$version' } } - // sample test list - /* $revList = array( - '2.1.0', '2.2.beta2', '2.2.beta1', '2.2.alpha1', */ - - /* '2.2.alpha3', '2.2.0', '2.2.2', '2.1.alpha1', '2.1.3'); */ - usort($revList, 'version_compare'); return $revList; } @@ -463,18 +454,6 @@ SET version = '$version' CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.')); } - // hack to make past ver compatible /w new incremental upgrade process - $convertVer = array( - '2.1' => '2.1.0', - '2.2' => '2.2.alpha1', - '2.2.alph' => '2.2.alpha3', - // since 3.1.1 had domain.version set as 3.1.0 - '3.1.0' => '3.1.1', - ); - if (isset($convertVer[$currentVer])) { - $currentVer = $convertVer[$currentVer]; - } - return array($currentVer, $latestVer); } @@ -569,7 +548,7 @@ SET version = '$version' * @param string $postUpgradeMessageFile * path of a modifiable file which lists the post-upgrade messages. * - * @return CRM_Queue + * @return CRM_Queue_Service */ public static function buildQueue($currentVer, $latestVer, $postUpgradeMessageFile) { $upgrade = new CRM_Upgrade_Form(); diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php new file mode 100644 index 0000000000..eb21b3917d --- /dev/null +++ b/CRM/Upgrade/Incremental/Base.php @@ -0,0 +1,106 @@ +processSQL($rev); + + return TRUE; + } + + /** + * Syntactic sugar for adding a task which (a) is in this class and (b) has + * a high priority. + * + * After passing the $funcName, you can also pass parameters that will go to + * the function. Note that all params must be serializable. + */ + protected function addTask($title, $funcName) { + $queue = CRM_Queue_Service::singleton()->load(array( + 'type' => 'Sql', + 'name' => CRM_Upgrade_Form::QUEUE_NAME, + )); + + $args = func_get_args(); + $title = array_shift($args); + $funcName = array_shift($args); + $task = new CRM_Queue_Task( + array(get_class($this), $funcName), + $args, + $title + ); + $queue->createItem($task, array('weight' => -1)); + } + +} diff --git a/CRM/Upgrade/Incremental/php/FourFive.php b/CRM/Upgrade/Incremental/php/FourFive.php index 9d8892cb48..9bca6fe6b5 100755 --- a/CRM/Upgrade/Incremental/php/FourFive.php +++ b/CRM/Upgrade/Incremental/php/FourFive.php @@ -26,39 +26,9 @@ */ /** - * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ - * + * Upgrade logic for 4.5 */ -class CRM_Upgrade_Incremental_php_FourFive { - const BATCH_SIZE = 5000; - - /** - * @param $errors - * - * @return bool - */ - public function verifyPreDBstate(&$errors) { - return TRUE; - } - - /** - * Compute any messages which should be displayed beforeupgrade. - * - * Note: This function is called iteratively for each upcoming - * revision to the database. - * - * @param $preUpgradeMessage - * @param string $rev - * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'. - * @param null $currentVer - * - * @return void - */ - public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { - } +class CRM_Upgrade_Incremental_php_FourFive extends CRM_Upgrade_Incremental_Base { /** * Compute any messages which should be displayed after upgrade. @@ -91,7 +61,7 @@ class CRM_Upgrade_Incremental_php_FourFive { public function upgrade_4_5_alpha1($rev) { // task to process sql $this->addTask(ts('Migrate honoree information to module_data'), 'migrateHonoreeInfo'); - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.5.alpha1')), 'task_4_5_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.5.alpha1')), 'runSql', $rev); $this->addTask(ts('Set default for Individual name fields configuration'), 'addNameFieldOptions'); // CRM-14522 - The below schema checking is done as foreign key name @@ -128,7 +98,7 @@ DROP KEY `{$dao->CONSTRAINT_NAME}`"; * @return bool */ public function upgrade_4_5_beta9($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.5.beta9')), 'task_4_5_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.5.beta9')), 'runSql', $rev); $entityTable = array( 'Participant' => 'civicrm_participant_payment', @@ -317,6 +287,7 @@ DROP KEY `{$dao->CONSTRAINT_NAME}`"; * Upgrade function. * * @param string $rev + * @return bool */ public function upgrade_4_5_9($rev) { // Task to process sql. @@ -400,39 +371,4 @@ DROP KEY `{$dao->CONSTRAINT_NAME}`"; return TRUE; } - - /** - * (Queue Task Callback) - */ - public static function task_4_5_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { - $upgrade = new CRM_Upgrade_Form(); - $upgrade->processSQL($rev); - - return TRUE; - } - - /** - * Syntactic sugar for adding a task which (a) is in this class and (b) has - * a high priority. - * - * After passing the $funcName, you can also pass parameters that will go to - * the function. Note that all params must be serializable. - */ - protected function addTask($title, $funcName) { - $queue = CRM_Queue_Service::singleton()->load(array( - 'type' => 'Sql', - 'name' => CRM_Upgrade_Form::QUEUE_NAME, - )); - - $args = func_get_args(); - $title = array_shift($args); - $funcName = array_shift($args); - $task = new CRM_Queue_Task( - array(get_class($this), $funcName), - $args, - $title - ); - $queue->createItem($task, array('weight' => -1)); - } - } diff --git a/CRM/Upgrade/Incremental/php/FourFour.php b/CRM/Upgrade/Incremental/php/FourFour.php index c6357d1cb3..cfb900f384 100644 --- a/CRM/Upgrade/Incremental/php/FourFour.php +++ b/CRM/Upgrade/Incremental/php/FourFour.php @@ -26,26 +26,11 @@ */ /** - * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ - * + * Upgrade logic for 4.4 */ -class CRM_Upgrade_Incremental_php_FourFour { - const BATCH_SIZE = 5000; - +class CRM_Upgrade_Incremental_php_FourFour extends CRM_Upgrade_Incremental_Base { const MAX_WORD_REPLACEMENT_SIZE = 255; - /** - * @param $errors - * - * @return bool - */ - public function verifyPreDBstate(&$errors) { - return TRUE; - } - /** * Compute any messages which should be displayed beforeupgrade. * @@ -121,7 +106,7 @@ WHERE ceft.entity_table = 'civicrm_contribution' AND cft.payment_instrument_id I */ public function upgrade_4_4_alpha1($rev) { // task to process sql - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.alpha1')), 'task_4_4_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.alpha1')), 'runSql', $rev); // Consolidate activity contacts CRM-12274. $this->addTask('Consolidate activity contacts', 'activityContacts'); @@ -133,7 +118,7 @@ WHERE ceft.entity_table = 'civicrm_contribution' AND cft.payment_instrument_id I * @param $rev */ public function upgrade_4_4_beta1($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.beta1')), 'task_4_4_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.beta1')), 'runSql', $rev); // add new 'data' column in civicrm_batch $query = 'ALTER TABLE civicrm_batch ADD data LONGTEXT NULL COMMENT "cache entered data"'; @@ -254,7 +239,7 @@ VALUES {$insertStatus}"; CRM_Core_DAO::executeQuery($sql, $p); } - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.1')), 'task_4_4_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.1')), 'runSql', $rev); $this->addTask('Patch word-replacement schema', 'wordReplacements_patch', $rev); } @@ -297,7 +282,7 @@ WHERE a.id IS NULL; } // task to process sql - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.4')), 'task_4_4_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.4')), 'runSql', $rev); // CRM-13892 : add `name` column to dashboard schema $query = " @@ -307,7 +292,6 @@ ALTER TABLE civicrm_dashboard $dashboard = new CRM_Core_DAO_Dashboard(); $dashboard->find(); - $values = ''; while ($dashboard->fetch()) { $urlElements = explode('/', $dashboard->url); if ($urlElements[1] == 'dashlet') { @@ -701,16 +685,6 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` ( return TRUE; } - /** - * (Queue Task Callback) - */ - public static function task_4_4_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { - $upgrade = new CRM_Upgrade_Form(); - $upgrade->processSQL($rev); - - return TRUE; - } - /** * Syntatic sugar for adding a task which (a) is in this class and (b) has * a high priority. diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index 792fb64c2c..9398979f9b 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -25,38 +25,9 @@ */ /** - * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ + * Upgrade logic for 4.7 */ -class CRM_Upgrade_Incremental_php_FourSeven { - const BATCH_SIZE = 5000; - - /** - * Verify DB state. - * - * @param $errors - * - * @return bool - */ - public function verifyPreDBstate(&$errors) { - return TRUE; - } - - /** - * Compute any messages which should be displayed before upgrade. - * - * Note: This function is called iteratively for each upcoming - * revision to the database. - * - * @param $preUpgradeMessage - * @param string $rev - * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'. - * @param null $currentVer - */ - public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { - } +class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base { /** * Compute any messages which should be displayed after upgrade. @@ -70,6 +41,7 @@ class CRM_Upgrade_Incremental_php_FourSeven { public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { if ($rev == '4.7.alpha1') { $config = CRM_Core_Config::singleton(); + // FIXME: Performing an upgrade step during postUpgrade message phase is probably bad $editor_id = self::updateWysiwyg(); $msg = NULL; $ext_href = 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1') . '"'; @@ -96,48 +68,13 @@ class CRM_Upgrade_Incremental_php_FourSeven { } } - - /** - * (Queue Task Callback) - */ - public static function task_4_7_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { - $upgrade = new CRM_Upgrade_Form(); - $upgrade->processSQL($rev); - - return TRUE; - } - - /** - * Syntactic sugar for adding a task which (a) is in this class and (b) has - * a high priority. - * - * After passing the $funcName, you can also pass parameters that will go to - * the function. Note that all params must be serializable. - */ - protected function addTask($title, $funcName) { - $queue = CRM_Queue_Service::singleton()->load(array( - 'type' => 'Sql', - 'name' => CRM_Upgrade_Form::QUEUE_NAME, - )); - - $args = func_get_args(); - $title = array_shift($args); - $funcName = array_shift($args); - $task = new CRM_Queue_Task( - array(get_class($this), $funcName), - $args, - $title - ); - $queue->createItem($task, array('weight' => -1)); - } - /** * Upgrade function. * * @param string $rev */ public function upgrade_4_7_alpha1($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'task_4_7_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); } /** diff --git a/CRM/Upgrade/Incremental/php/FourSix.php b/CRM/Upgrade/Incremental/php/FourSix.php index f450153203..ca7ccf6efc 100644 --- a/CRM/Upgrade/Incremental/php/FourSix.php +++ b/CRM/Upgrade/Incremental/php/FourSix.php @@ -26,38 +26,9 @@ */ /** - * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ + * Upgrade logic for 4.6 */ -class CRM_Upgrade_Incremental_php_FourSix { - const BATCH_SIZE = 5000; - - /** - * Verify DB state. - * - * @param $errors - * - * @return bool - */ - public function verifyPreDBstate(&$errors) { - return TRUE; - } - - /** - * Compute any messages which should be displayed before upgrade. - * - * Note: This function is called iteratively for each upcoming - * revision to the database. - * - * @param $preUpgradeMessage - * @param string $rev - * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'. - * @param null $currentVer - */ - public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { - } +class CRM_Upgrade_Incremental_php_FourSix extends CRM_Upgrade_Incremental_Base { /** * Compute any messages which should be displayed after upgrade. @@ -77,41 +48,6 @@ class CRM_Upgrade_Incremental_php_FourSix { } } - - /** - * (Queue Task Callback) - */ - public static function task_4_6_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { - $upgrade = new CRM_Upgrade_Form(); - $upgrade->processSQL($rev); - - return TRUE; - } - - /** - * Syntactic sugar for adding a task which (a) is in this class and (b) has - * a high priority. - * - * After passing the $funcName, you can also pass parameters that will go to - * the function. Note that all params must be serializable. - */ - protected function addTask($title, $funcName) { - $queue = CRM_Queue_Service::singleton()->load(array( - 'type' => 'Sql', - 'name' => CRM_Upgrade_Form::QUEUE_NAME, - )); - - $args = func_get_args(); - $title = array_shift($args); - $funcName = array_shift($args); - $task = new CRM_Queue_Task( - array(get_class($this), $funcName), - $args, - $title - ); - $queue->createItem($task, array('weight' => -1)); - } - /** * CRM-16846 - This function incorrectly omits running the 4.6.alpha3 sql file. * @@ -205,12 +141,12 @@ class CRM_Upgrade_Incremental_php_FourSix { public function upgrade_4_6_6($rev) { // CRM-16846 - This sql file may have been previously skipped. Conditionally run it again if it doesn't appear to have run before. if (!CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_state_province WHERE abbreviation = '100' AND country_id = 1193")) { - $this->addTask('Update Slovenian municipalities', 'task_4_6_x_runSql', '4.6.alpha3'); + $this->addTask('Update Slovenian municipalities', 'runSql', '4.6.alpha3'); } // CRM-16846 - This sql file may have been previously skipped. No harm in running it again because it's just UPDATE statements. - $this->addTask('State-province update from 4.4.7', 'task_4_6_x_runSql', '4.4.7'); + $this->addTask('State-province update from 4.4.7', 'runSql', '4.4.7'); - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'task_4_6_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); } /** diff --git a/CRM/Upgrade/Incremental/php/FourThree.php b/CRM/Upgrade/Incremental/php/FourThree.php index ee11244c4c..cb75605ac8 100644 --- a/CRM/Upgrade/Incremental/php/FourThree.php +++ b/CRM/Upgrade/Incremental/php/FourThree.php @@ -26,23 +26,9 @@ */ /** - * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ - * + * Upgrade logic for 4.3 */ -class CRM_Upgrade_Incremental_php_FourThree { - const BATCH_SIZE = 5000; - - /** - * @param $errors - * - * @return bool - */ - public function verifyPreDBstate(&$errors) { - return TRUE; - } +class CRM_Upgrade_Incremental_php_FourThree extends CRM_Upgrade_Incremental_Base { /** * Compute any messages which should be displayed beforeupgrade. @@ -258,7 +244,7 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0'); // CRM-12141 $this->addTask('Check/Add indexes for civicrm_entity_financial_trxn', 'task_4_3_x_checkIndexes', $rev); // task to process sql - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha1')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha1')), 'runSql', $rev); //CRM-11636 $this->addTask('Populate financial type values for price records', 'assignFinancialTypeToPriceRecords'); @@ -295,21 +281,21 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0'); if ($isColumnPresent) { CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_dedupe_rule_group DROP COLUMN is_default'); } - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha2')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha2')), 'runSql', $rev); } /** * @param $rev */ public function upgrade_4_3_alpha3($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha3')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha3')), 'runSql', $rev); } /** * @param $rev */ public function upgrade_4_3_beta2($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta2')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta2')), 'runSql', $rev); // CRM-12002 if ( @@ -324,7 +310,7 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0'); * @param $rev */ public function upgrade_4_3_beta3($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta3')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta3')), 'runSql', $rev); // CRM-12065 $query = "SELECT id, form_values FROM civicrm_report_instance WHERE form_values LIKE '%contribution_type%'"; $this->addTask('Replace contribution_type to financial_type in table civicrm_report_instance', 'replaceContributionTypeId', $query, 'reportInstance'); @@ -336,7 +322,7 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0'); * @param $rev */ public function upgrade_4_3_beta4($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta4')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta4')), 'runSql', $rev); // add indexes for civicrm_entity_financial_trxn // CRM-12141 $this->addTask('Check/Add indexes for civicrm_entity_financial_trxn', 'task_4_3_x_checkIndexes', $rev); @@ -366,14 +352,14 @@ ADD COLUMN premiums_nothankyou_label varchar(255) COLLATE utf8_unicode_ci DEFA "; CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE); } - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta5')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta5')), 'runSql', $rev); } /** * @param $rev */ public function upgrade_4_3_4($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.4')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.4')), 'runSql', $rev); } /** @@ -401,7 +387,7 @@ ADD CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) "; CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE); } - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.5')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.5')), 'runSql', $rev); } /** @@ -412,7 +398,7 @@ ADD CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) $this->addTask(ts('Add missing constraints'), 'addMissingConstraints', $rev); //CRM-13088 $this->addTask('Add ON DELETE Options for constraints', 'task_4_3_x_checkConstraints', $rev); - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.6')), 'task_4_3_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.6')), 'runSql', $rev); // CRM-12844 // update line_item, financial_trxn and financial_item table for recurring contributions $this->addTask('Update financial_account_id in financial_trxn table', 'updateFinancialTrxnData', $rev); @@ -1318,38 +1304,4 @@ ADD INDEX UI_entity_financial_trxn_entity_id (entity_id); return TRUE; } - /** - * (Queue Task Callback) - */ - public static function task_4_3_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { - $upgrade = new CRM_Upgrade_Form(); - $upgrade->processSQL($rev); - - return TRUE; - } - - /** - * Syntatic sugar for adding a task which (a) is in this class and (b) has - * a high priority. - * - * After passing the $funcName, you can also pass parameters that will go to - * the function. Note that all params must be serializable. - */ - protected function addTask($title, $funcName) { - $queue = CRM_Queue_Service::singleton()->load(array( - 'type' => 'Sql', - 'name' => CRM_Upgrade_Form::QUEUE_NAME, - )); - - $args = func_get_args(); - $title = array_shift($args); - $funcName = array_shift($args); - $task = new CRM_Queue_Task( - array(get_class($this), $funcName), - $args, - $title - ); - $queue->createItem($task, array('weight' => -1)); - } - } diff --git a/CRM/Upgrade/Incremental/php/FourTwo.php b/CRM/Upgrade/Incremental/php/FourTwo.php index 5d917b89ef..fca27ccda2 100644 --- a/CRM/Upgrade/Incremental/php/FourTwo.php +++ b/CRM/Upgrade/Incremental/php/FourTwo.php @@ -26,26 +26,12 @@ */ /** - * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ - * + * Upgrade logic for 4.2 */ -class CRM_Upgrade_Incremental_php_FourTwo { - const BATCH_SIZE = 5000; +class CRM_Upgrade_Incremental_php_FourTwo extends CRM_Upgrade_Incremental_Base { const SETTINGS_SNIPPET_PATTERN = '/CRM_Core_ClassLoader::singleton\(\)-\>register/'; const SETTINGS_SNIPPET = "\nrequire_once 'CRM/Core/ClassLoader.php';\nCRM_Core_ClassLoader::singleton()->register();\n"; - /** - * @param $errors - * - * @return bool - */ - public function verifyPreDBstate(&$errors) { - return TRUE; - } - /** * Compute any messages which should be displayed beforeupgrade. * @@ -211,7 +197,7 @@ INNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id AND cps.name <>'de // Some steps take a long time, so we break them up into separate // tasks and enqueue them separately. - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.alpha1')), 'task_4_2_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.alpha1')), 'runSql', $rev); $this->addTask(ts('Upgrade DB to 4.2.alpha1: Price Sets'), 'task_4_2_alpha1_createPriceSets', $rev); self::convertContribution(); $this->addTask(ts('Upgrade DB to 4.2.alpha1: Event Profile'), 'task_4_2_alpha1_eventProfile'); @@ -235,7 +221,7 @@ INNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id AND cps.name <>'de * @param $rev */ public function upgrade_4_2_beta3($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.beta3')), 'task_4_2_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.beta3')), 'runSql', $rev); $minParticipantId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_participant'); $maxParticipantId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_participant'); @@ -262,14 +248,14 @@ INNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id AND cps.name <>'de * @param $rev */ public function upgrade_4_2_0($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.0')), 'task_4_2_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.0')), 'runSql', $rev); } /** * @param $rev */ public function upgrade_4_2_2($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.2')), 'task_4_2_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.2')), 'runSql', $rev); //create line items for memberships and participants for api/import self::convertContribution(); @@ -309,7 +295,7 @@ INNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id AND cps.name <>'de * @param $rev */ public function upgrade_4_2_3($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.3')), 'task_4_2_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.3')), 'runSql', $rev); // CRM-10953 Remove duplicate activity type for 'Reminder Sent' which is mistakenly inserted by 4.2.alpha1 upgrade script $queryMin = " SELECT coalesce(min(value),0) from civicrm_option_value ov @@ -351,7 +337,7 @@ DELETE from civicrm_option_value * @param $rev */ public function upgrade_4_2_5($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.5')), 'task_4_2_x_runSql', $rev); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.5')), 'runSql', $rev); //CRM-11077 $sql = " SELECT cpse.entity_id, cpse.price_set_id FROM `civicrm_price_set_entity` cpse @@ -442,20 +428,6 @@ WHERE cpse.price_set_id IS NULL"; return TRUE; } - /** - * (Queue Task Callback) - */ - public static function task_4_2_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { - $upgrade = new CRM_Upgrade_Form(); - $upgrade->processSQL($rev); - - // now rebuild all the triggers - // CRM-9716 - // FIXME // CRM_Core_DAO::triggerRebuild(); - - return TRUE; - } - /** * * create price sets @@ -880,30 +852,6 @@ VALUES return TRUE; } - /** - * Syntatic sugar for adding a task which (a) is in this class and (b) has - * a high priority. - * - * After passing the $funcName, you can also pass parameters that will go to - * the function. Note that all params must be serializable. - */ - protected function addTask($title, $funcName) { - $queue = CRM_Queue_Service::singleton()->load(array( - 'type' => 'Sql', - 'name' => CRM_Upgrade_Form::QUEUE_NAME, - )); - - $args = func_get_args(); - $title = array_shift($args); - $funcName = array_shift($args); - $task = new CRM_Queue_Task( - array(get_class($this), $funcName), - $args, - $title - ); - $queue->createItem($task, array('weight' => -1)); - } - /** * @return array */ diff --git a/CRM/Upgrade/StateMachine.php b/CRM/Upgrade/StateMachine.php index fcdebf653a..89f750e6c9 100644 --- a/CRM/Upgrade/StateMachine.php +++ b/CRM/Upgrade/StateMachine.php @@ -34,20 +34,18 @@ */ /** - * State machine for managing different states of the Import process. - * + * State machine for managing different states of the upgrade process. */ class CRM_Upgrade_StateMachine extends CRM_Core_StateMachine { /** * Class constructor. * - * @param object $controller - * @param const $pages - * @param \const|int $action + * @param CRM_Upgrade_Controller $controller + * @param array $pages + * @param int $action * - * @internal param \CRM_Upgrade_Controller_base $object - * @return \CRM_Upgrade_StateMachine CRM_Upgrade_StateMachine_Base + * @return CRM_Upgrade_StateMachine */ public function __construct(&$controller, &$pages, $action = CRM_Core_Action::NONE) { parent::__construct($controller, $action); -- 2.25.1