mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-27 16:26:51 +01:00 
			
		
		
		
	 d09227659e
			
		
	
	
		d09227659e
		
			
		
	
	
	
	
		
			
			* add database notifications to all panels * add successful param to Installed event * add listener for Installed event * create event for subuser creation * add listener for SubUserAdded event * always send Installed event * create event for subuser removal * add listener for SubUserRemoved event * add prefix to server name * remove view action from SubUserRemoved notification
		
			
				
	
	
		
			62 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Controllers\Api\Remote\Servers;
 | |
| 
 | |
| use App\Enums\ServerState;
 | |
| use Illuminate\Http\Response;
 | |
| use App\Models\Server;
 | |
| use Illuminate\Http\JsonResponse;
 | |
| use App\Http\Controllers\Controller;
 | |
| use App\Events\Server\Installed as ServerInstalled;
 | |
| use App\Http\Requests\Api\Remote\InstallationDataRequest;
 | |
| 
 | |
| class ServerInstallController extends Controller
 | |
| {
 | |
|     /**
 | |
|      * Returns installation information for a server.
 | |
|      */
 | |
|     public function index(Server $server): JsonResponse
 | |
|     {
 | |
|         $egg = $server->egg;
 | |
| 
 | |
|         return new JsonResponse([
 | |
|             'container_image' => $egg->copy_script_container,
 | |
|             'entrypoint' => $egg->copy_script_entry,
 | |
|             'script' => $egg->copy_script_install,
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Updates the installation state of a server.
 | |
|      *
 | |
|      * @throws \App\Exceptions\Model\DataValidationException
 | |
|      */
 | |
|     public function store(InstallationDataRequest $request, Server $server): JsonResponse
 | |
|     {
 | |
|         $status = null;
 | |
| 
 | |
|         $successful = $request->boolean('successful');
 | |
| 
 | |
|         // Make sure the type of failure is accurate
 | |
|         if (!$successful) {
 | |
|             $status = $request->boolean('reinstall') ? ServerState::ReinstallFailed : ServerState::InstallFailed;
 | |
|         }
 | |
| 
 | |
|         // Keep the server suspended if it's already suspended
 | |
|         if ($server->status === ServerState::Suspended) {
 | |
|             $status = ServerState::Suspended;
 | |
|         }
 | |
| 
 | |
|         $previouslyInstalledAt = $server->installed_at;
 | |
| 
 | |
|         $server->status = $status;
 | |
|         $server->installed_at = now();
 | |
|         $server->save();
 | |
| 
 | |
|         $isInitialInstall = is_null($previouslyInstalledAt);
 | |
|         event(new ServerInstalled($server, $successful, $isInitialInstall));
 | |
| 
 | |
|         return new JsonResponse([], Response::HTTP_NO_CONTENT);
 | |
|     }
 | |
| }
 |