$schedule->command('cubist:magic:precache')->everyFiveMinutes();
$schedule->command('job:dispatch ProcessTotals')->everyTwoHours();
+ $schedule->command('job:dispatch Maintenance\\CleanDownloads')->dailyAt('4:00');
$schedule->command('fluidbook:farm:ping')->everyMinute();
$schedule->command('fluidbook:player:updatesources')->everyTwoHours();
$schedule->command('ws:migrate --publications=v2 --documents=missing')->dailyAt('1:00');
--- /dev/null
+<?php
+
+namespace App\Jobs\Maintenance;
+
+use App\Jobs\Base;
+use Cubist\Util\Files\Files;
+
+class CleanDownloads extends Base
+{
+ public function handle()
+ {
+ $days = 15;
+ $limit = time() - (3600 * 24 * $days);
+
+ $directoriesToClean = [protected_path('signedexe/')];
+
+ $types = ['elearningmedia', 'elearningpackage', 'quiz', 'fluidbookcollection', 'fluidbookpublication'];
+ foreach ($types as $type) {
+ $directoriesToClean[] = storage_path('app/public/' . $type . '/download/');
+ $directoriesToClean[] = protected_path($type . '/final/');
+ }
+
+ foreach ($directoriesToClean as $path) {
+ if (!file_exists($path) || !is_dir($path)) {
+ continue;
+ }
+ $path = rtrim($path, '/');
+ $it = Files::getDirectoryIterator($path);
+ foreach ($it as $file) {
+ /** @var $file \SplFileInfo */
+ if ($file->isDot()) {
+ continue;
+ }
+ if ($file->isLink()) {
+ continue;
+ }
+ if ($file->getMTime() >= $limit) {
+ continue;
+ }
+ $pathname = $file->getPathname();
+ if ($file->isFile()) {
+ $type = 'file';
+ unlink($pathname);
+ } else {
+ $type = 'dir';
+ `rm -rf $pathname`;
+ }
+ echo "Deleted $type $pathname\n";
+ }
+ }
+ }
+}