Skip to content

Commit a1166ed

Browse files
Hide menu when there is no manual workflow (#195)
Co-authored-by: Justus Dieckmann <[email protected]>
1 parent 421cc45 commit a1166ed

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

classes/local/manager/workflow_manager.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ public static function activate_workflow($workflowid) {
244244
$transaction->allow_commit();
245245
}
246246

247+
/**
248+
* Resets the 'does a manual workflow exist?'-cache.
249+
*/
250+
private static function reset_manual_workflow_cache() {
251+
$cache = \cache::make('tool_lifecycle', 'application');
252+
$cache->delete('manualworkflowexists');
253+
}
254+
247255
/**
248256
* Handles an action of the subplugin_settings.
249257
*
@@ -260,6 +268,7 @@ public static function handle_action($action, $workflowid) {
260268
}
261269
if ($action === action::WORKFLOW_ACTIVATE) {
262270
self::activate_workflow($workflowid);
271+
self::reset_manual_workflow_cache();
263272
} else if ($action === action::UP_WORKFLOW) {
264273
self::change_sortindex($workflowid, true);
265274
} else if ($action === action::DOWN_WORKFLOW) {
@@ -270,10 +279,12 @@ public static function handle_action($action, $workflowid) {
270279
self::backup_workflow($workflowid);
271280
} else if ($action === action::WORKFLOW_DISABLE) {
272281
self::disable($workflowid);
282+
self::reset_manual_workflow_cache();
273283
return; // Return, since we do not want to redirect outside to deactivated workflows.
274284
} else if ($action === action::WORKFLOW_ABORTDISABLE) {
275285
self::disable($workflowid);
276286
self::abortprocesses($workflowid);
287+
self::reset_manual_workflow_cache();
277288
return; // Return, since we do not want to redirect outside to deactivated workflows.
278289
} else if ($action === action::WORKFLOW_ABORT) {
279290
self::abortprocesses($workflowid);
@@ -283,6 +294,7 @@ public static function handle_action($action, $workflowid) {
283294
if (self::get_workflow($workflowid) &&
284295
self::is_removable($workflowid)) {
285296
self::remove($workflowid);
297+
self::reset_manual_workflow_cache();
286298
} else {
287299
\core\notification::add(get_string('workflow_not_removeable', 'tool_lifecycle')
288300
, \core\notification::WARNING);

db/caches.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@
2828
'mformdata' => [
2929
'mode' => cache_store::MODE_SESSION,
3030
],
31+
'application' => [
32+
'mode' => cache_store::MODE_APPLICATION,
33+
'simplekeys' => true,
34+
'simpledata' => true
35+
]
3136
];

lib.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @throws moodle_exception
3333
*/
3434
function tool_lifecycle_extend_navigation_course($navigation, $course, $context) {
35-
global $PAGE;
35+
global $DB, $PAGE;
3636

3737
// Only add this settings item on non-site course pages.
3838
if (!$PAGE->course || $PAGE->course->id == SITEID) {
@@ -43,8 +43,17 @@ function tool_lifecycle_extend_navigation_course($navigation, $course, $context)
4343
return null;
4444
}
4545

46-
$url = null;
47-
$settingnode = null;
46+
$cache = cache::make('tool_lifecycle', 'application');
47+
if ($cache->has('manualworkflowexists')) {
48+
$manualwfexists = $cache->get('manualworkflowexists');
49+
} else {
50+
$manualwfexists = $DB->record_exists_select('tool_lifecycle_workflow', 'manual = 1 AND timeactive IS NOT NULL');
51+
$cache->set('manualworkflowsexist', $manualwfexists);
52+
}
53+
54+
if (!$manualwfexists) {
55+
return null;
56+
}
4857

4958
$url = new moodle_url('/admin/tool/lifecycle/view.php', [
5059
'contextid' => $context->id,

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
defined('MOODLE_INTERNAL') || die;
2626

2727
$plugin->maturity = MATURITY_BETA;
28-
$plugin->version = 2023050200;
28+
$plugin->version = 2024022000;
2929
$plugin->component = 'tool_lifecycle';
3030
$plugin->requires = 2020061500; // Requires Moodle 3.9+.
3131
$plugin->release = 'v4.2-r1';

0 commit comments

Comments
 (0)