11<?php
2- /**
3- * Pterodactyl - Panel
4- * Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5- *
6- * This software is licensed under the terms of the MIT license.
7- * https://opensource.org/licenses/MIT
8- */
92
103namespace Pterodactyl \Console \Commands \Maintenance ;
114
125use Carbon \Carbon ;
136use Illuminate \Console \Command ;
7+ use Symfony \Component \Finder \SplFileInfo ;
148use Illuminate \Contracts \Filesystem \Factory as FilesystemFactory ;
159
1610class CleanServiceBackupFilesCommand extends Command
1711{
1812 const BACKUP_THRESHOLD_MINUTES = 5 ;
1913
20- /**
21- * @var \Carbon\Carbon
22- */
23- protected $ carbon ;
24-
2514 /**
2615 * @var string
2716 */
@@ -40,14 +29,12 @@ class CleanServiceBackupFilesCommand extends Command
4029 /**
4130 * CleanServiceBackupFilesCommand constructor.
4231 *
43- * @param \Carbon\Carbon $carbon
4432 * @param \Illuminate\Contracts\Filesystem\Factory $filesystem
4533 */
46- public function __construct (Carbon $ carbon , FilesystemFactory $ filesystem )
34+ public function __construct (FilesystemFactory $ filesystem )
4735 {
4836 parent ::__construct ();
4937
50- $ this ->carbon = $ carbon ;
5138 $ this ->disk = $ filesystem ->disk ();
5239 }
5340
@@ -58,11 +45,11 @@ public function handle()
5845 {
5946 $ files = $ this ->disk ->files ('services/.bak ' );
6047
61- collect ($ files )->each (function ($ file ) {
62- $ lastModified = $ this -> carbon -> timestamp ($ this ->disk ->lastModified ($ file ));
63- if ($ lastModified ->diffInMinutes ($ this -> carbon -> now ()) > self ::BACKUP_THRESHOLD_MINUTES ) {
64- $ this ->disk ->delete ($ file );
65- $ this ->info (trans ('command/messages.maintenance.deleting_service_backup ' , ['file ' => $ file ]));
48+ collect ($ files )->each (function (SplFileInfo $ file ) {
49+ $ lastModified = Carbon:: createFromTimestamp ($ this ->disk ->lastModified ($ file-> getPath () ));
50+ if ($ lastModified ->diffInMinutes (Carbon:: now ()) > self ::BACKUP_THRESHOLD_MINUTES ) {
51+ $ this ->disk ->delete ($ file-> getPath () );
52+ $ this ->info (trans ('command/messages.maintenance.deleting_service_backup ' , ['file ' => $ file-> getFilename () ]));
6653 }
6754 });
6855 }
0 commit comments