From: Coleman Watts Date: Mon, 18 Jul 2022 15:26:47 +0000 (-0400) Subject: APIv4 - Flush navigation caches after writing or deleting navigation item X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=cd6134ccf945da40a531d1e8d2c4f192c216f18d;p=civicrm-core.git APIv4 - Flush navigation caches after writing or deleting navigation 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. --- diff --git a/CRM/Core/BAO/Navigation.php b/CRM/Core/BAO/Navigation.php index 688d399d6f..f3e72a6b3f 100644 --- a/CRM/Core/BAO/Navigation.php +++ b/CRM/Core/BAO/Navigation.php @@ -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. *