Skip to content

Commit

Permalink
Hide menu when there is no manual workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Feb 20, 2024
1 parent dc8a0f9 commit 1025db9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
12 changes: 12 additions & 0 deletions classes/local/manager/workflow_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
'mformdata' => [
'mode' => cache_store::MODE_SESSION,
],
'application' => [
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => true
]
];
15 changes: 12 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 1025db9

Please sign in to comment.