diff --git a/classes/local/manager/workflow_manager.php b/classes/local/manager/workflow_manager.php index 97465f54..25c09b82 100644 --- a/classes/local/manager/workflow_manager.php +++ b/classes/local/manager/workflow_manager.php @@ -244,6 +244,14 @@ public static function activate_workflow($workflowid) { $transaction->allow_commit(); } + /** + * Resets the 'does a manual workflow exist?'-cache. + */ + private static function reset_manual_workflow_cache() { + $cache = \cache::make('tool_lifecycle', 'application'); + $cache->delete('manualworkflowexists'); + } + /** * Handles an action of the subplugin_settings. * @@ -260,6 +268,7 @@ public static function handle_action($action, $workflowid) { } if ($action === action::WORKFLOW_ACTIVATE) { self::activate_workflow($workflowid); + self::reset_manual_workflow_cache(); } else if ($action === action::UP_WORKFLOW) { self::change_sortindex($workflowid, true); } else if ($action === action::DOWN_WORKFLOW) { @@ -270,10 +279,12 @@ public static function handle_action($action, $workflowid) { self::backup_workflow($workflowid); } else if ($action === action::WORKFLOW_DISABLE) { self::disable($workflowid); + self::reset_manual_workflow_cache(); return; // Return, since we do not want to redirect outside to deactivated workflows. } else if ($action === action::WORKFLOW_ABORTDISABLE) { self::disable($workflowid); self::abortprocesses($workflowid); + self::reset_manual_workflow_cache(); return; // Return, since we do not want to redirect outside to deactivated workflows. } else if ($action === action::WORKFLOW_ABORT) { self::abortprocesses($workflowid); @@ -283,6 +294,7 @@ public static function handle_action($action, $workflowid) { if (self::get_workflow($workflowid) && self::is_removable($workflowid)) { self::remove($workflowid); + self::reset_manual_workflow_cache(); } else { \core\notification::add(get_string('workflow_not_removeable', 'tool_lifecycle') , \core\notification::WARNING); diff --git a/db/caches.php b/db/caches.php index 6335a0b2..a475590c 100644 --- a/db/caches.php +++ b/db/caches.php @@ -28,4 +28,9 @@ 'mformdata' => [ 'mode' => cache_store::MODE_SESSION, ], + 'application' => [ + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true + ] ]; diff --git a/lib.php b/lib.php index 28be8395..e54a64bf 100644 --- a/lib.php +++ b/lib.php @@ -32,7 +32,7 @@ * @throws moodle_exception */ function tool_lifecycle_extend_navigation_course($navigation, $course, $context) { - global $PAGE; + global $DB, $PAGE; // Only add this settings item on non-site course pages. if (!$PAGE->course || $PAGE->course->id == SITEID) { @@ -43,8 +43,17 @@ function tool_lifecycle_extend_navigation_course($navigation, $course, $context) return null; } - $url = null; - $settingnode = null; + $cache = cache::make('tool_lifecycle', 'application'); + if ($cache->has('manualworkflowexists')) { + $manualwfexists = $cache->get('manualworkflowexists'); + } else { + $manualwfexists = $DB->record_exists_select('tool_lifecycle_workflow', 'manual = 1 AND timeactive IS NOT NULL'); + $cache->set('manualworkflowsexist', $manualwfexists); + } + + if (!$manualwfexists) { + return null; + } $url = new moodle_url('/admin/tool/lifecycle/view.php', [ 'contextid' => $context->id, diff --git a/version.php b/version.php index 7fa410ae..28244903 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die; $plugin->maturity = MATURITY_BETA; -$plugin->version = 2023050200; +$plugin->version = 2024022000; $plugin->component = 'tool_lifecycle'; $plugin->requires = 2020061500; // Requires Moodle 3.9+. $plugin->release = 'v4.2-r1';