/** * Rewrite SQL query to use views to access tables with localized columns. * * @param $query string the query for rewrite * @return string the rewritten query */ static function rewriteQuery($query) { static $tables = null; if ($tables === null) { $tables =& CRM_Core_I18n_SchemaStructure::tables(); } global $dbLocale; foreach ($tables as $table) { $query = preg_replace("/([^'\"])({$table})([^_'\"])/", "\\1\\2{$dbLocale}\\3", $query); } // uncomment the below to rewrite the civicrm_value_* queries // $query = preg_replace("/(civicrm_value_[a-z0-9_]+_\d+)([^_])/", "\\1{$dbLocale}\\2", $query); return $query; }
static function schemaStructureTables($version = NULL, $force = FALSE) { static $_tables = NULL; if ($_tables === NULL || $force) { if ($version) { $latest = self::getLatestSchema($version); // FIXME: Doing require_once is a must here because a call like CRM_Core_I18n_SchemaStructure_4_1_0 makes // class loader look for file like - CRM/Core/I18n/SchemaStructure/4/1/0.php which is not what we want to be loaded require_once "CRM/Core/I18n/SchemaStructure_{$latest}.php"; $class = "CRM_Core_I18n_SchemaStructure_{$latest}"; $tables =& $class::tables(); } else { $tables = CRM_Core_I18n_SchemaStructure::tables(); } $_tables = $tables; } return $_tables; }