Skip to content

Commit

Permalink
Show menu entry when a manual or automatic workflow is active (#199)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
justusdieckmann and justusdieckmann committed Mar 14, 2024
1 parent f1ef4a6 commit 33cbd05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions classes/local/manager/workflow_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ public static function activate_workflow($workflowid) {
/**
* Resets the 'does a manual workflow exist?'-cache.
*/
private static function reset_manual_workflow_cache() {
private static function reset_has_workflow_cache() {
$cache = \cache::make('tool_lifecycle', 'application');
$cache->delete('manualworkflowexists');
$cache->delete('workflowactive');
}

/**
Expand All @@ -292,7 +292,7 @@ public static function handle_action($action, $workflowid) {
}
if ($action === action::WORKFLOW_ACTIVATE) {
self::activate_workflow($workflowid);
self::reset_manual_workflow_cache();
self::reset_has_workflow_cache();
} else if ($action === action::UP_WORKFLOW) {
self::change_sortindex($workflowid, true);
} else if ($action === action::DOWN_WORKFLOW) {
Expand All @@ -303,12 +303,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();
self::reset_has_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();
self::reset_has_workflow_cache();
return; // Return, since we do not want to redirect outside to deactivated workflows.
} else if ($action === action::WORKFLOW_ABORT) {
self::abortprocesses($workflowid);
Expand All @@ -318,7 +318,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();
self::reset_has_workflow_cache();
} else {
\core\notification::add(get_string('workflow_not_removeable', 'tool_lifecycle')
, \core\notification::WARNING);
Expand Down
12 changes: 7 additions & 5 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ function tool_lifecycle_extend_navigation_course($navigation, $course, $context)
}

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

if (!$manualwfexists) {
if (!$wfexists) {
return null;
}

Expand Down

0 comments on commit 33cbd05

Please sign in to comment.