INFRA-132 - CRM/Upgrade - Convert single-line @param to multi-line
[civicrm-core.git] / CRM / Upgrade / Form.php
index d23d976ff3eb1d7a30e2986a1fca2fec11ec4ce4..05f578c7d8018a7bcbf523e3fb6d7dee680db14c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -33,7 +33,7 @@
  *
  */
 class CRM_Upgrade_Form extends CRM_Core_Form {
-  CONST QUEUE_NAME = 'CRM_Upgrade';
+  const QUEUE_NAME = 'CRM_Upgrade';
 
   /**
    * Minimum size of MySQL's thread_stack option
@@ -44,31 +44,24 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
 
   protected $_config;
 
-  // note latestVersion is legacy code, and
-  // only used for 2.0 -> 2.1 upgrade
-  public $latestVersion;
-
   /**
    * Upgrade for multilingual
    *
    * @var boolean
-   * @public
    */
   public $multilingual = FALSE;
 
   /**
-   * locales available for multilingual upgrade
+   * Locales available for multilingual upgrade
    *
    * @var array
-   * @public
    */
   public $locales;
 
   /**
-   * number to string mapper
+   * Number to string mapper
    *
    * @var array
-   * @public
    */
   static $_numberMap = array(
     0 => 'Zero',
@@ -89,10 +82,13 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
    * 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 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
+   * @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
@@ -110,10 +106,6 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
   ) {
     $this->_config = CRM_Core_Config::singleton();
 
-    // this->latestVersion is legacy code, only used for 2.0 -> 2.1 upgrade
-    // latest ver in 2.1 series
-    $this->latestVersion = '2.1.6';
-
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
 
@@ -139,7 +131,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
    *
    * @return mixed
    */
-  static function &incrementalPhpObject($version) {
+  public static function &incrementalPhpObject($version) {
     static $incrementalPhpObject = array();
 
     $versionParts = explode('.', $version);
@@ -158,7 +150,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
    *
    * @return bool
    */
-  function checkVersionRelease($version, $release) {
+  public function checkVersionRelease($version, $release) {
     $versionParts = explode('.', $version);
     if ($versionParts[2] == $release) {
       return TRUE;
@@ -171,7 +163,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
    *
    * @return array
    */
-  function checkSQLConstraints(&$constraints) {
+  public function checkSQLConstraints(&$constraints) {
     $pass = $fail = 0;
     foreach ($constraints as $constraint) {
       if ($this->checkSQLConstraint($constraint)) {
@@ -189,23 +181,23 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
    *
    * @return bool
    */
-  function checkSQLConstraint($constraint) {
+  public function checkSQLConstraint($constraint) {
     // check constraint here
     return TRUE;
   }
 
   /**
-   * @param $fileName
+   * @param string $fileName
    * @param bool $isQueryString
    */
-  function source($fileName, $isQueryString = FALSE) {
+  public function source($fileName, $isQueryString = FALSE) {
 
     CRM_Utils_File::sourceSQLFile($this->_config->dsn,
       $fileName, NULL, $isQueryString
     );
   }
 
-  function preProcess() {
+  public function preProcess() {
     CRM_Utils_System::setTitle($this->getTitle());
     if (!$this->verifyPreDBState($errorMessage)) {
       if (!isset($errorMessage)) {
@@ -216,7 +208,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     $this->assign('recentlyViewed', FALSE);
   }
 
-  function buildQuickForm() {
+  public function buildQuickForm() {
     $this->addDefaultButtons($this->getButtonTitle(),
       'next',
       NULL,
@@ -225,29 +217,28 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
   }
 
   /**
-   * getter function for title. Should be over-ridden by derived class
+   * Getter function for title. Should be over-ridden by derived class
    *
    * @return string
-   * @access public
    */
   /**
    * @return string
    */
-  function getTitle() {
+  public function getTitle() {
     return ts('Title not Set');
   }
 
   /**
    * @return string
    */
-  function getFieldsetTitle() {
+  public function getFieldsetTitle() {
     return ts('');
   }
 
   /**
    * @return string
    */
-  function getButtonTitle() {
+  public function getButtonTitle() {
     return ts('Continue');
   }
 
@@ -255,12 +246,11 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
    * Use the form name to create the tpl file name
    *
    * @return string
-   * @access public
    */
   /**
    * @return string
    */
-  function getTemplateFileName() {
+  public function getTemplateFileName() {
     $this->assign('title',
       $this->getFieldsetTitle()
     );
@@ -270,7 +260,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
     return 'CRM/Upgrade/Base.tpl';
   }
 
-  function postProcess() {
+  public function postProcess() {
     $this->upgrade();
 
     if (!$this->verifyPostDBState($errorMessage)) {
@@ -286,7 +276,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
    *
    * @return Object
    */
-  function runQuery($query) {
+  public function runQuery($query) {
     return CRM_Core_DAO::executeQuery($query,
       CRM_Core_DAO::$_nullArray
     );
@@ -297,7 +287,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
    *
    * @return Object
    */
-  function setVersion($version) {
+  public function setVersion($version) {
     $this->logVersion($version);
 
     $query = "
@@ -312,7 +302,7 @@ SET    version = '$version'
    *
    * @return bool
    */
-  function logVersion($newVersion) {
+  public function logVersion($newVersion) {
     if ($newVersion) {
       $oldVersion = CRM_Core_BAO_Domain::version();
 
@@ -337,7 +327,7 @@ SET    version = '$version'
    *
    * @return bool
    */
-  function checkVersion($version) {
+  public function checkVersion($version) {
     $domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain',
       $version, 'id',
       'version'
@@ -349,7 +339,7 @@ SET    version = '$version'
    * @return array
    * @throws Exception
    */
-  function getRevisionSequence() {
+  public function getRevisionSequence() {
     $revList = array();
     $sqlDir = implode(DIRECTORY_SEPARATOR,
       array(dirname(__FILE__), 'Incremental', 'sql')
@@ -385,7 +375,7 @@ SET    version = '$version'
    *
    * @return null
    */
-  static function getRevisionPart($rev, $index = 1) {
+  public 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);
 
@@ -398,7 +388,7 @@ SET    version = '$version'
    *
    * @return bool
    */
-  function processLocales($tplFile, $rev) {
+  public function processLocales($tplFile, $rev) {
     $smarty = CRM_Core_Smarty::singleton();
     $smarty->assign('domainID', CRM_Core_Config::domainID());
 
@@ -413,7 +403,7 @@ SET    version = '$version'
   /**
    * @param $rev
    */
-  function setSchemaStructureTables($rev) {
+  public function setSchemaStructureTables($rev) {
     if ($this->multilingual) {
       CRM_Core_I18n_Schema::schemaStructureTables($rev, TRUE);
     }
@@ -424,7 +414,7 @@ SET    version = '$version'
    *
    * @throws Exception
    */
-  function processSQL($rev) {
+  public function processSQL($rev) {
     $sqlFile = implode(DIRECTORY_SEPARATOR,
       array(
         dirname(__FILE__), 'Incremental',
@@ -449,7 +439,7 @@ SET    version = '$version'
    *
    * @return array(0=>$currentVer, 1=>$latestVer)
    */
-  function getUpgradeVersions() {
+  public function getUpgradeVersions() {
     $latestVer = CRM_Utils_System::version();
     $currentVer = CRM_Core_BAO_Domain::version(true);
     if (!$currentVer) {
@@ -485,7 +475,7 @@ SET    version = '$version'
    *
    * @return mixed, a string error message or boolean 'false' if OK
    */
-  function checkUpgradeableVersion($currentVer, $latestVer) {
+  public function checkUpgradeableVersion($currentVer, $latestVer) {
     $error = FALSE;
     // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
     // lets do a pattern check -
@@ -539,7 +529,7 @@ SET    version = '$version'
    *
    * @return mixed, a string error message or boolean 'false' if OK
    */
-  function checkCurrentVersion($currentVer, $latestVer) {
+  public function checkCurrentVersion($currentVer, $latestVer) {
     $error = FALSE;
 
     // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
@@ -558,13 +548,16 @@ SET    version = '$version'
   /**
    * Fill the queue with upgrade tasks
    *
-   * @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
+   * @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 CRM_Queue
    */
-  static function buildQueue($currentVer, $latestVer, $postUpgradeMessageFile) {
+  public static function buildQueue($currentVer, $latestVer, $postUpgradeMessageFile) {
     $upgrade = new CRM_Upgrade_Form();
 
     // hack to make 4.0.x (D7,J1.6) codebase go through 3.4.x (d6, J1.5) upgrade files,
@@ -623,14 +616,12 @@ 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 $rev
+   *   String, the target (intermediate) revision e.g '3.2.alpha1'.
    *
    * @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) {
+  public static function doIncrementalUpgradeStart(CRM_Queue_TaskContext $ctx, $rev) {
     $upgrade = new CRM_Upgrade_Form();
 
     // as soon as we start doing anything we append ".upgrade" to version.
@@ -644,72 +635,61 @@ 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 $originalVer 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
+   * @param $rev
+   *   String, the target (intermediate) revision e.g '3.2.alpha1'.
+   * @param $originalVer
+   *   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, $originalVer, $latestVer, $postUpgradeMessageFile) {
+  public static function doIncrementalUpgradeStep(CRM_Queue_TaskContext$ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile) {
     $upgrade = new CRM_Upgrade_Form();
 
     $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
 
-    // follow old upgrade process for all version
-    // below 3.2.alpha1
-    if (version_compare($rev, '3.2.alpha1') < 0) {
-      if (is_callable(array(
-        'CRM_Upgrade_Incremental_Legacy', $phpFunctionName))) {
-        call_user_func(array('CRM_Upgrade_Incremental_Legacy', $phpFunctionName), $rev);
-      }
-      else {
-        $upgrade->processSQL($rev);
+    $versionObject = $upgrade->incrementalPhpObject($rev);
+
+    // pre-db check for major release.
+    if ($upgrade->checkVersionRelease($rev, 'alpha1')) {
+      if (!(is_callable(array(
+        $versionObject, 'verifyPreDBstate')))) {
+        CRM_Core_Error::fatal("verifyPreDBstate method was not found for $rev");
       }
-    }
-    else {
-      // new upgrade process from version
-      // 3.2.alpha1
-      $versionObject = $upgrade->incrementalPhpObject($rev);
-
-      // pre-db check for major release.
-      if ($upgrade->checkVersionRelease($rev, 'alpha1')) {
-        if (!(is_callable(array(
-          $versionObject, 'verifyPreDBstate')))) {
-          CRM_Core_Error::fatal("verifyPreDBstate method was not found for $rev");
-        }
 
-        $error = NULL;
-        if (!($versionObject->verifyPreDBstate($error))) {
-          if (!isset($error)) {
-            $error = "post-condition failed for current upgrade for $rev";
-          }
-          CRM_Core_Error::fatal($error);
+      $error = NULL;
+      if (!($versionObject->verifyPreDBstate($error))) {
+        if (!isset($error)) {
+          $error = "post-condition failed for current upgrade for $rev";
         }
-
+        CRM_Core_Error::fatal($error);
       }
 
-      $upgrade->setSchemaStructureTables($rev);
+    }
 
-      if (is_callable(array(
-        $versionObject, $phpFunctionName))) {
-        $versionObject->$phpFunctionName($rev, $originalVer, $latestVer);
-      }
-      else {
-        $upgrade->processSQL($rev);
-      }
+    $upgrade->setSchemaStructureTables($rev);
 
-      // set post-upgrade-message if any
-      if (is_callable(array(
-        $versionObject, 'setPostUpgradeMessage'))) {
-        $postUpgradeMessage = file_get_contents($postUpgradeMessageFile);
-        $versionObject->setPostUpgradeMessage($postUpgradeMessage, $rev);
-        file_put_contents($postUpgradeMessageFile, $postUpgradeMessage);
-      } else {
-        $postUpgradeMessage = file_get_contents($postUpgradeMessageFile);
-        CRM_Upgrade_Incremental_Legacy::setPostUpgradeMessage($postUpgradeMessage, $rev);
-        file_put_contents($postUpgradeMessageFile, $postUpgradeMessage);
-      }
+    if (is_callable(array(
+      $versionObject, $phpFunctionName))) {
+      $versionObject->$phpFunctionName($rev, $originalVer, $latestVer);
+    }
+    else {
+      $upgrade->processSQL($rev);
+    }
+
+    // set post-upgrade-message if any
+    if (is_callable(array(
+      $versionObject, 'setPostUpgradeMessage'))) {
+      $postUpgradeMessage = file_get_contents($postUpgradeMessageFile);
+      $versionObject->setPostUpgradeMessage($postUpgradeMessage, $rev);
+      file_put_contents($postUpgradeMessageFile, $postUpgradeMessage);
+    } else {
+      $postUpgradeMessage = file_get_contents($postUpgradeMessageFile);
+      CRM_Upgrade_Incremental_Legacy::setPostUpgradeMessage($postUpgradeMessage, $rev);
+      file_put_contents($postUpgradeMessageFile, $postUpgradeMessage);
     }
 
     return TRUE;
@@ -719,14 +699,18 @@ 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
+   * @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, $currentVer, $latestVer, $postUpgradeMessageFile) {
+  public static function doIncrementalUpgradeFinish(CRM_Queue_TaskContext $ctx, $rev, $currentVer, $latestVer, $postUpgradeMessageFile) {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->setVersion($rev);
     CRM_Utils_System::flushCache();
@@ -736,7 +720,7 @@ SET    version = '$version'
     return TRUE;
   }
 
-  static function doFinish() {
+  public static function doFinish() {
     $upgrade = new CRM_Upgrade_Form();
     list($ignore, $latestVer) = $upgrade->getUpgradeVersions();
     // Seems extraneous in context, but we'll preserve old behavior
@@ -766,11 +750,12 @@ SET    version = '$version'
    * by calling the 'setPreUpgradeMessage' on each incremental upgrade
    * object.
    *
-   * @param $preUpgradeMessage string, alterable
+   * @param $preUpgradeMessage
+   *   String, alterable.
    * @param $currentVer
    * @param $latestVer
    */
-  function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
+  public function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
     CRM_Upgrade_Incremental_Legacy::setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
 
     // Scan through all php files and see if any file is interested in setting pre-upgrade-message