Example #1
0
 /**
  * Build a list of triggers via hook and add them to (err, reconcile them
  * with) the database.
  *
  * @param string $tableName
  *   the specific table requiring a rebuild; or NULL to rebuild all tables.
  * @param bool $force
  *
  * @see CRM-9716
  */
 public function rebuild($tableName = NULL, $force = FALSE)
 {
     $info = array();
     $logging = new \CRM_Logging_Schema();
     $logging->triggerInfo($info, $tableName, $force);
     \CRM_Core_I18n_Schema::triggerInfo($info, $tableName);
     \CRM_Contact_BAO_Contact::triggerInfo($info, $tableName);
     \CRM_Utils_Hook::triggerInfo($info, $tableName);
     // drop all existing triggers on all tables
     $logging->dropTriggers($tableName);
     // now create the set of new triggers
     $this->createTriggers($info, $tableName);
 }
 public function testOptionLanguage()
 {
     $this->callAPISuccess('Setting', 'create', array('lcMessages' => 'en_US', 'languageLimit' => array('en_US' => 1)));
     CRM_Core_I18n_Schema::makeMultilingual('en_US');
     global $dbLocale;
     $dbLocale = '_en_US';
     CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US');
     $this->callAPISuccess('Setting', 'create', array('languageLimit' => array('en_US', 'fr_CA')));
     // Take a semi-random OptionGroup and test manually changing its label
     // in one language, while making sure it stays the same in English.
     $group = $this->callAPISuccess('OptionGroup', 'getsingle', array('name' => 'contact_edit_options'));
     $english_original = $this->callAPISuccess('OptionValue', 'getsingle', array('option_group_id' => $group['id'], 'name' => 'IM'));
     $this->callAPISuccess('OptionValue', 'create', array('id' => $english_original['id'], 'name' => 'IM', 'label' => 'Messagerie instantanée', 'option.language' => 'fr_CA'));
     $french = $this->callAPISuccess('OptionValue', 'getsingle', array('option_group_id' => $group['id'], 'name' => 'IM', 'option.language' => 'fr_CA'));
     $default = $this->callAPISuccess('OptionValue', 'getsingle', array('option_group_id' => $group['id'], 'name' => 'IM', 'option.language' => 'en_US'));
     $this->assertEquals($french['label'], 'Messagerie instantanée');
     $this->assertEquals($default['label'], $english_original['label']);
 }
Example #3
0
 /**
  * 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();
 }
Example #4
0
 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');
 }
Example #5
0
 public function postProcess()
 {
     $values = $this->exportValues();
     //cache contact fields retaining localized titles
     //though we changed localization, so reseting cache.
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
     CRM_Core_BAO_Cache::deleteGroup('navigation');
     // we do this only to initialize monetary decimal point and thousand separator
     $config = CRM_Core_Config::singleton();
     // save enabled currencies and defaul currency in option group 'currencies_enabled'
     // CRM-1496
     if (empty($values['currencyLimit'])) {
         $values['currencyLimit'] = array($values['defaultCurrency']);
     } elseif (!in_array($values['defaultCurrency'], $values['currencyLimit'])) {
         $values['currencyLimit'][] = $values['defaultCurrency'];
     }
     // sort so that when we display drop down, weights have right value
     sort($values['currencyLimit']);
     // get labels for all the currencies
     $options = array();
     $currencySymbols = self::getCurrencySymbols();
     for ($i = 0; $i < count($values['currencyLimit']); $i++) {
         $options[] = array('label' => $currencySymbols[$values['currencyLimit'][$i]], 'value' => $values['currencyLimit'][$i], 'weight' => $i + 1, 'is_active' => 1, 'is_default' => $values['currencyLimit'][$i] == $values['defaultCurrency']);
     }
     $dontCare = NULL;
     CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare);
     // unset currencyLimit so we dont store there
     unset($values['currencyLimit']);
     // make the site multi-lang if requested
     if (!empty($values['makeMultilingual'])) {
         CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']);
         $values['languageLimit'][$values['lcMessages']] = 1;
         // make the site single-lang if requested
     } elseif (!empty($values['makeSinglelingual'])) {
         CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']);
         $values['languageLimit'] = '';
     }
     // add a new db locale if the requested language is not yet supported by the db
     if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) {
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(TRUE);
         if (!substr_count($domain->locales, $values['addLanguage'])) {
             CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']);
         }
         $values['languageLimit'][$values['addLanguage']] = 1;
     }
     // if we manipulated the language list, return to the localization admin screen
     $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values));
     $filteredValues = $values;
     unset($filteredValues['makeMultilingual']);
     unset($filteredValues['makeSinglelingual']);
     unset($filteredValues['addLanguage']);
     unset($filteredValues['languageLimit']);
     Civi::settings()->set('languageLimit', CRM_Utils_Array::value('languageLimit', $values));
     // save all the settings
     parent::commonProcess($filteredValues);
     if ($return) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1'));
     }
 }
Example #6
0
 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);
     }
 }
Example #8
0
 static function dropAllTables()
 {
     // first drop all the custom tables we've created
     require_once 'CRM/Core/BAO/CustomGroup.php';
     CRM_Core_BAO_CustomGroup::dropAllTables();
     // drop all multilingual views
     require_once 'CRM/Core/I18n/Schema.php';
     CRM_Core_I18n_Schema::dropAllViews();
     require_once 'CRM/Utils/File.php';
     CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . 'civicrm_drop.mysql');
 }
 static function triggerRebuild($tableName = NULL)
 {
     $info = array();
     $logging = new CRM_Logging_Schema();
     $logging->triggerInfo($info, $tableName);
     CRM_Core_I18n_Schema::triggerInfo($info, $tableName);
     CRM_Utils_Hook::triggerInfo($info, $tableName);
     // drop all existing triggers on all tables
     $logging->dropTriggers($tableName);
     // now create the set of new triggers
     self::createTriggers($info);
 }
Example #10
0
 /**
  * @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);
         }
     }
 }
Example #11
0
 /**
  * @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);
         }
     }
 }
Example #12
0
 /**
  * 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;
 }
Example #13
0
 public static function dropAllTables()
 {
     // first drop all the custom tables we've created
     CRM_Core_BAO_CustomGroup::dropAllTables();
     // drop all multilingual views
     CRM_Core_I18n_Schema::dropAllViews();
     CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . 'civicrm_drop.mysql');
 }
Example #14
0
 /**
  * @param $rev
  */
 public function setSchemaStructureTables($rev)
 {
     if ($this->multilingual) {
         CRM_Core_I18n_Schema::schemaStructureTables($rev, TRUE);
     }
 }
Example #15
0
 public function postProcess()
 {
     $values = $this->exportValues();
     // make the site multi-lang if requested
     if (CRM_Utils_Array::value('makeMultilingual', $values)) {
         require_once 'CRM/Core/I18n/Schema.php';
         CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']);
         $values['languageLimit'][$values['lcMessages']] = 1;
         // make the site single-lang if requested
     } elseif (CRM_Utils_Array::value('makeSinglelingual', $values)) {
         require_once 'CRM/Core/I18n/Schema.php';
         CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']);
     }
     // add a new db locale if the requested language is not yet supported by the db
     if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) {
         require_once 'CRM/Core/DAO/Domain.php';
         $domain =& new CRM_Core_DAO_Domain();
         $domain->find(true);
         if (!substr_count($domain->locales, $values['addLanguage'])) {
             require_once 'CRM/Core/I18n/Schema.php';
             CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']);
         }
         $values['languageLimit'][$values['addLanguage']] = 1;
     }
     // if we manipulated the language list, return to the localization admin screen
     $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values) or CRM_Utils_Array::value('makeSinglelingual', $values));
     //cache contact fields retaining localized titles
     //though we changed localization, so reseting cache.
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     // we do this only to initialize monetary decimal point and thousand separator
     $config =& CRM_Core_Config::singleton();
     if ($monetaryPointSeparator = $config->defaultMonetaryPointSeparator($values['lcMonetary'])) {
         $values['monetaryDecimalPoint'] = CRM_Utils_Array::value('decimal_point', $monetaryPointSeparator);
         $values['monetaryThousandSeparator'] = CRM_Utils_Array::value('thousands_sep', $monetaryPointSeparator);
     }
     // save all the settings
     parent::commonProcess($values);
     if ($return) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1'));
     }
 }
/**
 * Help function: if we are multi-lingual, rewrite the
 * given query.
 **/
function sumfields_multilingual_rewrite($query)
{
    global $dbLocale;
    if ($dbLocale) {
        return CRM_Core_I18n_Schema::rewriteQuery($query);
    }
    return $query;
}
Example #17
0
 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;
 }