Skip to content

Instantly share code, notes, and snippets.

@MegaphoneJon
Last active March 1, 2023 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MegaphoneJon/ac0f50b2756badb61f2a42ae158abd01 to your computer and use it in GitHub Desktop.
Save MegaphoneJon/ac0f50b2756badb61f2a42ae158abd01 to your computer and use it in GitHub Desktop.
--- a/vendor/civicrm/civicrm-core/CRM/Core/I18n/Schema.php 2023-03-01 16:30:27.347351588 -0500
+++ b/vendor/civicrm/civicrm-core/CRM/Core/I18n/Schema.php 2023-03-01 16:26:53.196516104 -0500
@@ -303,9 +303,15 @@
}
// rebuild views
+ $config = CRM_Core_Config::singleton();
+
foreach ($locales as $locale) {
foreach ($tables as $table) {
$queries[] = self::createViewQuery($locale, $table, $dao, $class, $isUpgradeMode);
+
+ if ($config->logging) {
+ $queries[] = self::createViewQuery($locale, 'log_' . $table, $dao, $class, $isUpgradeMode);
+ }
}
}
@@ -458,10 +464,21 @@
$columns =& $class::columns();
$cols = [];
$tableCols = [];
- $dao->query("DESCRIBE {$table}", FALSE);
+ $db = $dao->_database;
+ $lookup_table = $table;
+ if (substr($table, 0, 4) == 'log_') {
+ $lookup_table = substr($table, 4);
+ $dsn = defined('CIVICRM_LOGGING_DSN') ? CRM_Utils_SQL::autoSwitchDSN(CIVICRM_LOGGING_DSN) : CRM_Utils_SQL::autoSwitchDSN(CIVICRM_DSN);
+ $dsn = DB::parseDSN($dsn);
+ $db = $dsn['database'];
+ }
+ $dao->query("DESCRIBE `{$db}`.{$table}", FALSE);
+
+
+
while ($dao->fetch()) {
// view non-internationalized columns directly
- if (!array_key_exists($dao->Field, $columns[$table]) &&
+ if (!array_key_exists($dao->Field, $columns[$lookup_table]) &&
!preg_match('/_[a-z][a-z]_[A-Z][A-Z]$/', $dao->Field)
) {
$cols[] = '`' . $dao->Field . '`';
@@ -469,7 +486,7 @@
$tableCols[] = $dao->Field;
}
// view internationalized columns through an alias
- foreach ($columns[$table] as $column => $_) {
+ foreach ($columns[$lookup_table] as $column => $_) {
if (!$isUpgradeMode) {
$cols[] = "`{$column}_{$locale}` `{$column}`";
}
@@ -477,7 +494,8 @@
$cols[] = "`{$column}_{$locale}` `{$column}`";
}
}
- return "CREATE OR REPLACE VIEW {$table}_{$locale} AS SELECT " . implode(', ', $cols) . " FROM {$table}";
+
+ return "CREATE OR REPLACE VIEW `{$db}`.{$table}_{$locale} AS SELECT " . implode(', ', $cols) . " FROM `{$db}`.{$table}";
}
/**
@MegaphoneJon
Copy link
Author

This is a direct copy of https://lab.civicrm.org/dev/translation/-/snippets/2, which you need to log in to view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment