Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 /**
  * Perform an incremental version update.
  *
  * @param CRM_Queue_TaskContext $ctx
  * @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
  */
 public static function doIncrementalUpgradeStep(CRM_Queue_TaskContext $ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile)
 {
     $upgrade = new CRM_Upgrade_Form();
     $phpFunctionName = 'upgrade_' . str_replace('.', '_', $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}");
         }
         $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);
     }
     // 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);
     }
     return TRUE;
 }