Skip to content

Commit 570eaaa

Browse files
committed
Add support for skipping the recycle bin in 3.1
1 parent 3e59ad7 commit 570eaaa

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

db/delete-courses.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929

3030
$help = "Mass deletion of courses in a given category.
3131
32-
Example:
33-
\$ sudo -u www-data /usr/bin/php admin/cli/delete-courses.php --category=CATEGORYID
32+
Usage:
33+
delete-courses.php --category=<id> [--skip-recycle-bin]
34+
35+
Options:
36+
--category=<id> ID of the course category.
37+
--skip-recycle-bin Do not keep deleted courses in the recycle bin.
3438
";
3539

3640
define('CLI_SCRIPT', true);
@@ -41,10 +45,11 @@
4145
list($options, $unrecognized) = cli_get_params(
4246
array(
4347
'category' => null,
48+
'skip-recycle-bin' => false,
4449
'help' => false
4550
),
4651
array(
47-
'h' => 'help'
52+
'h' => 'help',
4853
)
4954
);
5055

@@ -89,6 +94,11 @@
8994

9095
$done = 0;
9196
foreach ($courses as $course) {
97+
if ($options['skip-recycle-bin']) {
98+
// This is a hack, we pretend to be executed by the restore process
99+
// so that the recycle bin hook is skipped.
100+
$course->deletesource = 'restore';
101+
}
92102
if (!delete_course($course, false)) {
93103
throw new moodle_exception('cannotdeletecategorycourse', '', '', $course->shortname);
94104
}
@@ -101,3 +111,4 @@
101111
cli_writeln($help);
102112
}
103113

114+
cache_helper::purge_by_event('changesincoursecat');

0 commit comments

Comments
 (0)