Merge pull request #3179 from webpartners/master
[civicrm-core.git] / CRM / Upgrade / Form.php
index 7ec91adfbe580c1678cfa8b308957841cab1f71d..bd2413619da48390ae63b9609f442f860cc61c50 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -83,6 +83,26 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     9 => 'Nine',
   );
 
+  /**
+   * Constructor for the basic form page
+   *
+   * We should not use QuickForm directly. This class provides a lot
+   * of default convenient functions, rules and buttons
+   *
+   * @param object $state State associated with this form
+   * @param \const|\enum $action The mode the form is operating in (None/Create/View/Update/Delete)
+   * @param string $method The type of http method used (GET/POST)
+   * @param string $name The name of the form if different from class name
+   *
+   * @return \CRM_Core_Form
+  @access public
+   */
+  /**
+   * @param null|object $state
+   * @param const|enum|int $action
+   * @param string $method
+   * @param null|string $name
+   */
   function __construct($state = NULL,
     $action = CRM_Core_Action::NONE,
     $method = 'post',
@@ -114,6 +134,11 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     parent::__construct($state, $action, $method, $name);
   }
 
+  /**
+   * @param $version
+   *
+   * @return mixed
+   */
   static function &incrementalPhpObject($version) {
     static $incrementalPhpObject = array();
 
@@ -121,11 +146,18 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     $versionName = self::$_numberMap[$versionParts[0]] . self::$_numberMap[$versionParts[1]];
 
     if (!array_key_exists($versionName, $incrementalPhpObject)) {
-      eval("\$incrementalPhpObject['$versionName'] = new CRM_Upgrade_Incremental_php_{$versionName};");
+      $className = "CRM_Upgrade_Incremental_php_{$versionName}";
+      $incrementalPhpObject[$versionName] = new $className();
     }
     return $incrementalPhpObject[$versionName];
   }
 
+  /**
+   * @param $version
+   * @param $release
+   *
+   * @return bool
+   */
   function checkVersionRelease($version, $release) {
     $versionParts = explode('.', $version);
     if ($versionParts[2] == $release) {
@@ -134,6 +166,11 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     return FALSE;
   }
 
+  /**
+   * @param $constraints
+   *
+   * @return array
+   */
   function checkSQLConstraints(&$constraints) {
     $pass = $fail = 0;
     foreach ($constraints as $constraint) {
@@ -147,11 +184,20 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     }
   }
 
+  /**
+   * @param $constraint
+   *
+   * @return bool
+   */
   function checkSQLConstraint($constraint) {
     // check constraint here
     return TRUE;
   }
 
+  /**
+   * @param $fileName
+   * @param bool $isQueryString
+   */
   function source($fileName, $isQueryString = FALSE) {
 
     CRM_Utils_File::sourceSQLFile($this->_config->dsn,
@@ -178,18 +224,42 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     );
   }
 
+  /**
+   * getter function for title. Should be over-ridden by derived class
+   *
+   * @return string
+   * @access public
+   */
+  /**
+   * @return string
+   */
   function getTitle() {
     return ts('Title not Set');
   }
 
+  /**
+   * @return string
+   */
   function getFieldsetTitle() {
     return ts('');
   }
 
+  /**
+   * @return string
+   */
   function getButtonTitle() {
     return ts('Continue');
   }
 
+  /**
+   * Use the form name to create the tpl file name
+   *
+   * @return string
+   * @access public
+   */
+  /**
+   * @return string
+   */
   function getTemplateFileName() {
     $this->assign('title',
       $this->getFieldsetTitle()
@@ -211,12 +281,22 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     }
   }
 
+  /**
+   * @param $query
+   *
+   * @return Object
+   */
   function runQuery($query) {
     return CRM_Core_DAO::executeQuery($query,
       CRM_Core_DAO::$_nullArray
     );
   }
 
+  /**
+   * @param $version
+   *
+   * @return Object
+   */
   function setVersion($version) {
     $this->logVersion($version);
 
@@ -227,6 +307,11 @@ SET    version = '$version'
     return $this->runQuery($query);
   }
 
+  /**
+   * @param $newVersion
+   *
+   * @return bool
+   */
   function logVersion($newVersion) {
     if ($newVersion) {
       $oldVersion = CRM_Core_BAO_Domain::version();
@@ -247,6 +332,11 @@ SET    version = '$version'
     return FALSE;
   }
 
+  /**
+   * @param $version
+   *
+   * @return bool
+   */
   function checkVersion($version) {
     $domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain',
       $version, 'id',
@@ -255,6 +345,10 @@ SET    version = '$version'
     return $domainID ? TRUE : FALSE;
   }
 
+  /**
+   * @return array
+   * @throws Exception
+   */
   function getRevisionSequence() {
     $revList = array();
     $sqlDir = implode(DIRECTORY_SEPARATOR,
@@ -285,6 +379,12 @@ SET    version = '$version'
     return $revList;
   }
 
+  /**
+   * @param $rev
+   * @param int $index
+   *
+   * @return null
+   */
   static function getRevisionPart($rev, $index = 1) {
     $revPattern = '/^((\d{1,2})\.\d{1,2})\.(\d{1,2}|\w{4,7})?$/i';
     preg_match($revPattern, $rev, $matches);
@@ -292,6 +392,12 @@ SET    version = '$version'
     return array_key_exists($index, $matches) ? $matches[$index] : NULL;
   }
 
+  /**
+   * @param $tplFile
+   * @param $rev
+   *
+   * @return bool
+   */
   function processLocales($tplFile, $rev) {
     $smarty = CRM_Core_Smarty::singleton();
     $smarty->assign('domainID', CRM_Core_Config::domainID());
@@ -304,12 +410,20 @@ SET    version = '$version'
     return $this->multilingual;
   }
 
+  /**
+   * @param $rev
+   */
   function setSchemaStructureTables($rev) {
     if ($this->multilingual) {
       CRM_Core_I18n_Schema::schemaStructureTables($rev, TRUE);
     }
   }
 
+  /**
+   * @param $rev
+   *
+   * @throws Exception
+   */
   function processSQL($rev) {
     $sqlFile = implode(DIRECTORY_SEPARATOR,
       array(
@@ -366,6 +480,9 @@ SET    version = '$version'
   /**
    * Determine if $currentVer can be upgraded to $latestVer
    *
+   * @param $currentVer
+   * @param $latestVer
+   *
    * @return mixed, a string error message or boolean 'false' if OK
    */
   function checkUpgradeableVersion($currentVer, $latestVer) {
@@ -417,6 +534,9 @@ SET    version = '$version'
   /**
    * Determine if $currentver already matches $latestVer
    *
+   * @param $currentVer
+   * @param $latestVer
+   *
    * @return mixed, a string error message or boolean 'false' if OK
    */
   function checkCurrentVersion($currentVer, $latestVer) {
@@ -489,7 +609,7 @@ SET    version = '$version'
           // callback
           array('CRM_Upgrade_Form', 'doIncrementalUpgradeFinish'),
           // arguments
-          array($rev),
+          array($rev, $currentVer, $latestVer, $postUpgradeMessageFile),
           "Finish Upgrade DB to $rev"
         );
         $queue->createItem($task);
@@ -502,10 +622,13 @@ SET    version = '$version'
   /**
    * Perform an incremental version update
    *
+   * @param CRM_Queue_TaskContext $ctx
    * @param $rev string, the target (intermediate) revision e.g '3.2.alpha1'
-   * @param $currentVer string, the original revision
-   * @param $latestVer string, the target (final) revision
-   * @param $postUpgradeMessageFile string, path of a modifiable file which lists the post-upgrade messages
+   *
+   * @return bool
+   * @internal param string $currentVer , the original revision
+   * @internal param string $latestVer , the target (final) revision
+   * @internal param string $postUpgradeMessageFile , path of a modifiable file which lists the post-upgrade messages
    */
   static function doIncrementalUpgradeStart(CRM_Queue_TaskContext $ctx, $rev) {
     $upgrade = new CRM_Upgrade_Form();
@@ -520,10 +643,13 @@ SET    version = '$version'
   /**
    * Perform an incremental version update
    *
+   * @param CRM_Queue_TaskContext $ctx
    * @param $rev string, the target (intermediate) revision e.g '3.2.alpha1'
    * @param $currentVer string, the original revision
    * @param $latestVer string, the target (final) revision
    * @param $postUpgradeMessageFile string, path of a modifiable file which lists the post-upgrade messages
+   *
+   * @return bool
    */
   static function doIncrementalUpgradeStep(CRM_Queue_TaskContext$ctx, $rev, $currentVer, $latestVer, $postUpgradeMessageFile) {
     $upgrade = new CRM_Upgrade_Form();
@@ -592,22 +718,21 @@ SET    version = '$version'
   /**
    * Perform an incremental version update
    *
+   * @param CRM_Queue_TaskContext $ctx
    * @param $rev string, the target (intermediate) revision e.g '3.2.alpha1'
    * @param $currentVer string, the original revision
    * @param $latestVer string, the target (final) revision
    * @param $postUpgradeMessageFile string, path of a modifiable file which lists the post-upgrade messages
+   *
+   * @return bool
    */
-  static function doIncrementalUpgradeFinish(CRM_Queue_TaskContext $ctx, $rev) {
+  static function doIncrementalUpgradeFinish(CRM_Queue_TaskContext $ctx, $rev, $currentVer, $latestVer, $postUpgradeMessageFile) {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->setVersion($rev);
     CRM_Utils_System::flushCache();
 
     $config = CRM_Core_Config::singleton();
     $config->userSystem->flush();
-
-    if (version_compare($currentVer, '4.1.alpha1') >= 0) {
-      CRM_Core_BAO_Setting::updateSettingsFromMetaData();
-    }
     return TRUE;
   }
 
@@ -623,6 +748,10 @@ SET    version = '$version'
     $params = array();
     CRM_Core_BAO_ConfigSetting::add($params);
 
+    // CRM-12804 comment-51411 : add any missing settings
+    // at the end of upgrade
+    CRM_Core_BAO_Setting::updateSettingsFromMetaData();
+
     // cleanup caches CRM-8739
     $config = CRM_Core_Config::singleton();
     $config->cleanupCaches(1);
@@ -638,6 +767,8 @@ SET    version = '$version'
    * object.
    *
    * @param $preUpgradeMessage string, alterable
+   * @param $currentVer
+   * @param $latestVer
    */
   function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
     CRM_Upgrade_Incremental_Legacy::setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);