/** * (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; }
/** * @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); }
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); }
/** * @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); }
/** * (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; }
/** * @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); }
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 » Global Settings » Date Formats.", array(1 => $defaults['dateInputFormat'])); $template->assign('afterUpgradeMessage', $afterUpgradeMessage); }
/** * @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); }
/** * 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; }
/** * 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); }