X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUpgrade%2FForm.php;h=6f40d682b11509b36aee97abb9edc4f3f8c4a56b;hb=daaca8f90dcbfb4d7e8a80a01e83750f850fb197;hp=97104500bb564c3fdb4e473f42e8f34b1ff95532;hpb=64e59809d10c3ff342718a28f42983ec217dc282;p=civicrm-core.git diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 97104500bb..6f40d682b1 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -23,7 +23,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ /** * @@ -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 @@ -48,7 +48,6 @@ class CRM_Upgrade_Form extends CRM_Core_Form { * Upgrade for multilingual * * @var boolean - * @public */ public $multilingual = FALSE; @@ -56,7 +55,6 @@ class CRM_Upgrade_Form extends CRM_Core_Form { * Locales available for multilingual upgrade * * @var array - * @public */ public $locales; @@ -64,7 +62,6 @@ class CRM_Upgrade_Form extends CRM_Core_Form { * Number to string mapper * * @var array - * @public */ static $_numberMap = array( 0 => 'Zero', @@ -85,13 +82,15 @@ 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 */ /** * @param null|object $state @@ -99,10 +98,11 @@ class CRM_Upgrade_Form extends CRM_Core_Form { * @param string $method * @param null|string $name */ - function __construct($state = NULL, + public function __construct( + $state = NULL, $action = CRM_Core_Action::NONE, $method = 'post', - $name = NULL + $name = NULL ) { $this->_config = CRM_Core_Config::singleton(); @@ -131,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); @@ -150,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; @@ -163,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)) { @@ -181,7 +181,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form { * * @return bool */ - function checkSQLConstraint($constraint) { + public function checkSQLConstraint($constraint) { // check constraint here return TRUE; } @@ -190,14 +190,14 @@ class CRM_Upgrade_Form extends CRM_Core_Form { * @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)) { @@ -208,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, @@ -220,26 +220,25 @@ 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() { + 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'); } @@ -247,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() ); @@ -262,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)) { @@ -278,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 ); @@ -289,7 +287,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form { * * @return Object */ - function setVersion($version) { + public function setVersion($version) { $this->logVersion($version); $query = " @@ -304,7 +302,7 @@ SET version = '$version' * * @return bool */ - function logVersion($newVersion) { + public function logVersion($newVersion) { if ($newVersion) { $oldVersion = CRM_Core_BAO_Domain::version(); @@ -329,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' @@ -341,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') @@ -362,11 +360,10 @@ SET version = '$version' // sample test list /* $revList = array( - '2.1.0', '2.2.beta2', '2.2.beta1', '2.2.alpha1', */ + '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; } @@ -377,7 +374,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); @@ -390,7 +387,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()); @@ -405,7 +402,7 @@ SET version = '$version' /** * @param $rev */ - function setSchemaStructureTables($rev) { + public function setSchemaStructureTables($rev) { if ($this->multilingual) { CRM_Core_I18n_Schema::schemaStructureTables($rev, TRUE); } @@ -416,11 +413,13 @@ SET version = '$version' * * @throws Exception */ - function processSQL($rev) { + public function processSQL($rev) { $sqlFile = implode(DIRECTORY_SEPARATOR, array( - dirname(__FILE__), 'Incremental', - 'sql', $rev . '.mysql', + dirname(__FILE__), + 'Incremental', + 'sql', + $rev . '.mysql', ) ); $tplFile = "$sqlFile.tpl"; @@ -441,9 +440,9 @@ 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); + $currentVer = CRM_Core_BAO_Domain::version(TRUE); if (!$currentVer) { CRM_Core_Error::fatal(ts('Version information missing in civicrm database.')); } @@ -477,7 +476,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 - @@ -500,23 +499,23 @@ SET version = '$version' $minPhpVersion = '5.3.3'; if (version_compare($phpVersion, $minPhpVersion) < 0) { $error = ts('CiviCRM %3 requires PHP version %1 (or newer), but the current system uses %2 ', - array( - 1 => $minPhpVersion, - 2 => $phpVersion, - 3 => $latestVer - )); + array( + 1 => $minPhpVersion, + 2 => $phpVersion, + 3 => $latestVer, + )); } // check for mysql trigger privileges if (!CRM_Core_DAO::checkTriggerViewPermission(FALSE, TRUE)) { $error = ts('CiviCRM %1 requires MySQL trigger privileges.', - array(1 => $latestVer)); + array(1 => $latestVer)); } - if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024*self::MINIMUM_THREAD_STACK)) { + if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024 * self::MINIMUM_THREAD_STACK)) { $error = ts('CiviCRM %1 requires MySQL thread stack >= %2k', array( 1 => $latestVer, - 2 => self::MINIMUM_THREAD_STACK + 2 => self::MINIMUM_THREAD_STACK, )); } @@ -531,7 +530,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), @@ -550,13 +549,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 string $currentVer + * the original revision. + * @param string $latestVer + * the target (final) revision. + * @param string $postUpgradeMessageFile + * 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, @@ -570,17 +572,17 @@ SET version = '$version' CRM_Core_Error::fatal(ts('Failed to find or create queueing table')); } $queue = CRM_Queue_Service::singleton()->create(array( - 'name' => self::QUEUE_NAME, - 'type' => 'Sql', - 'reset' => TRUE, - )); + 'name' => self::QUEUE_NAME, + 'type' => 'Sql', + 'reset' => TRUE, + )); $revisions = $upgrade->getRevisionSequence(); foreach ($revisions as $rev) { // proceed only if $currentVer < $rev if (version_compare($currentVer, $rev) < 0) { $beginTask = new CRM_Queue_Task( - // callback + // callback array('CRM_Upgrade_Form', 'doIncrementalUpgradeStart'), // arguments array($rev), @@ -589,7 +591,7 @@ SET version = '$version' $queue->createItem($beginTask); $task = new CRM_Queue_Task( - // callback + // callback array('CRM_Upgrade_Form', 'doIncrementalUpgradeStep'), // arguments array($rev, $currentVer, $latestVer, $postUpgradeMessageFile), @@ -598,7 +600,7 @@ SET version = '$version' $queue->createItem($task); $task = new CRM_Queue_Task( - // callback + // callback array('CRM_Upgrade_Form', 'doIncrementalUpgradeFinish'), // arguments array($rev, $currentVer, $latestVer, $postUpgradeMessageFile), @@ -615,11 +617,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 string $rev + * the target (intermediate) revision e.g '3.2.alpha1'. * * @return bool */ - 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. @@ -633,14 +636,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 $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 string $rev + * the target (intermediate) revision e.g '3.2.alpha1'. + * @param string $originalVer + * the original revision. + * @param string $latestVer + * the target (final) revision. + * @param string $postUpgradeMessageFile + * 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); @@ -650,7 +657,10 @@ SET version = '$version' // pre-db check for major release. if ($upgrade->checkVersionRelease($rev, 'alpha1')) { if (!(is_callable(array( - $versionObject, 'verifyPreDBstate')))) { + $versionObject, + 'verifyPreDBstate', + ))) + ) { CRM_Core_Error::fatal("verifyPreDBstate method was not found for $rev"); } @@ -667,7 +677,9 @@ SET version = '$version' $upgrade->setSchemaStructureTables($rev); if (is_callable(array( - $versionObject, $phpFunctionName))) { + $versionObject, + $phpFunctionName, + ))) { $versionObject->$phpFunctionName($rev, $originalVer, $latestVer); } else { @@ -676,11 +688,14 @@ SET version = '$version' // set post-upgrade-message if any if (is_callable(array( - $versionObject, 'setPostUpgradeMessage'))) { + $versionObject, + 'setPostUpgradeMessage', + ))) { $postUpgradeMessage = file_get_contents($postUpgradeMessageFile); $versionObject->setPostUpgradeMessage($postUpgradeMessage, $rev); file_put_contents($postUpgradeMessageFile, $postUpgradeMessage); - } else { + } + else { $postUpgradeMessage = file_get_contents($postUpgradeMessageFile); CRM_Upgrade_Incremental_Legacy::setPostUpgradeMessage($postUpgradeMessage, $rev); file_put_contents($postUpgradeMessageFile, $postUpgradeMessage); @@ -693,14 +708,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 string $rev + * the target (intermediate) revision e.g '3.2.alpha1'. + * @param string $currentVer + * the original revision. + * @param string $latestVer + * the target (final) revision. + * @param string $postUpgradeMessageFile + * 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(); @@ -710,7 +729,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 @@ -740,11 +759,12 @@ SET version = '$version' * by calling the 'setPreUpgradeMessage' on each incremental upgrade * object. * - * @param $preUpgradeMessage string, alterable + * @param string $preUpgradeMessage + * 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 @@ -756,11 +776,14 @@ SET version = '$version' version_compare($rev, '3.2.alpha1') > 0 ) { $versionObject = $this->incrementalPhpObject($rev); - if (is_callable(array( - $versionObject, 'setPreUpgradeMessage'))) { - $versionObject->setPreUpgradeMessage($preUpgradeMessage, $rev, $currentVer); - } + if (is_callable(array( + $versionObject, + 'setPreUpgradeMessage', + ))) { + $versionObject->setPreUpgradeMessage($preUpgradeMessage, $rev, $currentVer); + } } } } + }