Example #1
0
 /**
  * Perform an upgrade without using the web-frontend
  *
  * @param bool $enablePrint
  *
  * @throws Exception
  * @return array, with keys:
  *   - message: string, HTML-ish blob
  */
 public function run($enablePrint = TRUE)
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $upgrade = new CRM_Upgrade_Form();
     list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
     if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
         throw new Exception($error);
     }
     // Disable our SQL triggers
     CRM_Core_DAO::dropTriggers();
     // CRM-11156
     $preUpgradeMessage = NULL;
     $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
     $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade');
     $queueRunner = new CRM_Queue_Runner(array('title' => ts('CiviCRM Upgrade Tasks'), 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile)));
     $queueResult = $queueRunner->runAll();
     if ($queueResult !== TRUE) {
         $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']);
         CRM_Core_Error::debug_log_message($errorMessage);
         if ($enablePrint) {
             print $errorMessage;
         }
         throw $queueResult['exception'];
         // FIXME test
     }
     CRM_Upgrade_Form::doFinish();
     $message = file_get_contents($postUpgradeMessageFile);
     return array('latestVer' => $latestVer, 'message' => $message, 'text' => CRM_Utils_String::htmlToText($message));
 }
Example #2
0
 function run()
 {
     $upgrade = new CRM_Upgrade_Form();
     $message = ts('CiviCRM upgrade successful');
     if ($upgrade->checkVersion($upgrade->latestVersion)) {
         $message = ts('Your database has already been upgraded to CiviCRM %1', array(1 => $upgrade->latestVersion));
     } elseif ($upgrade->checkVersion('2.1.2') || $upgrade->checkVersion('2.1.3') || $upgrade->checkVersion('2.1.4') || $upgrade->checkVersion('2.1.5')) {
         // do nothing, db version is changed for all upgrades
     } elseif ($upgrade->checkVersion('2.1.0') || $upgrade->checkVersion('2.1') || $upgrade->checkVersion('2.1.1')) {
         // 2.1 to 2.1.2
         $this->runTwoOneTwo();
     } else {
         // 2.0 to 2.1
         for ($i = 1; $i <= 4; $i++) {
             $this->runForm($i);
         }
         // 2.1 to 2.1.2
         $this->runTwoOneTwo();
     }
     // just change the ver in the db, since nothing to upgrade
     $upgrade->setVersion($upgrade->latestVersion);
     // also cleanup the templates_c directory
     $config = CRM_Core_Config::singleton();
     $config->cleanup(1);
     $template = CRM_Core_Smarty::singleton();
     $template->assign('message', $message);
     $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $upgrade->latestVersion)));
     $template->assign('menuRebuildURL', CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1'));
     $contents = $template->fetch('CRM/common/success.tpl');
     echo $contents;
 }
Example #3
0
 /**
  * Display any final messages, clear caches, etc
  */
 public function runFinish()
 {
     $upgrade = new CRM_Upgrade_Form();
     $template = CRM_Core_Smarty::singleton();
     // If we're redirected from queue-runner, then isUpgradePending=true.
     // If user then reloads the finish page, the isUpgradePending will be unset. (Because the session has been cleared.)
     if ($this->get('isUpgradePending')) {
         // TODO: Use structured message store
         $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile'));
         // This destroys $session, so do it after get('postUpgradeMessageFile')
         CRM_Upgrade_Form::doFinish();
     } else {
         $postUpgradeMessage = '';
         // Session was destroyed! Can't recover messages.
     }
     // do a version check - after doFinish() sets the final version
     list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
     if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) {
         CRM_Core_Error::fatal($error);
     }
     $template->assign('message', $postUpgradeMessage);
     $template->assign('upgraded', TRUE);
     $template->assign('sid', CRM_Utils_System::getSiteID());
     // Render page header
     if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) {
         CRM_Utils_System::addHTMLHead($region->render(''));
     }
     $content = $template->fetch('CRM/common/success.tpl');
     echo CRM_Utils_System::theme($content, $this->_print, TRUE);
 }
Example #4
0
 /**
  * (Queue Task Callback)
  */
 public static function task_4_7_x_runSql(CRM_Queue_TaskContext $ctx, $rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
     return TRUE;
 }
Example #5
0
 function upgrade_3_1_4($rev)
 {
     require_once 'CRM/Upgrade/ThreeOne/ThreeOne.php';
     $threeOne = new CRM_Upgrade_ThreeOne_ThreeOne();
     $threeOne->upgrade_3_1_4();
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
 }
 function upgrade_3_3_7($rev)
 {
     $dao = new CRM_Contact_DAO_Contact();
     $dbName = $dao->_database;
     $chkExtQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1\n                        AND TABLE_NAME = 'civicrm_phone' AND COLUMN_NAME = 'phone_ext'";
     $extensionExists = CRM_Core_DAO::singleValueQuery($chkExtQuery, array(1 => array($dbName, 'String')), TRUE, FALSE);
     if (!$extensionExists) {
         $colQuery = 'ALTER TABLE `civicrm_phone` ADD `phone_ext` VARCHAR( 16 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `phone` ';
         CRM_Core_DAO::executeQuery($colQuery);
     }
     // handle db changes done for CRM-8218
     $alterContactDashboard = FALSE;
     $dao = new CRM_Contact_DAO_DashboardContact();
     $dbName = $dao->_database;
     $chkContentQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1\n                        AND TABLE_NAME = 'civicrm_dashboard_contact' AND COLUMN_NAME = 'content'";
     $contentExists = CRM_Core_DAO::singleValueQuery($chkContentQuery, array(1 => array($dbName, 'String')), TRUE, FALSE);
     if (!$contentExists) {
         $alterContactDashboard = TRUE;
     }
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->assign('alterContactDashboard', $alterContactDashboard);
     $upgrade->processSQL($rev);
 }
 /**
  * (Queue Task Callback)
  */
 public static function task_4_2_x_runSql(CRM_Queue_TaskContext $ctx, $rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
     // now rebuild all the triggers
     // CRM-9716
     // FIXME // CRM_Core_DAO::triggerRebuild();
     return TRUE;
 }
Example #8
0
 /**
  * Queue Task Callback for CRM-16846
  *
  * Run a sql file without resetting locale to that version
  */
 public static function task_4_6_x_runOnlySql(CRM_Queue_TaskContext $ctx, $rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     $smarty = CRM_Core_Smarty::singleton();
     $smarty->assign('domainID', CRM_Core_Config::domainID());
     $fileName = "CRM/Upgrade/Incremental/sql/{$rev}.mysql.tpl";
     $upgrade->source($smarty->fetch($fileName), TRUE);
     return TRUE;
 }
 static function doFinish()
 {
     $upgrade = new CRM_Upgrade_Form();
     list($ignore, $latestVer) = $upgrade->getUpgradeVersions();
     // Seems extraneous in context, but we'll preserve old behavior
     $upgrade->setVersion($latestVer);
     // cleanup caches CRM-8739
     $config = CRM_Core_Config::singleton();
     $config->cleanupCaches(1, FALSE);
 }
 /**
  * Perform an incremental upgrade
  *
  * @param $rev string, the revision to which we are upgrading (Note: When processing a series of upgrades, this is the immediate upgrade - not the final)
  */
 static function upgrade_3_1_4($rev)
 {
     $threeOne = new CRM_Upgrade_ThreeOne_ThreeOne();
     $threeOne->upgrade_3_1_4();
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
 }
Example #11
0
 /**
  * @param $rev
  */
 public function upgrade_4_1_1($rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->assign('addDedupeEmail', !CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'dedupe_email'));
     $sql = "SELECT id FROM civicrm_worldregion LIMIT 1";
     $upgrade->assign('worldRegionEmpty', !CRM_Core_DAO::singleValueQuery($sql));
     $upgrade->processSQL($rev);
 }
Example #12
0
 /**
  * @param $rev
  *
  * @throws Exception
  */
 public function upgrade_3_4_7($rev)
 {
     $onBehalfProfileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name');
     if (!$onBehalfProfileId) {
         CRM_Core_Error::fatal();
     }
     $pages = CRM_Core_DAO::executeQuery("\nSELECT    civicrm_contribution_page.id\nFROM      civicrm_contribution_page\nLEFT JOIN civicrm_uf_join ON entity_table = 'civicrm_contribution_page' AND entity_id = civicrm_contribution_page.id AND module = 'OnBehalf'\nWHERE     is_for_organization = 1\nAND       civicrm_uf_join.id IS NULL\n");
     while ($pages->fetch()) {
         $query = "\nINSERT INTO civicrm_uf_join\n    (is_active, module, entity_table, entity_id, weight, uf_group_id)\nVALUES\n    (1, 'OnBehalf', 'civicrm_contribution_page', %1, 1, %2)";
         $params = array(1 => array($pages->id, 'Integer'), 2 => array($onBehalfProfileId, 'Integer'));
         CRM_Core_DAO::executeQuery($query, $params);
     }
     // CRM-8774
     $config = CRM_Core_Config::singleton();
     if ($config->userFramework == 'Drupal' || $config->userFramework == 'Drupal6') {
         db_query("UPDATE {system} SET weight = 100 WHERE name = 'civicrm'");
         drupal_flush_all_caches();
     }
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
 }
Example #13
0
 function upgrade($rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     //Run the SQL file
     $upgrade->processSQL($rev);
     // fix for CRM-5162
     // we need to encrypt all smtpPasswords if present
     require_once "CRM/Core/DAO/Preferences.php";
     $mailingDomain = new CRM_Core_DAO_Preferences();
     $mailingDomain->find();
     while ($mailingDomain->fetch()) {
         if ($mailingDomain->mailing_backend) {
             $values = unserialize($mailingDomain->mailing_backend);
             if (isset($values['smtpPassword'])) {
                 require_once 'CRM/Utils/Crypt.php';
                 $values['smtpPassword'] = CRM_Utils_Crypt::encrypt($values['smtpPassword']);
                 $mailingDomain->mailing_backend = serialize($values);
                 $mailingDomain->save();
             }
         }
     }
     require_once "CRM/Core/DAO/Domain.php";
     $domain = new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     $domain->selectAdd('config_backend');
     $domain->find(true);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         if ($dateFormat = CRM_Utils_Array::value('dateformatQfDate', $defaults)) {
             $dateFormatArray = explode(" ", $dateFormat);
             //replace new date format based on previous month format
             //%b month name [abbreviated]
             //%B full month name ('January'..'December')
             //%m decimal number, 0-padded ('01'..'12')
             if ($dateFormat == '%b %d %Y') {
                 $defaults['dateInputFormat'] = 'mm/dd/yy';
             } else {
                 if ($dateFormat == '%d-%b-%Y') {
                     $defaults['dateInputFormat'] = 'dd-mm-yy';
                 } else {
                     if (in_array('%b', $dateFormatArray)) {
                         $defaults['dateInputFormat'] = 'M d, yy';
                     } else {
                         if (in_array('%B', $dateFormatArray)) {
                             $defaults['dateInputFormat'] = 'MM d, yy';
                         } else {
                             $defaults['dateInputFormat'] = 'mm/dd/yy';
                         }
                     }
                 }
             }
         }
         // %p - lowercase ante/post meridiem ('am', 'pm')
         // %P - uppercase ante/post meridiem ('AM', 'PM')
         if ($dateTimeFormat = CRM_Utils_Array::value('dateformatQfDatetime', $defaults)) {
             $defaults['timeInputFormat'] = 2;
             $dateTimeFormatArray = explode(" ", $dateFormat);
             if (in_array('%P', $dateTimeFormatArray) || in_array('%p', $dateTimeFormatArray)) {
                 $defaults['timeInputFormat'] = 1;
             }
             unset($defaults['dateformatQfDatetime']);
         }
         unset($defaults['dateformatQfDate']);
         unset($defaults['dateformatTime']);
         require_once "CRM/Core/BAO/Setting.php";
         CRM_Core_BAO_Setting::add($defaults);
     }
     $sql = "SELECT id, form_values FROM civicrm_report_instance";
     $instDAO = CRM_Core_DAO::executeQuery($sql);
     while ($instDAO->fetch()) {
         $fromVal = @unserialize($instDAO->form_values);
         foreach ((array) $fromVal as $key => $value) {
             if (strstr($key, '_relative')) {
                 $elementName = substr($key, 0, strlen($key) - strlen('_relative'));
                 $fromNamekey = $elementName . '_from';
                 $toNamekey = $elementName . '_to';
                 $fromNameVal = $fromVal[$fromNamekey];
                 $toNameVal = $fromVal[$toNamekey];
                 //check 'choose date range' is set
                 if ($value == '0') {
                     if (CRM_Utils_Date::isDate($fromNameVal)) {
                         $fromDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($fromNameVal));
                         $fromNameVal = $fromDate[0];
                     } else {
                         $fromNameVal = '';
                     }
                     if (CRM_Utils_Date::isDate($toNameVal)) {
                         $toDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($toNameVal));
                         $toNameVal = $toDate[0];
                     } else {
                         $toNameVal = '';
                     }
                 } else {
                     $fromNameVal = '';
                     $toNameVal = '';
                 }
                 $fromVal[$fromNamekey] = $fromNameVal;
                 $fromVal[$toNamekey] = $toNameVal;
                 continue;
             }
         }
         $fromVal = serialize($fromVal);
         $updateSQL = "UPDATE civicrm_report_instance SET form_values = '{$fromVal}' WHERE id = {$instDAO->id}";
         CRM_Core_DAO::executeQuery($updateSQL);
     }
     $customFieldSQL = "SELECT id, date_format FROM civicrm_custom_field WHERE data_type = 'Date' ";
     $customDAO = CRM_Core_DAO::executeQuery($customFieldSQL);
     while ($customDAO->fetch()) {
         $datePartKey = $dateParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customDAO->date_format);
         $dateParts = array_combine($datePartKey, $dateParts);
         $year = CRM_Utils_Array::value('Y', $dateParts);
         $month = CRM_Utils_Array::value('M', $dateParts);
         $date = CRM_Utils_Array::value('d', $dateParts);
         $hour = CRM_Utils_Array::value('h', $dateParts);
         $minute = CRM_Utils_Array::value('i', $dateParts);
         $timeFormat = CRM_Utils_Array::value('A', $dateParts);
         $newDateFormat = 'mm/dd/yy';
         if ($year && $month && $date) {
             $newDateFormat = 'mm/dd/yy';
         } else {
             if (!$year && $month && $date) {
                 $newDateFormat = 'mm/dd';
             }
         }
         $newTimeFormat = 'NULL';
         if ($timeFormat && $hour == 'h') {
             $newTimeFormat = 1;
         } else {
             if ($hour) {
                 $newTimeFormat = 2;
             }
         }
         $updateSQL = "UPDATE civicrm_custom_field SET date_format = '{$newDateFormat}', time_format = {$newTimeFormat} WHERE id = {$customDAO->id}";
         CRM_Core_DAO::executeQuery($updateSQL);
     }
     $template =& CRM_Core_Smarty::singleton();
     $afterUpgradeMessage = '';
     if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
         $afterUpgradeMessage .= "<br/><br/>";
     }
     $afterUpgradeMessage .= ts("Date Input Format has been set to %1 format. If you want to use a different format please check Administer CiviCRM &raquo; Global Settings &raquo; Date Formats.", array(1 => $defaults['dateInputFormat']));
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
 }
Example #14
0
 /**
  * @param $rev
  */
 public function upgrade_3_2_1($rev)
 {
     //CRM-6565 check if Activity Index is already exists or not.
     $addActivityTypeIndex = TRUE;
     $indexes = CRM_Core_DAO::executeQuery('SHOW INDEXES FROM civicrm_activity');
     while ($indexes->fetch()) {
         if ($indexes->Key_name == 'UI_activity_type_id') {
             $addActivityTypeIndex = FALSE;
         }
     }
     // CRM-6563: restrict access to the upload dir, tighten access to the config-and-log dir
     $config = CRM_Core_Config::singleton();
     CRM_Utils_File::restrictAccess($config->uploadDir);
     CRM_Utils_File::restrictAccess($config->configAndLogDir);
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->assign('addActivityTypeIndex', $addActivityTypeIndex);
     $upgrade->processSQL($rev);
 }
Example #15
0
 public static function doFinish()
 {
     $upgrade = new CRM_Upgrade_Form();
     list($ignore, $latestVer) = $upgrade->getUpgradeVersions();
     // Seems extraneous in context, but we'll preserve old behavior
     $upgrade->setVersion($latestVer);
     // lets rebuild the config array in case we've made a few changes in the
     // code base
     // this also helps us always store the latest version of civi in the DB
     $params = array();
     CRM_Core_BAO_ConfigSetting::add($params);
     // CRM-12804 comment-51411 : add any missing settings
     // at the end of upgrade
     CRM_Core_BAO_Setting::updateSettingsFromMetaData();
     // cleanup caches CRM-8739
     $config = CRM_Core_Config::singleton();
     $config->cleanupCaches(1);
     // Rebuild all triggers and re-enable logging if needed
     $logging = new CRM_Logging_Schema();
     $logging->fixSchemaDifferences();
     //CRM-16257 update Config.IDS.ini might be an old copy
     CRM_Core_IDS::createConfigFile(TRUE);
 }
Example #16
0
 /**
  * @param $rev
  */
 function upgrade($rev)
 {
     // fix CRM-5270: if civicrm_report_instance.description is localised,
     // recreate it based on the first locale’s description_xx_YY contents
     // and drop all the description_xx_YY columns
     if (!CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'description')) {
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(TRUE);
         $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
         CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance ADD description VARCHAR(255)");
         CRM_Core_DAO::executeQuery("UPDATE civicrm_report_instance SET description = description_{$locales[0]}");
         CRM_Core_DAO::executeQuery("DROP TRIGGER IF EXISTS civicrm_report_instance_before_insert");
         foreach ($locales as $locale) {
             CRM_Core_DAO::executeQuery("DROP VIEW civicrm_report_instance_{$locale}");
             CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance DROP description_{$locale}");
         }
     }
     //We execute some part of php after sql and then again sql
     //So using conditions for skipping some part of sql CRM-4575
     $upgrade = new CRM_Upgrade_Form();
     //Run the SQL file (1)
     $upgrade->processSQL($rev);
     //replace  with ; in report instance
     $sql = "UPDATE civicrm_report_instance\n                       SET form_values = REPLACE(form_values,'#',';') ";
     CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     //delete unnecessary activities
     $bulkEmailID = CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name');
     if ($bulkEmailID) {
         $mailingActivityIds = array();
         $query = "\n            SELECT max( ca.id ) as aid,\n                   ca.source_record_id sid\n            FROM civicrm_activity ca\n            WHERE ca.activity_type_id = %1\n            GROUP BY ca.source_record_id";
         $params = array(1 => array($bulkEmailID, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($query, $params);
         while ($dao->fetch()) {
             $updateQuery = "\n                UPDATE civicrm_activity_target cat, civicrm_activity ca\n                    SET cat.activity_id = {$dao->aid}\n                WHERE ca.source_record_id IS NOT NULL   AND\n                      ca.activity_type_id = %1          AND\n                      ca.id <> {$dao->aid}              AND\n                      ca.source_record_id = {$dao->sid} AND\n                      ca.id = cat.activity_id";
             $updateParams = array(1 => array($bulkEmailID, 'Integer'));
             CRM_Core_DAO::executeQuery($updateQuery, $updateParams);
             $deleteQuery = "\n                DELETE ca.*\n                FROM civicrm_activity ca\n                WHERE ca.source_record_id IS NOT NULL  AND\n                      ca.activity_type_id = %1         AND\n                      ca.id <> {$dao->aid}             AND\n                      ca.source_record_id = {$dao->sid}";
             $deleteParams = array(1 => array($bulkEmailID, 'Integer'));
             CRM_Core_DAO::executeQuery($deleteQuery, $deleteParams);
         }
     }
     //CRM-4453
     //lets insert column in civicrm_aprticipant table
     $query = "\n        ALTER TABLE `civicrm_participant`\n            ADD `fee_currency` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '3 character string, value derived from config setting.' AFTER `discount_id`";
     CRM_Core_DAO::executeQuery($query);
     //get currency from contribution table if exists/default
     //insert currency when fee_amount != NULL or event is paid.
     $query = "\n        SELECT  civicrm_participant.id\n        FROM    civicrm_participant\n            LEFT JOIN  civicrm_event\n                   ON ( civicrm_participant.event_id = civicrm_event.id )\n        WHERE  civicrm_participant.fee_amount IS NOT NULL OR\n               civicrm_event.is_monetary = 1";
     $participant = CRM_Core_DAO::executeQuery($query);
     while ($participant->fetch()) {
         $query = "\n            SELECT civicrm_contribution.currency\n            FROM   civicrm_contribution,\n                   civicrm_participant_payment\n            WHERE  civicrm_contribution.id = civicrm_participant_payment.contribution_id AND\n                   civicrm_participant_payment.participant_id = {$participant->id}";
         $currencyID = CRM_Core_DAO::singleValueQuery($query);
         if (!$currencyID) {
             $config = CRM_Core_Config::singleton();
             $currencyID = $config->defaultCurrency;
         }
         //finally update participant record.
         CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Participant', $participant->id, 'fee_currency', $currencyID);
     }
     //CRM-4575
     //check whether {contact.name} is set in mailing labels
     $mailingFormat = self::getPreference('mailing_format');
     $addNewAddressee = TRUE;
     if (strpos($mailingFormat, '{contact.contact_name}') === FALSE) {
         $addNewAddressee = FALSE;
     } else {
         //else compare individual name format with default individual addressee.
         $individualNameFormat = self::getPreference('individual_name_format');
         $defaultAddressee = CRM_Core_OptionGroup::values('addressee', FALSE, FALSE, FALSE, " AND v.filter = 1 AND v.is_default =  1", 'label');
         if (array_search($individualNameFormat, $defaultAddressee) !== FALSE) {
             $addNewAddressee = FALSE;
         }
     }
     $docURL = CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', FALSE, NULL, NULL, 'color: white; text-decoration: underline;', "wiki");
     if ($addNewAddressee) {
         //otherwise insert new token in addressee and set as a default
         $addresseeGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'addressee', 'id', 'name');
         $optionValueParams = array('label' => $individualNameFormat, 'is_active' => 1, 'contactOptions' => 1, 'filter' => 1, 'is_default' => 1, 'reset_default_for' => array('filter' => "0, 1"));
         $action = CRM_Core_Action::ADD;
         $addresseeGroupParams = array('name' => 'addressee');
         $fieldValues = array('option_group_id' => $addresseeGroupId);
         $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
         $optionValueParams['weight'] = $weight;
         $addresseeToken = CRM_Core_OptionValue::addOptionValue($optionValueParams, $addresseeGroupParams, $action, $optionId = NULL);
         $afterUpgradeMessage = ts("During this upgrade, Postal Addressee values have been stored for each contact record using the system default format - %2.You will need to run the included command-line script to update your Individual contact records to use the \"Individual Name Format\" previously specified for your site %1", array(1 => $docURL, 2 => array_pop($defaultAddressee)));
     } else {
         $afterUpgradeMessage = ts("Email Greeting, Postal Greeting and Postal Addressee values have been stored for all contact records based on the system default formats. If you want to use a different format for any of these contact fields - you can run the provided command line script to update contacts to a different format %1 ", array(1 => $docURL));
     }
     //replace contact.contact_name with contact.addressee in civicrm_preference.mailing_format
     $updateQuery = "\n        UPDATE civicrm_preferences\n               SET `mailing_format` =\n                    replace(`mailing_format`, '{contact.contact_name}','{contact.addressee}')";
     CRM_Core_DAO::executeQuery($updateQuery);
     //drop column individual_name_format
     $alterQuery = "\n        ALTER TABLE `civicrm_preferences`\n              DROP `individual_name_format`";
     CRM_Core_DAO::executeQuery($alterQuery);
     //set status message for default greetings
     $template = CRM_Core_Smarty::singleton();
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
 }
Example #17
0
 function __construct($version)
 {
     parent::__construct();
     $this->latestVersion = $version;
 }
 /**
  * Display any final messages, clear caches, etc
  */
 function runFinish()
 {
     $upgrade = new CRM_Upgrade_Form();
     $template = CRM_Core_Smarty::singleton();
     // TODO: Use structured message store
     $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile'));
     // This destroys $session, so do it after ge('postUpgradeMessageFile')
     CRM_Upgrade_Form::doFinish();
     // do a version check - after doFinish() sets the final version
     list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
     if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) {
         CRM_Core_Error::fatal($error);
     }
     $template->assign('message', $postUpgradeMessage);
     $template->assign('upgraded', TRUE);
     $content = $template->fetch('CRM/common/success.tpl');
     echo CRM_Utils_System::theme('page', $content, TRUE, $this->_print, FALSE, TRUE);
 }
Example #19
0
 public static function doFinish()
 {
     $upgrade = new CRM_Upgrade_Form();
     list($ignore, $latestVer) = $upgrade->getUpgradeVersions();
     // Seems extraneous in context, but we'll preserve old behavior
     $upgrade->setVersion($latestVer);
     // Clear cached metadata.
     Civi::service('settings_manager')->flush();
     // cleanup caches CRM-8739
     $config = CRM_Core_Config::singleton();
     $config->cleanupCaches(1);
     // Rebuild all triggers and re-enable logging if needed
     $logging = new CRM_Logging_Schema();
     $logging->fixSchemaDifferences();
     //CRM-16257 update Config.IDS.ini might be an old copy
     CRM_Core_IDS::createConfigFile(TRUE);
 }