Skip to content

Commit

Permalink
APIv4 - Flush navigation caches after writing or deleting navigation …
Browse files Browse the repository at this point in the history
…item

Historically the expectation was that this cache gets flushed manually.
I've kept that unchanged for legacy code (v3 create/delete and direct BAO::add)
but with APIv4 and onward the cache will get flushed automatically after a write operation.
  • Loading branch information
colemanw committed Jul 18, 2022
1 parent 215461c commit 43f09f8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions CRM/Core/BAO/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,42 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation {
// Number of characters in the menu js cache key
const CACHE_KEY_STRLEN = 8;

/**
* Override parent method to flush caches after a write op.
*
* Note: this only applies to APIv4 because v3 uses the singular writeRecord.
*
* @param array[] $records
* @return CRM_Core_DAO_Navigation[]
* @throws CRM_Core_Exception
*/
public static function writeRecords($records): array {
$results = [];
foreach ($records as $record) {
$results[] = self::writeRecord($record);
}
self::resetNavigation();
return $results;
}

/**
* Override parent method to flush caches after delete.
*
* Note: this only applies to APIv4 because v3 uses the singular writeRecord.
*
* @param array[] $records
* @return CRM_Core_DAO_Navigation[]
* @throws CRM_Core_Exception
*/
public static function deleteRecords(array $records) {
$results = [];
foreach ($records as $record) {
$results[] = self::deleteRecord($record);
}
self::resetNavigation();
return $results;
}

/**
* Update the is_active flag in the db.
*
Expand Down

0 comments on commit 43f09f8

Please sign in to comment.