Example #1
0
 /**
  * Return the running civicrm version.
  *
  * @return string
  *   civicrm version
  */
 public static function version()
 {
     static $version;
     if (!$version) {
         $verFile = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', '..', 'civicrm-version.php'));
         if (file_exists($verFile)) {
             require_once $verFile;
             if (function_exists('civicrmVersion')) {
                 $info = civicrmVersion();
                 $version = $info['version'];
             }
         } else {
             // svn installs don't have version.txt by default. In that case version.xml should help -
             $verFile = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', '..', 'xml', 'version.xml'));
             if (file_exists($verFile)) {
                 $str = file_get_contents($verFile);
                 $xmlObj = simplexml_load_string($str);
                 $version = (string) $xmlObj->version_no;
             }
         }
         // pattern check
         if (!CRM_Utils_System::isVersionFormatValid($version)) {
             CRM_Core_Error::fatal('Unknown codebase version.');
         }
     }
     return $version;
 }
Example #2
0
 function run()
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $latestVer = CRM_Utils_System::version();
     $currentVer = CRM_Core_BAO_Domain::version();
     if (!$currentVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
     } else {
         if (stripos($currentVer, 'upgrade')) {
             CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.'));
         }
     }
     if (!$latestVer) {
         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', '3.1.0' => '3.1.1');
     if (isset($convertVer[$currentVer])) {
         $currentVer = $convertVer[$currentVer];
     }
     // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
     // lets do a pattern check -
     if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
         CRM_Core_Error::fatal(ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'));
     }
     // This could be removed in later rev
     if ($currentVer == '2.1.6') {
         $config =& CRM_Core_Config::singleton();
         // also cleanup the templates_c directory
         $config->cleanup(1, false);
         if ($config->userFramework !== 'Standalone') {
             // clean the session
             $session =& CRM_Core_Session::singleton();
             $session->reset(2);
         }
     }
     // end of hack
     CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $upgrade =& new CRM_Upgrade_Form();
     $template =& CRM_Core_Smarty::singleton();
     $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $template->assign('menuRebuildURL', CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1'));
     $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
     if (version_compare($currentVer, $latestVer) > 0) {
         // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error.
         $dbToolsLink = CRM_Utils_System::docURL2("Database Troubleshooting Tools", true);
         $error = ts('Your database is marked with an unexpected version number: %1. The automated upgrade to version %2 can not be run - and the %2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. The database tools utility at %3 may be helpful. You may want to revert to the codebase you were using prior to beginning this upgrade until you resolve this problem.', array(1 => $currentVer, 2 => $latestVer, 3 => $dbToolsLink));
         CRM_Core_Error::fatal($error);
     } else {
         if (version_compare($currentVer, $latestVer) == 0) {
             $message = ts('Your database has already been upgraded to CiviCRM %1', array(1 => $latestVer));
             $template->assign('upgraded', true);
         } else {
             $message = ts('CiviCRM upgrade was successful.');
             $template->assign('currentVersion', $currentVer);
             $template->assign('newVersion', $latestVer);
             $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', array(1 => $currentVer, 2 => $latestVer)));
             $template->assign('upgraded', false);
             if (CRM_Utils_Array::value('upgrade', $_POST)) {
                 $revisions = $upgrade->getRevisionSequence();
                 foreach ($revisions as $rev) {
                     // proceed only if $currentVer < $rev
                     if (version_compare($currentVer, $rev) < 0) {
                         // as soon as we start doing anything we append ".upgrade" to version.
                         // this also helps detect any partial upgrade issues
                         $upgrade->setVersion($rev . '.upgrade');
                         $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
                         if (is_callable(array($this, $phpFunctionName))) {
                             eval("\$this->{$phpFunctionName}('{$rev}');");
                         } else {
                             $upgrade->processSQL($rev);
                         }
                         // after an successful intermediate upgrade, set the complete version
                         $upgrade->setVersion($rev);
                     }
                 }
                 $upgrade->setVersion($latestVer);
                 $template->assign('upgraded', true);
                 // also cleanup the templates_c directory
                 $config =& CRM_Core_Config::singleton();
                 $config->cleanup(1, false);
                 // clear db caching
                 $config->clearDBCache();
                 // clean the session. Note: In case of standalone this makes the user logout.
                 // So skip this step for standalone.
                 if ($config->userFramework !== 'Standalone') {
                     $session =& CRM_Core_Session::singleton();
                     $session->reset(2);
                 }
             }
         }
     }
     $template->assign('message', $message);
     $content = $template->fetch('CRM/common/success.tpl');
     echo CRM_Utils_System::theme('page', $content, true, $this->_print, false, true);
 }
Example #3
0
 static function isDBVersionValid(&$errorMessage)
 {
     require_once 'CRM/Core/BAO/Domain.php';
     $dbVersion = CRM_Core_BAO_Domain::version();
     if (!$dbVersion) {
         // if db.ver missing
         $errorMessage = ts('Version information found to be missing in database. You will need to determine the correct version corresponding to your current database state.');
         return false;
     } else {
         if (!CRM_Utils_System::isVersionFormatValid($dbVersion)) {
             $errorMessage = ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.');
             return false;
         } else {
             if (stripos($dbVersion, 'upgrade')) {
                 // if db.ver indicates a partially upgraded db
                 $upgradeUrl = CRM_Utils_System::url("civicrm/upgrade", "reset=1");
                 $errorMessage = ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the <a href=\'%1\'>upgrade process</a> again.', array(1 => $upgradeUrl));
                 return false;
             } else {
                 $codeVersion = CRM_Utils_System::version();
                 // if db.ver < code.ver, time to upgrade
                 if (version_compare($dbVersion, $codeVersion) < 0) {
                     $upgradeUrl = CRM_Utils_System::url("civicrm/upgrade", "reset=1");
                     $errorMessage = ts('New codebase version detected. You might want to visit <a href=\'%1\'>upgrade screen</a> to upgrade the database.', array(1 => $upgradeUrl));
                     return false;
                 }
                 // if db.ver > code.ver, sth really wrong
                 if (version_compare($dbVersion, $codeVersion) > 0) {
                     $errorMessage = ts('Your database is marked with an unexpected version number: %1. The v%2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. You may want to revert to the codebase you were using until you resolve this problem.', array(1 => $dbVersion, 2 => $codeVersion));
                     $errorMessage .= "<p>" . ts('OR if this is an svn install, you might want to fix version.txt file.') . "</p>";
                     return false;
                 }
             }
         }
     }
     // FIXME: there should be another check to make sure version is in valid format - X.Y.alpha_num
     return true;
 }
Example #4
0
 /**
  * Checks if CiviCRM database version is up-to-date
  * @return array
  */
 public function checkDbVersion()
 {
     $messages = array();
     $dbVersion = CRM_Core_BAO_Domain::version();
     $upgradeUrl = CRM_Utils_System::url("civicrm/upgrade", "reset=1");
     if (!$dbVersion) {
         // if db.ver missing
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Version information found to be missing in database. You will need to determine the correct version corresponding to your current database state.'), ts('Database Version Missing'), \Psr\Log\LogLevel::ERROR, 'fa-database');
     } elseif (!CRM_Utils_System::isVersionFormatValid($dbVersion)) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'), ts('Database Version Invalid'), \Psr\Log\LogLevel::ERROR, 'fa-database');
     } elseif (stripos($dbVersion, 'upgrade')) {
         // if db.ver indicates a partially upgraded db
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Database check failed - the database looks to have been partially upgraded. You must reload the database with the backup and try the <a href=\'%1\'>upgrade process</a> again.', array(1 => $upgradeUrl)), ts('Database Partially Upgraded'), \Psr\Log\LogLevel::ALERT, 'fa-database');
     } else {
         $codeVersion = CRM_Utils_System::version();
         // if db.ver < code.ver, time to upgrade
         if (version_compare($dbVersion, $codeVersion) < 0) {
             $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('New codebase version detected. You must visit <a href=\'%1\'>upgrade screen</a> to upgrade the database.', array(1 => $upgradeUrl)), ts('Database Upgrade Required'), \Psr\Log\LogLevel::ALERT, 'fa-database');
         }
         // if db.ver > code.ver, sth really wrong
         if (version_compare($dbVersion, $codeVersion) > 0) {
             $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Your database is marked with an unexpected version number: %1. The v%2 codebase may not be compatible with your database state.
         You will need to determine the correct version corresponding to your current database state. You may want to revert to the codebase
         you were using until you resolve this problem.<br/>OR if this is a manual install from git, you might want to fix civicrm-version.php file.', array(1 => $dbVersion, 2 => $codeVersion)), ts('Database In Unexpected Version'), \Psr\Log\LogLevel::ERROR, 'fa-database');
         }
     }
     return $messages;
 }
Example #5
0
 function run()
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $latestVer = CRM_Utils_System::version();
     $currentVer = CRM_Core_BAO_Domain::version();
     if (!$currentVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
     } else {
         if (stripos($currentVer, 'upgrade')) {
             CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.'));
         }
     }
     if (!$latestVer) {
         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', '3.1.0' => '3.1.1');
     if (isset($convertVer[$currentVer])) {
         $currentVer = $convertVer[$currentVer];
     }
     // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
     // lets do a pattern check -
     if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
         CRM_Core_Error::fatal(ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'));
     }
     // This could be removed in later rev
     if ($currentVer == '2.1.6') {
         $config = CRM_Core_Config::singleton();
         // also cleanup the templates_c directory
         $config->cleanup(1, false);
         if ($config->userFramework !== 'Standalone') {
             // clean the session
             $session = CRM_Core_Session::singleton();
             $session->reset(2);
         }
     }
     // end of hack
     CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $upgrade = new CRM_Upgrade_Form();
     $template = CRM_Core_Smarty::singleton();
     $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $template->assign('menuRebuildURL', CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1'));
     $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
     if (version_compare($currentVer, $latestVer) > 0) {
         // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error.
         $dbToolsLink = CRM_Utils_System::docURL2("Database Troubleshooting Tools", true);
         $error = ts('Your database is marked with an unexpected version number: %1. The automated upgrade to version %2 can not be run - and the %2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. The database tools utility at %3 may be helpful. You may want to revert to the codebase you were using prior to beginning this upgrade until you resolve this problem.', array(1 => $currentVer, 2 => $latestVer, 3 => $dbToolsLink));
         CRM_Core_Error::fatal($error);
     } else {
         if (version_compare($currentVer, $latestVer) == 0) {
             $message = ts('Your database has already been upgraded to CiviCRM %1', array(1 => $latestVer));
             $template->assign('upgraded', true);
         } else {
             $message = ts('CiviCRM upgrade was successful.');
             if ($latestVer == '3.2.alpha1') {
                 $message .= '<br />' . ts("We have reset the COUNTED flag to false for the event participant status 'Pending from incomplete transaction'. This change ensures that people who have a problem during registration can try again.");
             } else {
                 if ($latestVer == '3.2.beta3' && version_compare($currentVer, '3.1.alpha1') >= 0) {
                     require_once 'CRM/Contact/BAO/ContactType.php';
                     $subTypes = CRM_Contact_BAO_ContactType::subTypes();
                     if (is_array($subTypes) && !empty($subTypes)) {
                         $config = CRM_Core_Config::singleton();
                         $subTypeTemplates = array();
                         if (isset($config->customTemplateDir)) {
                             foreach ($subTypes as $key => $subTypeName) {
                                 $customContactSubTypeEdit = $config->customTemplateDir . "CRM/Contact/Form/Edit/" . $subTypeName . ".tpl";
                                 $customContactSubTypeView = $config->customTemplateDir . "CRM/Contact/Page/View/" . $subTypeName . ".tpl";
                                 if (file_exists($customContactSubTypeEdit) || file_exists($customContactSubTypeView)) {
                                     $subTypeTemplates[$subTypeName] = $subTypeName;
                                 }
                             }
                         }
                         foreach ($subTypes as $key => $subTypeName) {
                             $customContactSubTypeEdit = $config->templateDir . "CRM/Contact/Form/Edit/" . $subTypeName . ".tpl";
                             $customContactSubTypeView = $config->templateDir . "CRM/Contact/Page/View/" . $subTypeName . ".tpl";
                             if (file_exists($customContactSubTypeEdit) || file_exists($customContactSubTypeView)) {
                                 $subTypeTemplates[$subTypeName] = $subTypeName;
                             }
                         }
                         if (!empty($subTypeTemplates)) {
                             $subTypeTemplates = implode(',', $subTypeTemplates);
                             $message .= '<br />' . ts('You are using custom template for contact subtypes: %1.', array(1 => $subTypeTemplates)) . '<br />' . ts('You need to move these subtype templates to the SubType directory in %1 and %2 respectively.', array(1 => 'CRM/Contact/Form/Edit', 2 => 'CRM/Contact/Page/View'));
                         }
                     }
                 } else {
                     if ($latestVer == '3.2.beta4') {
                         $statuses = array('New', 'Current', 'Grace', 'Expired', 'Pending', 'Cancelled', 'Deceased');
                         $sql = "\nSELECT  count( id ) as statusCount \n  FROM  civicrm_membership_status \n WHERE  name IN ( '" . implode("' , '", $statuses) . "' ) ";
                         $count = CRM_Core_DAO::singleValueQuery($sql);
                         if ($count < count($statuses)) {
                             $message .= '<br />' . ts("One or more Membership Status Rules was disabled during the upgrade because it did not match a recognized status name. if custom membership status rules were added to this site - review the disabled statuses and re-enable any that are still needed (Administer > CiviMember > Membership Status Rules).");
                         }
                     }
                 }
             }
             $template->assign('currentVersion', $currentVer);
             $template->assign('newVersion', $latestVer);
             $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', array(1 => $currentVer, 2 => $latestVer)));
             $template->assign('upgraded', false);
             if (CRM_Utils_Array::value('upgrade', $_POST)) {
                 $revisions = $upgrade->getRevisionSequence();
                 foreach ($revisions as $rev) {
                     // proceed only if $currentVer < $rev
                     if (version_compare($currentVer, $rev) < 0) {
                         // as soon as we start doing anything we append ".upgrade" to version.
                         // this also helps detect any partial upgrade issues
                         $upgrade->setVersion($rev . '.upgrade');
                         $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($this, $phpFunctionName))) {
                                 eval("\$this->{$phpFunctionName}('{$rev}');");
                             } else {
                                 $upgrade->processSQL($rev);
                             }
                         } else {
                             // new upgrade process from version
                             // 3.2.alpha1
                             $versionObject = $upgrade->incrementalPhpObject($rev);
                             // predb 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);
                                 }
                             }
                             if (is_callable(array($versionObject, $phpFunctionName))) {
                                 $versionObject->{$phpFunctionName}($rev);
                             } else {
                                 $upgrade->processSQL($rev);
                             }
                         }
                         // after an successful intermediate upgrade, set the complete version
                         $upgrade->setVersion($rev);
                     }
                 }
                 $upgrade->setVersion($latestVer);
                 $template->assign('upgraded', true);
                 // also cleanup the templates_c directory
                 $config = CRM_Core_Config::singleton();
                 $config->cleanup(1, false);
                 // clear db caching
                 $config->clearDBCache();
                 // clear temporary tables
                 $config->clearTempTables();
                 // clean the session. Note: In case of standalone this makes the user logout.
                 // So skip this step for standalone.
                 if ($config->userFramework !== 'Standalone') {
                     $session = CRM_Core_Session::singleton();
                     $session->reset(2);
                 }
             }
         }
     }
     $template->assign('message', $message);
     $content = $template->fetch('CRM/common/success.tpl');
     echo CRM_Utils_System::theme('page', $content, true, $this->_print, false, true);
 }
Example #6
0
 /**
  * Determine if $currentver already matches $latestVer
  *
  * @param $currentVer
  * @param $latestVer
  *
  * @return mixed, a string error message or boolean 'false' if OK
  */
 public function checkCurrentVersion($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 -
     if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
         $error = ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.');
     } elseif (version_compare($currentVer, $latestVer) != 0) {
         $error = ts('Your database is not configured for version %1', array(1 => $latestVer));
     }
     return $error;
 }