@@ -33,6 +33,8 @@ class BuildModificationService
3333 * BuildModificationService constructor.
3434 *
3535 * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
36+ * @param \Illuminate\Database\ConnectionInterface $connection
37+ * @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
3638 */
3739 public function __construct (
3840 ServerConfigurationStructureService $ structureService ,
@@ -56,34 +58,37 @@ public function handle(Server $server, array $data)
5658 {
5759 $ this ->connection ->beginTransaction ();
5860
59- $ this ->processAllocations ($ server , $ data );
61+ /** @var \Pterodactyl\Models\Server $server */
62+ $ server = $ this ->connection ->transaction (function () use ($ server , $ data ) {
63+ $ this ->processAllocations ($ server , $ data );
6064
61- if (isset ($ data ['allocation_id ' ]) && $ data ['allocation_id ' ] != $ server ->allocation_id ) {
62- try {
63- Allocation::query ()->where ('id ' , $ data ['allocation_id ' ])->where ('server_id ' , $ server ->id )->firstOrFail ();
64- } catch (ModelNotFoundException $ ex ) {
65- throw new DisplayException ('The requested default allocation is not currently assigned to this server. ' );
65+ if (isset ($ data ['allocation_id ' ]) && $ data ['allocation_id ' ] != $ server ->allocation_id ) {
66+ try {
67+ Allocation::query ()->where ('id ' , $ data ['allocation_id ' ])->where ('server_id ' , $ server ->id )->firstOrFail ();
68+ } catch (ModelNotFoundException $ ex ) {
69+ throw new DisplayException ('The requested default allocation is not currently assigned to this server. ' );
70+ }
6671 }
67- }
6872
69- // If any of these values are passed through in the data array go ahead and set
70- // them correctly on the server model.
71- $ merge = Arr::only ($ data , ['oom_disabled ' , 'memory ' , 'swap ' , 'io ' , 'cpu ' , 'threads ' , 'disk ' , 'allocation_id ' ]);
73+ // If any of these values are passed through in the data array go ahead and set
74+ // them correctly on the server model.
75+ $ merge = Arr::only ($ data , ['oom_disabled ' , 'memory ' , 'swap ' , 'io ' , 'cpu ' , 'threads ' , 'disk ' , 'allocation_id ' ]);
7276
73- $ server ->forceFill (array_merge ($ merge , [
74- 'database_limit ' => Arr::get ($ data , 'database_limit ' , 0 ) ?? null ,
75- 'allocation_limit ' => Arr::get ($ data , 'allocation_limit ' , 0 ) ?? null ,
76- 'backup_limit ' => Arr::get ($ data , 'backup_limit ' , 0 ) ?? 0 ,
77- ]))->saveOrFail ();
77+ $ server ->forceFill (array_merge ($ merge , [
78+ 'database_limit ' => Arr::get ($ data , 'database_limit ' , 0 ) ?? null ,
79+ 'allocation_limit ' => Arr::get ($ data , 'allocation_limit ' , 0 ) ?? null ,
80+ 'backup_limit ' => Arr::get ($ data , 'backup_limit ' , 0 ) ?? 0 ,
81+ ]))->saveOrFail ();
7882
79- $ server = $ server ->fresh ();
83+ return $ server ->refresh ();
84+ });
8085
8186 $ updateData = $ this ->structureService ->handle ($ server );
8287
8388 // Because Wings always fetches an updated configuration from the Panel when booting
8489 // a server this type of exception can be safely "ignored" and just written to the logs.
85- // Ideally this request succeedes so we can apply resource modifications on the fly
86- // but if it fails it isn't the end of the world .
90+ // Ideally this request succeedes so we can apply resource modifications on the fly, but
91+ // if it fails we can just continue on as normal .
8792 if (!empty ($ updateData ['build ' ])) {
8893 try {
8994 $ this ->daemonServerRepository ->setServer ($ server )->update ([
@@ -94,8 +99,6 @@ public function handle(Server $server, array $data)
9499 }
95100 }
96101
97- $ this ->connection ->commit ();
98-
99102 return $ server ;
100103 }
101104
0 commit comments