{
$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');
protected $_operations = [DownloadOperation::class];
+ public static $basePath = '/application/ftp/';
+
public function setFields()
{
parent::setFields();
protected function ___listFilesOfUser($id)
{
- $path = '/application/ftp/' . $id;
+ $path = self::$basePath . $id;
if (!file_exists($path) || !is_dir($path)) {
return [];
}
$date = new \DateTime();
$date->setTimestamp($mtime);
- $hash = Files::hashFileAttributes($pathname);
+ $hash = self::hash($pathname);
$res[$hash] = [
'path' => $pathname,
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;