Пример #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
 /**
  * Test the drop index if exists function.
  */
 public function testDropIndexExists()
 {
     CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_contact', 'index_hash');
     $this->assertFalse(CRM_Core_BAO_SchemaHandler::checkIfIndexExists('civicrm_contact', 'index_hash'));
     // Recreate it to clean up after the test.
     CRM_Core_BAO_SchemaHandler::createIndexes(array('civicrm_contact' => array('hash')));
 }
Пример #3
0
 /**
  * CRM-17663 - Dashboard schema changes
  *
  * @param \CRM_Queue_TaskContext $ctx
  *
  * @return bool
  */
 public static function dashboardSchemaUpdate(CRM_Queue_TaskContext $ctx)
 {
     if (!CRM_Core_BAO_SchemaHandler::checkIfIndexExists('civicrm_dashboard_contact', 'index_dashboard_id_contact_id')) {
         // Delete any stray duplicate rows and add unique index to prevent new dupes and enable INSERT/UPDATE combo query
         CRM_Core_DAO::executeQuery('DELETE c1 FROM civicrm_dashboard_contact c1, civicrm_dashboard_contact c2 WHERE c1.contact_id = c2.contact_id AND c1.dashboard_id = c2.dashboard_id AND c1.id > c2.id');
         CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_dashboard_contact ADD UNIQUE INDEX index_dashboard_id_contact_id (dashboard_id, contact_id);');
     }
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard_contact', 'content');
     CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard_contact', 'is_minimized');
     CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard_contact', 'is_fullscreen');
     CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard_contact', 'created_date');
     CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard', 'is_fullscreen');
     CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard', 'is_minimized');
     CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard', 'column_no');
     CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard', 'weight');
     CRM_Core_DAO::executeQuery('UPDATE civicrm_dashboard SET url = REPLACE(url, "&snippet=5", ""), fullscreen_url = REPLACE(fullscreen_url, "&snippet=5", "")');
     if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_dashboard', 'cache_minutes')) {
         CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_dashboard ADD COLUMN cache_minutes int unsigned NOT NULL DEFAULT 60 COMMENT "Number of minutes to cache dashlet content in browser localStorage."', array(), TRUE, NULL, FALSE, FALSE);
     }
     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_dashboard SET cache_minutes = 1440 WHERE name = "blog"');
     CRM_Core_DAO::executeQuery('UPDATE civicrm_dashboard SET cache_minutes = 7200 WHERE name IN ("activity","getting-started")');
     return TRUE;
 }