Skip to content

Commit

Permalink
COMCL-603: Fix cache issue in schema difference calculation for log t…
Browse files Browse the repository at this point in the history
…ables

Included in

PR: civicrm#30697
  • Loading branch information
Muhammad Shahrukh authored and shahrukh-compuco committed Jul 17, 2024
1 parent 8e5d6bd commit 091ab2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions CRM/Logging/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,10 @@ public function getIndexesForTable($table) {
* name of the relevant table.
* @param array $cols
* Mixed array of columns to add or null (to check for the missing columns).
* @param bool $resetTableCache
* Refresh the cache for table before calculating the differences with log table.
*/
public function fixSchemaDifferencesFor(string $table, array $cols = []): void {
public function fixSchemaDifferencesFor(string $table, array $cols = [], bool $resetTableCache = FALSE): void {
if (!in_array($table, $this->tables, TRUE)) {
// Create the table if the log table does not exist and
// the table is in 'this->tables'. This latter array
Expand All @@ -441,13 +443,17 @@ public function fixSchemaDifferencesFor(string $table, array $cols = []): void {
return;
}

if ($resetTableCache) {
$this->resetSchemaCacheForTable($table);
}
$this->resetSchemaCacheForTable("log_$table");

if (empty($cols)) {
$cols = $this->columnsWithDiffSpecs($table, "log_$table");
}

// If a column that already exists on logging table is being added, we
// should treat it as a modification.
$this->resetSchemaCacheForTable("log_$table");
$logTableSchema = $this->columnSpecsOf("log_$table");
if (!empty($cols['ADD'])) {
foreach ($cols['ADD'] as $colKey => $col) {
Expand Down
6 changes: 3 additions & 3 deletions CRM/Upgrade/Incremental/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public static function addColumn($ctx, $table, $column, $properties, $localizabl
}
$schema = new CRM_Logging_Schema();
if ($schema->isEnabled()) {
$schema->fixSchemaDifferencesFor($table);
$schema->fixSchemaDifferencesFor($table, [], TRUE);
}
}
if ($locales && $triggerRebuild) {
Expand Down Expand Up @@ -613,7 +613,7 @@ public static function dropColumn($ctx, $table, $column) {
}
$schema = new CRM_Logging_Schema();
if ($schema->isEnabled()) {
$schema->fixSchemaDifferencesFor($table);
$schema->fixSchemaDifferencesFor($table, [], TRUE);
}
$locales = CRM_Core_I18n::getMultilingual();
if ($locales) {
Expand Down Expand Up @@ -720,7 +720,7 @@ public static function alterColumn($ctx, $table, $column, $properties, $localiza
}
$schema = new CRM_Logging_Schema();
if ($schema->isEnabled()) {
$schema->fixSchemaDifferencesFor($table);
$schema->fixSchemaDifferencesFor($table, [], TRUE);
}
if ($locales) {
CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, NULL, TRUE);
Expand Down

0 comments on commit 091ab2d

Please sign in to comment.