Skip to content

Commit

Permalink
Remove category based dynamic item cache deletion method.
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Aug 9, 2023
1 parent 62de05d commit 8e0c9e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 56 deletions.
27 changes: 4 additions & 23 deletions classes/eventobservers.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,10 @@ public static function course_updated(\core\event\base $event) {
// Require smart menus library.
require_once($CFG->dirroot . '/theme/boost_union/smartmenus/menulib.php');

// Course is moved to another category, Event data only contains the newer category.
// Update the cache for new category, added the updated course in that menu item,
// But the previous category of the course still hold this course.
// Therefore need to delete all the items which are configured as dynamic courses.
if (isset($event->other['updatedfields'])) {
if (in_array('category', array_keys($event->other['updatedfields']))) {
// Purge all the dynamic course items cache.
\smartmenu_helper::purge_cache_dynamic_courseitems();
return true;
}
}
// Purge all the dynamic course items cache.
\smartmenu_helper::purge_cache_dynamic_courseitems();

// Fetch category id of the deleted course from the record snapshot.
// Get category using normal get_course throw course not find error.
if ($event->action == 'deleted') {
$record = $event->get_record_snapshot($event->objecttable, $event->objectid);
if (!empty($record)) {
\smartmenu_helper::purge_cache_updated_category($record->category);
}
return true;
}
// Clear the cache of menu when the course updated.
\smartmenu_helper::purge_cache_updated_course($event->objectid);
return true;
}

/**
Expand All @@ -209,7 +190,7 @@ public static function category_updated(\core\event\base $event) {
require_once($CFG->dirroot . '/theme/boost_union/smartmenus/menulib.php');

// Clear the cache of menu when the course updated.
\smartmenu_helper::purge_cache_updated_category($event->objectid);
\smartmenu_helper::purge_cache_dynamic_courseitems();
}

/**
Expand Down
33 changes: 0 additions & 33 deletions smartmenus/menulib.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,39 +486,6 @@ public static function purge_cache_session_roles(int $roleid, int $userid) {
}
}

/**
* Purge the cache of items and menus which is configured to use the affected course category.
*
* @param int $courseid
* @return void
*/
public static function purge_cache_updated_course($courseid) {
// Fetch affected course data.
$course = get_course($courseid);
if ($items = self::find_condition_used_menuitems($course->category, 'category')) {
// List of items to purge.
$items = array_column($items, 'id');
// Remove the menus items for the user.
array_walk($items, ['self', 'purge_item_cache']);
}
}

/**
* Purge the cache of items and menus which is configured to use the affected course category.
*
* @param int $categoryid
* @return void
*/
public static function purge_cache_updated_category($categoryid) {
// Fetch list of menuitems, configured with the event categoryid.
if ($items = self::find_condition_used_menuitems($categoryid, 'category')) {
// List of items to purge.
$items = array_column($items, 'id');
// Remove the menus items for the user.
array_walk($items, ['self', 'purge_item_cache']);
}
}

/**
* Purge the cache of dynamic course items.
*
Expand Down

0 comments on commit 8e0c9e2

Please sign in to comment.