Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show menu entry when a manual or automatic workflow is active #199

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions classes/local/manager/workflow_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,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 @@ -268,7 +268,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 @@ -279,12 +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();
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 @@ -294,7 +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();
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
Loading