Fix allocation selection

This commit is contained in:
Dane Everitt 2016-01-22 21:43:56 -05:00
parent ae843a72c6
commit be48fbd418
2 changed files with 19 additions and 15 deletions

View file

@ -211,24 +211,24 @@ class AjaxController extends Controller
}
try {
$repo = new Repositories\ServerRepository;
$repo->changeBuild($server->id, [
'default' => $request->input('connection'),
]);
return response('The default connection for this server has been updated. Please be aware that you will need to restart your server for this change to go into effect.');
} catch (\Exception $e) {
if ($e instanceof \Pterodactyl\Exceptions\DisplayException || $e instanceof \Pterodactyl\Exceptions\DisplayValidationException) {
return response()->json([
'error' => $e->getMessage(),
], 503);
} else {
Log::error($e);
return response()->json([
'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.'
], 503);
}
} catch (\Pterodactyl\Exceptions\DisplayValidationException $ex) {
return response()->json([
'error' => json_decode($ex->getMessage(), true),
], 503);
} catch (\Pterodactyl\Exceptions\DisplayException $ex) {
return response()->json([
'error' => $ex->getMessage(),
], 503);
} catch (\Exception $ex) {
Log::error($ex);
return response()->json([
'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.'
], 503);
}
}

View file

@ -416,9 +416,9 @@ class ServerRepository
if (isset($data['default'])) {
list($ip, $port) = explode(':', $data['default']);
if ($ip !== $server->ip || $port !== $server->port) {
$allocation = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->get();
$allocation = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->first();
if (!$allocation) {
throw new DisplayException('The assigned default connection (' . $ip . ':' . $port . ') is not allocated to this server.');
throw new DisplayException('The requested default connection (' . $ip . ':' . $port . ') is not allocated to this server.');
}
$server->ip = $ip;
@ -532,6 +532,10 @@ class ServerRepository
} catch (\GuzzleHttp\Exception\TransferException $ex) {
DB::rollBack();
throw new DisplayException('An error occured while attempting to update the configuration: ' . $ex->getMessage());
} catch (\Exception $ex) {
DB::rollBack();
Log::error($ex);
throw $ex;
}
}