1010namespace Pterodactyl \Services \Servers ;
1111
1212use Ramsey \Uuid \Uuid ;
13- use Illuminate \Log \Writer ;
14- use Illuminate \Database \DatabaseManager ;
1513use GuzzleHttp \Exception \RequestException ;
16- use Pterodactyl \ Exceptions \ DisplayException ;
14+ use Illuminate \ Database \ ConnectionInterface ;
1715use Pterodactyl \Services \Nodes \NodeCreationService ;
1816use Pterodactyl \Contracts \Repository \NodeRepositoryInterface ;
1917use Pterodactyl \Contracts \Repository \UserRepositoryInterface ;
2018use Pterodactyl \Contracts \Repository \ServerRepositoryInterface ;
2119use Pterodactyl \Contracts \Repository \AllocationRepositoryInterface ;
20+ use Pterodactyl \Exceptions \Http \Connection \DaemonConnectionException ;
2221use Pterodactyl \Contracts \Repository \ServerVariableRepositoryInterface ;
2322use Pterodactyl \Contracts \Repository \Daemon \ServerRepositoryInterface as DaemonServerRepositoryInterface ;
2423
@@ -35,14 +34,14 @@ class ServerCreationService
3534 protected $ configurationStructureService ;
3635
3736 /**
38- * @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
37+ * @var \Illuminate\Database\ConnectionInterface
3938 */
40- protected $ daemonServerRepository ;
39+ protected $ connection ;
4140
4241 /**
43- * @var \Illuminate\Database\DatabaseManager
42+ * @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
4443 */
45- protected $ database ;
44+ protected $ daemonServerRepository ;
4645
4746 /**
4847 * @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
@@ -74,50 +73,42 @@ class ServerCreationService
7473 */
7574 protected $ validatorService ;
7675
77- /**
78- * @var \Illuminate\Log\Writer
79- */
80- protected $ writer ;
81-
8276 /**
8377 * CreationService constructor.
8478 *
8579 * @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
80+ * @param \Illuminate\Database\ConnectionInterface $connection
8681 * @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
87- * @param \Illuminate\Database\DatabaseManager $database
8882 * @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $nodeRepository
8983 * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
9084 * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
9185 * @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository
9286 * @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $userRepository
9387 * @param \Pterodactyl\Services\Servers\UsernameGenerationService $usernameService
9488 * @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
95- * @param \Illuminate\Log\Writer $writer
9689 */
9790 public function __construct (
9891 AllocationRepositoryInterface $ allocationRepository ,
92+ ConnectionInterface $ connection ,
9993 DaemonServerRepositoryInterface $ daemonServerRepository ,
100- DatabaseManager $ database ,
10194 NodeRepositoryInterface $ nodeRepository ,
10295 ServerConfigurationStructureService $ configurationStructureService ,
10396 ServerRepositoryInterface $ repository ,
10497 ServerVariableRepositoryInterface $ serverVariableRepository ,
10598 UserRepositoryInterface $ userRepository ,
10699 UsernameGenerationService $ usernameService ,
107- VariableValidatorService $ validatorService ,
108- Writer $ writer
100+ VariableValidatorService $ validatorService
109101 ) {
110102 $ this ->allocationRepository = $ allocationRepository ;
111- $ this ->daemonServerRepository = $ daemonServerRepository ;
112103 $ this ->configurationStructureService = $ configurationStructureService ;
113- $ this ->database = $ database ;
104+ $ this ->connection = $ connection ;
105+ $ this ->daemonServerRepository = $ daemonServerRepository ;
114106 $ this ->nodeRepository = $ nodeRepository ;
115107 $ this ->repository = $ repository ;
116108 $ this ->serverVariableRepository = $ serverVariableRepository ;
117109 $ this ->userRepository = $ userRepository ;
118110 $ this ->usernameService = $ usernameService ;
119111 $ this ->validatorService = $ validatorService ;
120- $ this ->writer = $ writer ;
121112 }
122113
123114 /**
@@ -136,7 +127,7 @@ public function create(array $data)
136127 $ validator = $ this ->validatorService ->isAdmin ()->setFields ($ data ['environment ' ])->validate ($ data ['option_id ' ]);
137128 $ uniqueShort = str_random (8 );
138129
139- $ this ->database ->beginTransaction ();
130+ $ this ->connection ->beginTransaction ();
140131
141132 $ server = $ this ->repository ->create ([
142133 'uuid ' => Uuid::uuid4 ()->toString (),
@@ -187,16 +178,13 @@ public function create(array $data)
187178
188179 // Create the server on the daemon & commit it to the database.
189180 try {
190- $ this ->daemonServerRepository ->setNode ($ server ->node_id )->create ($ structure , ['start_on_completion ' => (bool ) $ data ['start_on_completion ' ]]);
191- $ this ->database ->commit ();
181+ $ this ->daemonServerRepository ->setNode ($ server ->node_id )->create ($ structure , [
182+ 'start_on_completion ' => (bool ) array_get ($ data , 'start_on_completion ' , false ),
183+ ]);
184+ $ this ->connection ->commit ();
192185 } catch (RequestException $ exception ) {
193- $ response = $ exception ->getResponse ();
194- $ this ->writer ->warning ($ exception );
195- $ this ->database ->rollBack ();
196-
197- throw new DisplayException (trans ('admin/server.exceptions.daemon_exception ' , [
198- 'code ' => is_null ($ response ) ? 'E_CONN_REFUSED ' : $ response ->getStatusCode (),
199- ]));
186+ $ this ->connection ->rollBack ();
187+ throw new DaemonConnectionException ($ exception );
200188 }
201189
202190 return $ server ;
0 commit comments