2017-11-04 04:07:18 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-23 20:09:16 +00:00
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2022-05-15 18:40:19 +00:00
|
|
|
use Pterodactyl\Models\Egg;
|
2017-11-04 04:07:18 +00:00
|
|
|
use Pterodactyl\Models\Nest;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
use Pterodactyl\Services\Eggs\Sharing\EggImporterService;
|
|
|
|
use Pterodactyl\Services\Eggs\Sharing\EggUpdateImporterService;
|
|
|
|
|
|
|
|
class EggSeeder extends Seeder
|
|
|
|
{
|
2022-05-15 18:40:19 +00:00
|
|
|
protected EggImporterService $importerService;
|
2017-11-04 04:07:18 +00:00
|
|
|
|
2022-05-15 18:40:19 +00:00
|
|
|
protected EggUpdateImporterService $updateImporterService;
|
2017-11-04 04:07:18 +00:00
|
|
|
|
|
|
|
/**
|
2022-05-15 18:40:19 +00:00
|
|
|
* @var string[]
|
2017-11-04 04:07:18 +00:00
|
|
|
*/
|
2022-05-15 18:40:19 +00:00
|
|
|
public static array $import = [
|
|
|
|
'Minecraft',
|
|
|
|
'Source Engine',
|
|
|
|
'Voice Servers',
|
|
|
|
'Rust',
|
|
|
|
];
|
2017-11-04 04:07:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* EggSeeder constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
EggImporterService $importerService,
|
2022-05-15 18:40:19 +00:00
|
|
|
EggUpdateImporterService $updateImporterService
|
2017-11-04 04:07:18 +00:00
|
|
|
) {
|
|
|
|
$this->importerService = $importerService;
|
|
|
|
$this->updateImporterService = $updateImporterService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the egg seeder.
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2022-05-15 18:40:19 +00:00
|
|
|
foreach (static::$import as $nest) {
|
|
|
|
/* @noinspection PhpParamsInspection */
|
|
|
|
$this->parseEggFiles(
|
|
|
|
Nest::query()->where('author', 'support@pterodactyl.io')->where('name', $nest)->firstOrFail()
|
|
|
|
);
|
|
|
|
}
|
2017-11-04 04:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loop through the list of egg files and import them.
|
|
|
|
*/
|
2022-05-15 18:40:19 +00:00
|
|
|
protected function parseEggFiles(Nest $nest)
|
2017-11-04 04:07:18 +00:00
|
|
|
{
|
2022-05-15 18:40:19 +00:00
|
|
|
$files = new \DirectoryIterator(database_path('Seeders/eggs/' . kebab_case($nest->name)));
|
2017-11-04 04:07:18 +00:00
|
|
|
|
|
|
|
$this->command->alert('Updating Eggs for Nest: ' . $nest->name);
|
2022-05-15 18:40:19 +00:00
|
|
|
/** @var \DirectoryIterator $file */
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if (!$file->isFile() || !$file->isReadable()) {
|
|
|
|
continue;
|
2017-11-04 04:07:18 +00:00
|
|
|
}
|
|
|
|
|
2022-05-15 18:40:19 +00:00
|
|
|
$decoded = json_decode(file_get_contents($file->getRealPath()), true, 512, JSON_THROW_ON_ERROR);
|
2020-06-26 04:16:59 +00:00
|
|
|
$file = new UploadedFile($file->getPathname(), $file->getFilename(), 'application/json');
|
2017-11-04 04:07:18 +00:00
|
|
|
|
2022-05-15 18:40:19 +00:00
|
|
|
$egg = $nest->eggs()
|
|
|
|
->where('author', $decoded['author'])
|
|
|
|
->where('name', $decoded['name'])
|
|
|
|
->first();
|
2017-11-04 04:07:18 +00:00
|
|
|
|
2022-05-15 18:40:19 +00:00
|
|
|
if ($egg instanceof Egg) {
|
2020-10-06 04:29:35 +00:00
|
|
|
$this->updateImporterService->handle($egg, $file);
|
2022-05-15 18:40:19 +00:00
|
|
|
$this->command->info('Updated ' . $decoded['name']);
|
|
|
|
} else {
|
2017-11-04 04:07:18 +00:00
|
|
|
$this->importerService->handle($file, $nest->id);
|
2022-05-15 18:40:19 +00:00
|
|
|
$this->command->comment('Created ' . $decoded['name']);
|
2017-11-04 04:07:18 +00:00
|
|
|
}
|
2022-05-15 18:40:19 +00:00
|
|
|
}
|
2017-11-04 04:07:18 +00:00
|
|
|
|
|
|
|
$this->command->line('');
|
|
|
|
}
|
|
|
|
}
|