Skip to content

Commit 33cbd05

Browse files
Show menu entry when a manual or automatic workflow is active (#199)
* Show menu point when a manual or automatic workflow is active * Rename reset cache function * Show menu entry if there are workflows other than the default two --------- Co-authored-by: Justus Dieckmann <[email protected]>
1 parent f1ef4a6 commit 33cbd05

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

classes/local/manager/workflow_manager.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ public static function activate_workflow($workflowid) {
271271
/**
272272
* Resets the 'does a manual workflow exist?'-cache.
273273
*/
274-
private static function reset_manual_workflow_cache() {
274+
private static function reset_has_workflow_cache() {
275275
$cache = \cache::make('tool_lifecycle', 'application');
276-
$cache->delete('manualworkflowexists');
276+
$cache->delete('workflowactive');
277277
}
278278

279279
/**
@@ -292,7 +292,7 @@ public static function handle_action($action, $workflowid) {
292292
}
293293
if ($action === action::WORKFLOW_ACTIVATE) {
294294
self::activate_workflow($workflowid);
295-
self::reset_manual_workflow_cache();
295+
self::reset_has_workflow_cache();
296296
} else if ($action === action::UP_WORKFLOW) {
297297
self::change_sortindex($workflowid, true);
298298
} else if ($action === action::DOWN_WORKFLOW) {
@@ -303,12 +303,12 @@ public static function handle_action($action, $workflowid) {
303303
self::backup_workflow($workflowid);
304304
} else if ($action === action::WORKFLOW_DISABLE) {
305305
self::disable($workflowid);
306-
self::reset_manual_workflow_cache();
306+
self::reset_has_workflow_cache();
307307
return; // Return, since we do not want to redirect outside to deactivated workflows.
308308
} else if ($action === action::WORKFLOW_ABORTDISABLE) {
309309
self::disable($workflowid);
310310
self::abortprocesses($workflowid);
311-
self::reset_manual_workflow_cache();
311+
self::reset_has_workflow_cache();
312312
return; // Return, since we do not want to redirect outside to deactivated workflows.
313313
} else if ($action === action::WORKFLOW_ABORT) {
314314
self::abortprocesses($workflowid);
@@ -318,7 +318,7 @@ public static function handle_action($action, $workflowid) {
318318
if (self::get_workflow($workflowid) &&
319319
self::is_removable($workflowid)) {
320320
self::remove($workflowid);
321-
self::reset_manual_workflow_cache();
321+
self::reset_has_workflow_cache();
322322
} else {
323323
\core\notification::add(get_string('workflow_not_removeable', 'tool_lifecycle')
324324
, \core\notification::WARNING);

lib.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ function tool_lifecycle_extend_navigation_course($navigation, $course, $context)
4444
}
4545

4646
$cache = cache::make('tool_lifecycle', 'application');
47-
if ($cache->has('manualworkflowexists')) {
48-
$manualwfexists = $cache->get('manualworkflowexists');
47+
if ($cache->has('workflowactive')) {
48+
$wfexists = $cache->get('workflowactive');
4949
} else {
50-
$manualwfexists = $DB->record_exists_select('tool_lifecycle_workflow', 'manual = 1 AND timeactive IS NOT NULL');
51-
$cache->set('manualworkflowsexist', $manualwfexists);
50+
$wfexists = $DB->record_exists_sql("SELECT 'yes' FROM {tool_lifecycle_workflow} wf " .
51+
"JOIN {tool_lifecycle_trigger} t ON wf.id = t.workflowid " .
52+
"WHERE wf.timeactive IS NOT NULL AND t.subpluginname NOT IN ('sitecourse', 'delayedcourses')");
53+
$cache->set('workflowactive', $wfexists);
5254
}
5355

54-
if (!$manualwfexists) {
56+
if (!$wfexists) {
5557
return null;
5658
}
5759

0 commit comments

Comments
 (0)