Skip to content

Commit ccda2b6

Browse files
committed
Add more CLI commands for panel management
1 parent 763f7a9 commit ccda2b6

File tree

15 files changed

+494
-514
lines changed

15 files changed

+494
-514
lines changed

app/Console/Commands/AddNode.php

Lines changed: 0 additions & 110 deletions
This file was deleted.

app/Console/Commands/ClearTasks.php

Lines changed: 0 additions & 78 deletions
This file was deleted.

app/Console/Commands/ClearServices.php renamed to app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**
2+
/*
33
* Pterodactyl - Panel
44
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
55
*
@@ -22,66 +22,61 @@
2222
* SOFTWARE.
2323
*/
2424

25-
namespace Pterodactyl\Console\Commands;
25+
namespace Pterodactyl\Console\Commands\Maintenance;
2626

27-
use DB;
27+
use Carbon\Carbon;
2828
use Illuminate\Console\Command;
29+
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
2930

30-
class ClearServices extends Command
31+
class CleanServiceBackupFilesCommand extends Command
3132
{
3233
/**
33-
* The name and signature of the console command.
34-
*
34+
* @var \Carbon\Carbon
35+
*/
36+
protected $carbon;
37+
38+
/**
3539
* @var string
3640
*/
37-
protected $signature = 'pterodactyl:clear-services';
41+
protected $description = 'Clean orphaned .bak files created when modifying services.';
42+
43+
/**
44+
* @var \Illuminate\Contracts\Filesystem\Filesystem
45+
*/
46+
protected $disk;
3847

3948
/**
40-
* The console command description.
41-
*
4249
* @var string
4350
*/
44-
protected $description = 'Removes all services from the database for installing updated ones as needed.';
51+
protected $signature = 'p:maintenance:clean-service-backups';
4552

4653
/**
47-
* Create a new command instance.
54+
* CleanServiceBackupFilesCommand constructor.
55+
*
56+
* @param \Carbon\Carbon $carbon
57+
* @param \Illuminate\Contracts\Filesystem\Factory $filesystem
4858
*/
49-
public function __construct()
59+
public function __construct(Carbon $carbon, FilesystemFactory $filesystem)
5060
{
5161
parent::__construct();
62+
63+
$this->carbon = $carbon;
64+
$this->disk = $filesystem->disk();
5265
}
5366

5467
/**
55-
* Execute the console command.
56-
*
57-
* @return mixed
68+
* Handle command execution.
5869
*/
5970
public function handle()
6071
{
61-
if (! $this->confirm('This is a destructive operation, are you sure you wish to continue?')) {
62-
$this->error('Canceling.');
63-
exit();
64-
}
65-
66-
$bar = $this->output->createProgressBar(3);
67-
DB::beginTransaction();
68-
69-
try {
70-
DB::table('services')->truncate();
71-
$bar->advance();
72-
73-
DB::table('service_options')->truncate();
74-
$bar->advance();
75-
76-
DB::table('service_variables')->truncate();
77-
$bar->advance();
78-
79-
DB::commit();
80-
} catch (\Exception $ex) {
81-
DB::rollBack();
82-
}
72+
$files = $this->disk->files('services/.bak');
8373

84-
$this->info("\n");
85-
$this->info('All services have been removed. Consider running `php artisan pterodactyl:service-defaults` at this time.');
74+
collect($files)->each(function ($file) {
75+
$lastModified = $this->carbon->timestamp($this->disk->lastModified($file));
76+
if ($lastModified->diffInMinutes($this->carbon->now()) > 5) {
77+
$this->disk->delete($file);
78+
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file]));
79+
}
80+
});
8681
}
8782
}

0 commit comments

Comments
 (0)