CRM-16860 - Cleanup & add base class for CRM_Upgrade_Incremental
authorColeman Watts <coleman@civicrm.org>
Fri, 24 Jul 2015 15:15:51 +0000 (11:15 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 24 Jul 2015 17:48:43 +0000 (13:48 -0400)
CRM/Upgrade/Form.php
CRM/Upgrade/Incremental/Base.php [new file with mode: 0644]
CRM/Upgrade/Incremental/php/FourFive.php
CRM/Upgrade/Incremental/php/FourFour.php
CRM/Upgrade/Incremental/php/FourSeven.php
CRM/Upgrade/Incremental/php/FourSix.php
CRM/Upgrade/Incremental/php/FourThree.php
CRM/Upgrade/Incremental/php/FourTwo.php
CRM/Upgrade/StateMachine.php

index 924c437cba50f7e53e0f57f8081600ae37f05a26..7832d1855726b88a7f17fa1e9507a8a7dea62bcc 100644 (file)
@@ -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 (file)
index 0000000..eb21b39
--- /dev/null
@@ -0,0 +1,106 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6.alpha1                                         |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Base class for incremental upgrades
+ */
+class CRM_Upgrade_Incremental_Base {
+  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.8.alpha1', '4.8.beta3', '4.8.0'.
+   * @param null $currentVer
+   */
+  public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
+  }
+
+  /**
+   * Compute any messages which should be displayed after upgrade.
+   *
+   * @param string $postUpgradeMessage
+   *   alterable.
+   * @param string $rev
+   *   an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
+   * @return void
+   */
+  public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
+  }
+
+
+  /**
+   * (Queue Task Callback)
+   */
+  public static function 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));
+  }
+
+}
index 9d8892cb4872d5cffa9204a212d8d91abe482c01..9bca6fe6b5d5d047cb8f8f678876bb5f4367d854 100755 (executable)
  */
 
 /**
- *
- * @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));
-  }
-
 }
index c6357d1cb3d464d75f36a745eac1d606ce818f18..cfb900f384c357e6addaef2a963cac99ce0f42fc 100644 (file)
  */
 
 /**
- *
- * @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.
index 792fb64c2c594866e4bb42ca5c621f8ecb5e80dd..9398979f9b2d4f297da73dcd015be1d98009f421 100644 (file)
  */
 
 /**
- *
- * @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);
   }
 
   /**
index f450153203202d7f7b76d92bdeb904517057ad2a..ca7ccf6efc183d0a8b884e8f3d60ce08d38ca1cc 100644 (file)
  */
 
 /**
- *
- * @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);
   }
 
   /**
index ee11244c4c508faf7a745332dee15ba383eacc80..cb75605ac84ed6743f0efbcdca23e418852675ee 100644 (file)
  */
 
 /**
- *
- * @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));
-  }
-
 }
index 5d917b89efea45fd427ce4321d9a41ad809ac9a2..fca27ccda241310f9e882118cd0850886fc2b3dc 100644 (file)
  */
 
 /**
- *
- * @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
    */
index fcdebf653aeb04756b17ca015ef4adb168032768..89f750e6c950f264d77a0c65b6986fc0cce34e81 100644 (file)
  */
 
 /**
- * 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);