Scripts: Update course deletion script documentation - refs BT#19673

pull/4271/head
Yannick Warnier 4 years ago
parent 3ef3a7a018
commit 01f4257913
  1. 22
      tests/scripts/delete_old_courses.php

@ -5,32 +5,38 @@
* another specific date (see $creation and $access)
* Use this script with caution, as it will completely remove any trace of the
* deleted courses.
* Please note that this is not written with the inclusion of the concept ot
* Please note that this is not written with the inclusion of the concept of
* sessions. As such, it might delete courses but leave the course reference
* in the session, which would cause issues.
* Only deletes courses that are considered empty or "only with demo content".
* Launch from the command line.
* Usage: php delete_old_courses.php
*/
exit;
$creation = '2014-01-01';
$access = '2014-07-01';
require_once '../../main/inc/global.inc.php';
if (PHP_SAPI !== 'cli') {
die('This script can only be executed from the command line');
}
// The date before which the course must have been created to be considered
$creation = '2019-06-14';
// The last date at which the course must have been accessed to be considered.
// If it was accessed *after* that date, it will NOT be considered for deletion.
$access = '2019-06-14';
$tableExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT
id, code, directory, db_name, creation_date, last_visit
id, code, directory, creation_date, last_visit
FROM $tableCourse c
WHERE creation_date < '$creation' AND last_visit < '$access'
ORDER by code
WHERE creation_date < '$creation' AND (last_visit < '$access' OR last_visit IS NULL) ".
// Set course codes and uncomment the next line to exclude these from deletion
// " AND c.code NOT IN ('CHAMILOSESSIONS1ES','CHACOBU1ESPRE','CHAPA1ESPRE','CHAPA1FRX','CHACOBU1FRX','CHAPA1ESX','CHACOBU1ESX','DESIGNCHAMILO','EXELEARNING','CHAPA1ENX','CHACOBU1ENX') ".
" ORDER by code
";
echo $sql.PHP_EOL;
@ -51,7 +57,7 @@ if (!empty($items)) {
echo('rm -rf '.__DIR__.'/../../archive/'.$item['directory'].'_*').PHP_EOL;
exec('rm -rf '.__DIR__.'/../../archive/'.$item['directory'].'_*');
// The normal procedure also created a database dump, but it is
// stored in the course folder, so no issue there...
// stored in the course folder, so no issue there...
if (substr($size, 0, 4) == '160K') {
$total += 160;
}

Loading…
Cancel
Save