From: Vincent Vanwaelscappel Date: Thu, 16 Feb 2023 09:41:19 +0000 (+0100) Subject: wip #5718 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=dad10020db2c2cdc76dac3239f852e7000ecc74b;p=fluidbook-toolbox.git wip #5718 @1 --- diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index a461fe906..02144204c 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -26,6 +26,7 @@ class Kernel extends \Cubist\Backpack\Console\Kernel { $schedule->command('queue:prune-failed --hours=24')->daily()->at('03:50'); $schedule->command('job:dispatch Maintenance\\\\CleanDownloads')->dailyAt('4:00'); + $schedule->command('job:dispatch Maintenance\\\\CleanFTP')->dailyAt('4:30'); // $schedule->command('backup:clean')->daily()->at('04:00'); // $schedule->command('backup:run')->daily()->at('05:00'); diff --git a/app/Jobs/Maintenance/CleanFTP.php b/app/Jobs/Maintenance/CleanFTP.php new file mode 100644 index 000000000..29cf98a85 --- /dev/null +++ b/app/Jobs/Maintenance/CleanFTP.php @@ -0,0 +1,15 @@ +setTimestamp($mtime); - $hash = Files::hashFileAttributes($pathname); + $hash = self::hash($pathname); $res[$hash] = [ 'path' => $pathname, @@ -129,6 +131,37 @@ class File extends ToolboxModel return $res; } + public static function clean() + { + $limit = time() - (92 * 3600 * 24); + $toDelete = File::whereNotIn('ext', ['apk', 'ipa'])->where('mtime', '<', $limit)->orderBy('mtime', 'ASC')->limit(10)->get(); + foreach ($toDelete as $f) { + /** @var $f File */ + echo "Delete " . $f->path . "\n"; + $f->delete(); + } + } + + public function onDeleting(): bool + { + $res = parent::onDeleting(); + unlink($this->path); + self::touchChangeFile(); + + return $res; + } + + public static function touchChangeFile() + { + touch(self::$basePath . '__LAST_CHANGE'); + } + + + public static function hash($pathname) + { + return sha1('!!//' . trim(str_replace(self::$basePath, '', $pathname), '/') . '||--'); + } + public function showPrimaryColumn() { return false;