| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
*
*/
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
* Upgrade for multilingual
*
* @var boolean
- * @public
*/
public $multilingual = FALSE;
* Locales available for multilingual upgrade
*
* @var array
- * @public
*/
public $locales;
* Number to string mapper
*
* @var array
- * @public
*/
static $_numberMap = array(
0 => 'Zero',
* 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
* @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();
*
* @return mixed
*/
- static function &incrementalPhpObject($version) {
+ public static function &incrementalPhpObject($version) {
static $incrementalPhpObject = array();
$versionParts = explode('.', $version);
*
* @return bool
*/
- function checkVersionRelease($version, $release) {
+ public function checkVersionRelease($version, $release) {
$versionParts = explode('.', $version);
if ($versionParts[2] == $release) {
return TRUE;
*
* @return array
*/
- function checkSQLConstraints(&$constraints) {
+ public function checkSQLConstraints(&$constraints) {
$pass = $fail = 0;
foreach ($constraints as $constraint) {
if ($this->checkSQLConstraint($constraint)) {
*
* @return bool
*/
- function checkSQLConstraint($constraint) {
+ public function checkSQLConstraint($constraint) {
// check constraint here
return TRUE;
}
* @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)) {
$this->assign('recentlyViewed', FALSE);
}
- function buildQuickForm() {
+ public function buildQuickForm() {
$this->addDefaultButtons($this->getButtonTitle(),
'next',
NULL,
* 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');
}
* 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()
);
return 'CRM/Upgrade/Base.tpl';
}
- function postProcess() {
+ public function postProcess() {
$this->upgrade();
if (!$this->verifyPostDBState($errorMessage)) {
*
* @return Object
*/
- function runQuery($query) {
+ public function runQuery($query) {
return CRM_Core_DAO::executeQuery($query,
CRM_Core_DAO::$_nullArray
);
*
* @return Object
*/
- function setVersion($version) {
+ public function setVersion($version) {
$this->logVersion($version);
$query = "
*
* @return bool
*/
- function logVersion($newVersion) {
+ public function logVersion($newVersion) {
if ($newVersion) {
$oldVersion = CRM_Core_BAO_Domain::version();
*
* @return bool
*/
- function checkVersion($version) {
+ public function checkVersion($version) {
$domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain',
$version, 'id',
'version'
* @return array
* @throws Exception
*/
- function getRevisionSequence() {
+ public function getRevisionSequence() {
$revList = array();
$sqlDir = implode(DIRECTORY_SEPARATOR,
array(dirname(__FILE__), 'Incremental', 'sql')
// 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;
}
*
* @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);
*
* @return bool
*/
- function processLocales($tplFile, $rev) {
+ public function processLocales($tplFile, $rev) {
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('domainID', CRM_Core_Config::domainID());
/**
* @param $rev
*/
- function setSchemaStructureTables($rev) {
+ public function setSchemaStructureTables($rev) {
if ($this->multilingual) {
CRM_Core_I18n_Schema::schemaStructureTables($rev, TRUE);
}
*
* @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";
*
* @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.'));
}
*
* @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 -
$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,
));
}
*
* @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),
/**
* 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,
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),
$queue->createItem($beginTask);
$task = new CRM_Queue_Task(
- // callback
+ // callback
array('CRM_Upgrade_Form', 'doIncrementalUpgradeStep'),
// arguments
array($rev, $currentVer, $latestVer, $postUpgradeMessageFile),
$queue->createItem($task);
$task = new CRM_Queue_Task(
- // callback
+ // callback
array('CRM_Upgrade_Form', 'doIncrementalUpgradeFinish'),
// arguments
array($rev, $currentVer, $latestVer, $postUpgradeMessageFile),
* 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.
* 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);
// 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");
}
$upgrade->setSchemaStructureTables($rev);
if (is_callable(array(
- $versionObject, $phpFunctionName))) {
+ $versionObject,
+ $phpFunctionName,
+ ))) {
$versionObject->$phpFunctionName($rev, $originalVer, $latestVer);
}
else {
// 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);
* 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();
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
* 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
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);
+ }
}
}
}
+
}