Improve script to delete old unused courses

1.9.x
Yannick Warnier 10 years ago
parent e056271329
commit 0e6ec76906
  1. 17
      tests/scripts/delete_old_courses.php

@ -1,8 +1,15 @@
<?php
/**
* This script synchronize the exercise score (track_e_exercises.exe_result)
* with the LP score result (lp_item_view.score).
* This script works only if 1 there's one attempt
* This deletes courses that were created but no file was ever uploaded, and
* that were created previous to a specific date and last used previous to
* 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
* sessions. As such, it might delete courses but leave the course reference
* in the session, which would cause issues.
* Launch from the command line.
* Usage: php delete_old_courses.php
*/
exit;
@ -35,6 +42,8 @@ if (!empty($items)) {
foreach ($items as $item) {
$size = exec('du -sh '.__DIR__.'/../../courses/'.$item['directory']);
echo "Course ".$item['code'].'('.$item['id'].') created on '.$item['creation_date'].' and last used on '.$item['last_visit'].' uses '.substr($size, 0, 8).PHP_EOL;
// Check if it's 160K or 9.1M in size, which is the case for 'empty'
// courses (created without or with example content)
if (substr($size, 0, 4) == '160K' or substr($size, 0, 4) == '9,1M') {
CourseManager::delete_course($item['code']);
// The normal procedure moves the course directory to archive, so
@ -51,9 +60,11 @@ if (!empty($items)) {
}
$count ++;
if ($count%100 == 0) {
// Print progressive information about the freed space
echo '### Until now: '.$total.'K in '.$count.' courses'.PHP_EOL;
}
}
}
}
// Print final information about the freed space
echo $total.'K in '.$count.' courses'.PHP_EOL;

Loading…
Cancel
Save