$item['last_visit']) { // The course has not been accessed by students since $access $courses[$item['c_id']] = $item['last_visit']; } } $sql = "SELECT id, code, directory, creation_date FROM $tableCourse WHERE id IN (".implode(',', array_keys($courses)).")"; $result = Database::query($sql); $items = Database::store_result($result, 'ASSOC'); if ($simulate) { echo $sql.PHP_EOL; } echo "Found ".count($items)." courses matching the given dates.".PHP_EOL; $total = 0; $count = 0; if (!empty($items)) { foreach ($items as $item) { $size = exec('du -sh '.__DIR__.'/../../app/courses/'.$item['directory']); list($mysize, $mypath) = preg_split('/\t/', $size); $size = trim($mysize); echo "[$count] Course ".$item['code'].'('.$item['id'].') created on '.$item['creation_date'].' and last used on '.date('Y-m-d', $courses[$item['id']]).' uses '.$size.PHP_EOL; echo('rm -rf '.__DIR__.'/../../app/courses/'.$item['directory']).PHP_EOL; echo('rm -rf '.__DIR__.'/../../app/cache/'.$item['directory'].'_*').PHP_EOL; if (!$simulate) { CourseManager::delete_course($item['code']); // The normal procedure moves the course directory to archive, so // delete it there as well exec('rm -rf '.__DIR__.'/../../app/courses/'.$item['directory']); exec('rm -rf '.__DIR__.'/../../app/cache/'.$item['directory'].'_*'); } // The normal procedure also created a database dump, but it is // stored in the course folder, so no issue there... $matches = []; preg_match('/^(\d+)(\D)$/', $size, $matches); switch($matches[2]) { case 'K': $total += $matches[1]; break; case 'M': $total += $matches[1]*1024; break; case 'G': $total += $matches[1]*1024*1024; break; } $count ++; if ($count%100 == 0) { echo '### Until now: '.$total.'K in '.$count.' courses'.PHP_EOL; } } } echo round($total / (1024)).'MB in '.$count.' courses'.PHP_EOL;