Path: blob/1.0-develop/app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php
7461 views
<?php12namespace Pterodactyl\Console\Commands\Maintenance;34use Carbon\Carbon;5use Illuminate\Console\Command;6use Illuminate\Contracts\Filesystem\Filesystem;7use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;89class CleanServiceBackupFilesCommand extends Command10{11public const BACKUP_THRESHOLD_MINUTES = 5;1213protected $description = 'Clean orphaned .bak files created when modifying services.';1415protected $signature = 'p:maintenance:clean-service-backups';1617protected Filesystem $disk;1819/**20* CleanServiceBackupFilesCommand constructor.21*/22public function __construct(FilesystemFactory $filesystem)23{24parent::__construct();2526$this->disk = $filesystem->disk();27}2829/**30* Handle command execution.31*/32public function handle()33{34$files = $this->disk->files('services/.bak');3536collect($files)->each(function (\SplFileInfo $file) {37$lastModified = Carbon::createFromTimestamp($this->disk->lastModified($file->getPath()));38if ((int) $lastModified->diffInMinutes(Carbon::now()) > self::BACKUP_THRESHOLD_MINUTES) {39$this->disk->delete($file->getPath());40$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file->getFilename()]));41}42});43}44}454647