/** * Test creating logging schema when database is in multilingual mode. * Also test altering a multilingual table. */ public function testMultilingualAlterSchemaLogging() { CRM_Core_I18n_Schema::makeMultilingual('en_US'); $logging = new CRM_Logging_Schema(); $logging->enableLogging(); $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", array(), FALSE, FALSE); $this->assertNotNull($value, 'Logging not enabled successfully'); $logging->disableLogging(); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT NULL", array(), FALSE, NULL, FALSE, TRUE); CRM_Core_I18n_Schema::rebuildMultilingualSchema(array('en_US')); $logging->enableLogging(); $query = CRM_Core_DAO::executeQuery("SHOW CREATE TABLE `log_civicrm_option_value`", array(), TRUE, NULL, FALSE, FALSE); $query->fetch(); $create = explode("\n", $query->Create_Table); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` DROP COLUMN `logging_test`", array(), FALSE, NULL, FALSE, TRUE); $this->assertTrue(in_array(" `logging_test` int(11) DEFAULT NULL", $create)); $logging->disableLogging(); }
function upgrade() { $sqlFile = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', '..', 'Incremental', 'sql', '2.2.alpha1.mysql')); $tplFile = "{$sqlFile}.tpl"; $isMultilingual = FALSE; if (file_exists($tplFile)) { $isMultilingual = $this->processLocales($tplFile, '2.2'); } else { if (!file_exists($sqlFile)) { CRM_Core_Error::fatal("sqlfile - {$rev}.mysql not found."); } $this->source($sqlFile); } if ($isMultilingual) { $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, '2.2'); } $this->setVersion('2.1.102'); }
function processLocales($tplFile, $rev) { $config =& CRM_Core_Config::singleton(); $smarty =& CRM_Core_Smarty::singleton(); $smarty->compile_dir = $config->templateCompileDir; $domain =& new CRM_Core_DAO_Domain(); $domain->find(true); $multilingual = (bool) $domain->locales; $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); $smarty->assign('multilingual', $multilingual); $smarty->assign('locales', $locales); // we didn't call CRM_Core_BAO_Setting::retrieve(), so we need to set $dbLocale by hand if ($multilingual) { global $dbLocale; $dbLocale = "_{$config->lcMessages}"; } $this->source($smarty->fetch($tplFile), true); if ($multilingual) { require_once 'CRM/Core/I18n/Schema.php'; CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, $rev); } return $multilingual; }
function upgrade_3_3_beta1($rev) { $upgrade = new CRM_Upgrade_Form(); $upgrade->processSQL($rev); // CRM-6902 // Add column price_field_value_id in civicrm_line_item. // Do not drop option_group_id column now since we need it to // update line items. $updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;"; CRM_Core_DAO::executeQuery($updateLineItem1); $priceFieldDAO = new CRM_Price_DAO_Field(); $priceFieldDAO->find(); $ids = array(); while ($priceFieldDAO->fetch()) { $opGroupDAO = new CRM_Core_DAO_OptionGroup(); $opGroupDAO->name = 'civicrm_price_field.amount.' . $priceFieldDAO->id; if (!$opGroupDAO->find(TRUE)) { $opGroupDAO->free(); continue; } $opValueDAO = new CRM_Core_DAO_OptionValue(); $opValueDAO->option_group_id = $opGroupDAO->id; $opValueDAO->find(); while ($opValueDAO->fetch()) { // FIX ME: not migrating description(?), there will // be a field description for each option. $fieldValue = array('price_field_id' => $priceFieldDAO->id, 'label' => $opValueDAO->label, 'name' => CRM_Utils_String::munge($opValueDAO->label, '_', 64), 'amount' => $opValueDAO->name, 'weight' => $opValueDAO->weight, 'is_default' => $opValueDAO->is_default, 'is_active' => $opValueDAO->is_active); if ($priceFieldDAO->count) { // Migrate Participant Counts on option level. // count of each option will be the same // as earlier field count. $fieldValue['count'] = $priceFieldDAO->count; } $fieldValueDAO = CRM_Price_BAO_FieldValue::add($fieldValue, $ids); $lineItemDAO = new CRM_Price_DAO_LineItem(); $lineItemDAO->option_group_id = $opGroupDAO->id; $lineItemDAO->label = $opValueDAO->label; $lineItemDAO->unit_price = $opValueDAO->name; $labelFound = $priceFound = FALSE; // check with label and amount if (!$lineItemDAO->find(TRUE)) { $lineItemDAO->free(); $lineItemDAO = new CRM_Price_DAO_LineItem(); $lineItemDAO->option_group_id = $opGroupDAO->id; $lineItemDAO->label = $opValueDAO->label; // check with label only if ($lineItemDAO->find(TRUE)) { $labelFound = TRUE; } } else { $labelFound = TRUE; $priceFound = TRUE; } $lineItemDAO->free(); // update civicrm_line_item for price_field_value_id. // Used query to avoid line by line update. if ($labelFound || $priceFound) { $lineItemParams = array(1 => array($fieldValueDAO->id, 'Integer'), 2 => array($opValueDAO->label, 'String')); $updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2"; if ($priceFound) { $lineItemParams[3] = array($opValueDAO->name, 'Float'); $updateLineItems .= " AND unit_price = %3"; } CRM_Core_DAO::executeQuery($updateLineItems, $lineItemParams); } } $opGroupDAO->delete(); $opValueDAO->free(); $opGroupDAO->free(); } $priceFieldDAO->free(); // Now drop option_group_id column from civicrm_line_item $updateLineItem2 = "ALTER TABLE civicrm_line_item DROP option_group_id,\n ADD CONSTRAINT `FK_civicrm_price_field_value_id` FOREIGN KEY (price_field_value_id) REFERENCES civicrm_price_field_value(id) ON DELETE SET NULL;"; CRM_Core_DAO::executeQuery($updateLineItem2, array(), TRUE, NULL, FALSE, FALSE); $updatePriceField = "ALTER TABLE civicrm_price_field DROP count"; CRM_Core_DAO::executeQuery($updatePriceField, array(), TRUE, NULL, FALSE, FALSE); // as the table 'civicrm_price_field' is localised and column 'count' is dropped // after the views are rebuild, we need to rebuild views to avoid invalid refrence of table. if ($upgrade->multilingual) { CRM_Core_I18n_Schema::rebuildMultilingualSchema($upgrade->locales, $rev); } }
/** * @param string $tableName * @param string $columnName * @param bool $l18n * */ public static function dropColumn($tableName, $columnName, $l18n = FALSE) { if (self::checkIfFieldExists($tableName, $columnName)) { $sql = "ALTER TABLE {$tableName} DROP COLUMN {$columnName}"; if ($l18n) { CRM_Core_DAO::executeQuery($sql); } else { CRM_Core_DAO::executeQuery($sql, array(), TRUE, NULL, FALSE, FALSE); } $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); if ($domain->locales) { $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, NULL); } } }
/** * @param $rev */ public function upgrade_3_4_beta3($rev) { // do the regular upgrade $upgrade = new CRM_Upgrade_Form(); $upgrade->processSQL($rev); if ($upgrade->multilingual) { // rebuild schema, because due to a CRM-7854 mis-fix some indices might be missing CRM_Core_I18n_Schema::rebuildMultilingualSchema($upgrade->locales, $rev); // turn a set of columns singlelingual $config = CRM_Core_Config::singleton(); $tables = array('civicrm_address', 'civicrm_contact', 'civicrm_mailing', 'civicrm_mailing_component'); $triggers = array(array('when' => 'before', 'event' => 'update'), array('when' => 'before', 'event' => 'insert')); // FIXME: Doing require_once is a must here because a call like CRM_Core_I18n_SchemaStructure_3_4_beta2 makes // class loader look for file like - CRM/Core/I18n/SchemaStructure/3/4/beta2.php which is not what we want to be loaded require_once "CRM/Core/I18n/SchemaStructure_3_4_beta2.php"; foreach ($tables as $table) { CRM_Core_I18n_Schema::makeSinglelingualTable($config->lcMessages, $table, 'CRM_Core_I18n_SchemaStructure_3_4_beta2', $triggers); } } }
/** * @param $tplFile * @param $rev * * @return bool */ public function processLocales($tplFile, $rev) { $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('domainID', CRM_Core_Config::domainID()); $this->source($smarty->fetch($tplFile), TRUE); if ($this->multilingual) { CRM_Core_I18n_Schema::rebuildMultilingualSchema($this->locales, $rev); } return $this->multilingual; }
function processLocales($tplFile, $rev) { $smarty =& CRM_Core_Smarty::singleton(); $this->source($smarty->fetch($tplFile), true); if ($this->multilingual) { require_once 'CRM/Core/I18n/Schema.php'; CRM_Core_I18n_Schema::rebuildMultilingualSchema($this->locales, $rev); } return $this->multilingual; }
/** * CRM-18651 Add DataType column to Option Group Table * @return bool */ public static function addDataTypeColumnToOptionGroupTable() { if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_option_group', 'data_type')) { CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_group` ADD COLUMN `data_type` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL comment 'Data Type of Option Group.'", array(), TRUE, NULL, FALSE, FALSE); } $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); if ($domain->locales) { $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, NULL); } CRM_Core_DAO::executeQuery("UPDATE `civicrm_option_group` SET `data_type` = 'Integer'\n WHERE name IN ('activity_type', 'gender', 'payment_instrument', 'participant_role', 'event_type')"); return TRUE; }