mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 13:56:52 +01:00 
			
		
		
		
	 61f3e965ba
			
		
	
	
		61f3e965ba
		
			
		
	
	
	
	
		
			
			* combine importer and updateimport * integrate egg parser into importer * remove EggCreationService and EggUpdateService * run pint * revert change to composer.json * use egg exporter directly instead of old admin route
		
			
				
	
	
		
			84 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace Database\Seeders;
 | |
| 
 | |
| use App\Models\Egg;
 | |
| use Exception;
 | |
| use Illuminate\Database\Seeder;
 | |
| use Illuminate\Http\UploadedFile;
 | |
| use App\Services\Eggs\Sharing\EggImporterService;
 | |
| 
 | |
| class EggSeeder extends Seeder
 | |
| {
 | |
|     protected EggImporterService $importerService;
 | |
| 
 | |
|     /**
 | |
|      * @var string[]
 | |
|      */
 | |
|     public static array $imports = [
 | |
|         'Minecraft',
 | |
|         'Source Engine',
 | |
|         'Voice Servers',
 | |
|         'Rust',
 | |
|     ];
 | |
| 
 | |
|     /**
 | |
|      * EggSeeder constructor.
 | |
|      */
 | |
|     public function __construct(
 | |
|         EggImporterService $importerService
 | |
|     ) {
 | |
|         $this->importerService = $importerService;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Run the egg seeder.
 | |
|      */
 | |
|     public function run()
 | |
|     {
 | |
|         foreach (static::$imports as $import) {
 | |
|             /* @noinspection PhpParamsInspection */
 | |
|             $this->parseEggFiles($import);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Loop through the list of egg files and import them.
 | |
|      */
 | |
|     protected function parseEggFiles($name)
 | |
|     {
 | |
|         $files = new \DirectoryIterator(database_path('Seeders/eggs/' . kebab_case($name)));
 | |
| 
 | |
|         $this->command->alert('Updating Eggs for: ' . $name);
 | |
|         /** @var \DirectoryIterator $file */
 | |
|         foreach ($files as $file) {
 | |
|             if (!$file->isFile() || !$file->isReadable()) {
 | |
|                 continue;
 | |
|             }
 | |
| 
 | |
|             try {
 | |
|                 $decoded = json_decode(file_get_contents($file->getRealPath()), true, 512, JSON_THROW_ON_ERROR);
 | |
|             } catch (Exception) {
 | |
|                 continue;
 | |
|             }
 | |
| 
 | |
|             $file = new UploadedFile($file->getPathname(), $file->getFilename(), 'application/json');
 | |
| 
 | |
|             $egg = Egg::query()
 | |
|                 ->where('author', $decoded['author'])
 | |
|                 ->where('name', $decoded['name'])
 | |
|                 ->first();
 | |
| 
 | |
|             if ($egg instanceof Egg) {
 | |
|                 $this->importerService->fromFile($file, $egg);
 | |
|                 $this->command->info('Updated ' . $decoded['name']);
 | |
|             } else {
 | |
|                 $this->importerService->fromFile($file);
 | |
|                 $this->command->comment('Created ' . $decoded['name']);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         $this->command->line('');
 | |
|     }
 | |
| }
 |