mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-30 18:46:51 +01:00 
			
		
		
		
	 da195fd2fe
			
		
	
	
		da195fd2fe
		
			
		
	
	
	
	
		
			
			* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
		
			
				
	
	
		
			62 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Services\Servers;
 | |
| 
 | |
| use Illuminate\Support\Arr;
 | |
| use App\Models\Server;
 | |
| use Illuminate\Database\ConnectionInterface;
 | |
| use App\Traits\Services\ReturnsUpdatedModels;
 | |
| use App\Repositories\Daemon\DaemonServerRepository;
 | |
| use Illuminate\Http\Client\ConnectionException;
 | |
| 
 | |
| class DetailsModificationService
 | |
| {
 | |
|     use ReturnsUpdatedModels;
 | |
| 
 | |
|     /**
 | |
|      * DetailsModificationService constructor.
 | |
|      */
 | |
|     public function __construct(private ConnectionInterface $connection, private DaemonServerRepository $serverRepository) {}
 | |
| 
 | |
|     /**
 | |
|      * Update the details for a single server instance.
 | |
|      *
 | |
|      * @param array{
 | |
|      *     external_id: int,
 | |
|      *     owner_id: int,
 | |
|      *     name: string,
 | |
|      *     description?: ?string
 | |
|      * } $data
 | |
|      *
 | |
|      * @throws \Throwable
 | |
|      */
 | |
|     public function handle(Server $server, array $data): Server
 | |
|     {
 | |
|         return $this->connection->transaction(function () use ($data, $server) {
 | |
|             $owner = $server->owner_id;
 | |
| 
 | |
|             $server->forceFill([
 | |
|                 'external_id' => Arr::get($data, 'external_id'),
 | |
|                 'owner_id' => Arr::get($data, 'owner_id'),
 | |
|                 'name' => Arr::get($data, 'name'),
 | |
|                 'description' => Arr::get($data, 'description') ?? '',
 | |
|             ])->saveOrFail();
 | |
| 
 | |
|             // If the owner_id value is changed we need to revoke any tokens that exist for the server
 | |
|             // on the daemon instance so that the old owner no longer has any permission to access the
 | |
|             // websockets.
 | |
|             if ($server->owner_id !== $owner) {
 | |
|                 try {
 | |
|                     $this->serverRepository->setServer($server)->revokeUserJTI($owner);
 | |
|                 } catch (ConnectionException) {
 | |
|                     // Do nothing. A failure here is not ideal, but it is likely to be caused by daemon
 | |
|                     // being offline, or in an entirely broken state. Remember, these tokens reset every
 | |
|                     // few minutes by default, we're just trying to help it along a little quicker.
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             return $server;
 | |
|         });
 | |
|     }
 | |
| }
 |