예제 #1
0
 /**
  * Switch database from single-lang to multi (by adding
  * the first language and dropping the original columns).
  *
  * @param string $locale
  *   the first locale to create (migrate to).
  */
 public static function makeMultilingual($locale)
 {
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     // break early if the db is already multi-lang
     if ($domain->locales) {
         return;
     }
     $dao = new CRM_Core_DAO();
     // build the column-adding SQL queries
     $columns = CRM_Core_I18n_SchemaStructure::columns();
     $indices = CRM_Core_I18n_SchemaStructure::indices();
     $queries = array();
     foreach ($columns as $table => $hash) {
         // drop old indices
         if (isset($indices[$table])) {
             foreach ($indices[$table] as $index) {
                 if (CRM_Core_BAO_SchemaHandler::checkIfIndexExists($table, $index['name'])) {
                     $queries[] = "DROP INDEX {$index['name']} ON {$table}";
                 }
             }
         }
         // deal with columns
         foreach ($hash as $column => $type) {
             $queries[] = "ALTER TABLE {$table} ADD {$column}_{$locale} {$type}";
             if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists($table, $column)) {
                 $queries[] = "UPDATE {$table} SET {$column}_{$locale} = {$column}";
                 $queries[] = "ALTER TABLE {$table} DROP {$column}";
             }
         }
         // add view
         $queries[] = self::createViewQuery($locale, $table, $dao);
         // add new indices
         $queries = array_merge($queries, array_values(self::createIndexQueries($locale, $table)));
     }
     // execute the queries without i18n rewriting
     foreach ($queries as $query) {
         $dao->query($query, FALSE);
     }
     // update civicrm_domain.locales
     $domain->locales = $locale;
     $domain->save();
 }
예제 #2
0
 /**
  * @param $tableName
  * @param $columnName
  *
  * @dataProvider columnTests
  */
 public function testCheckIfColumnExists($tableName, $columnName)
 {
     if ($columnName == 'xxxx') {
         $this->assertFalse(CRM_Core_BAO_SchemaHandler::checkIfFieldExists($tableName, $columnName));
     } else {
         $this->assertTrue(CRM_Core_BAO_SchemaHandler::checkIfFieldExists($tableName, $columnName));
     }
 }
예제 #3
0
 /**
  * CRM-19372 Add field to store accepted credit credit cards for a payment processor.
  * @return bool
  */
 public static function addAcceptedCardTypesField()
 {
     if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_payment_processor', 'accepted_credit_cards')) {
         CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_payment_processor ADD COLUMN `accepted_credit_cards` text   DEFAULT NULL COMMENT 'array of accepted credit card types'");
     }
     return TRUE;
 }
예제 #4
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;
 }