@@ -63,6 +63,11 @@ class ServersController extends Controller
6363 */
6464 protected $ databaseRepository ;
6565
66+ /**
67+ * @var \Pterodactyl\Services\Database\CreationService
68+ */
69+ protected $ databaseCreationService ;
70+
6671 /**
6772 * @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
6873 */
@@ -97,6 +102,7 @@ public function __construct(
97102 AllocationRepositoryInterface $ allocationRepository ,
98103 ConfigRepository $ config ,
99104 CreationService $ service ,
105+ \Pterodactyl \Services \Database \CreationService $ databaseCreationService ,
100106 DatabaseRepositoryInterface $ databaseRepository ,
101107 DatabaseHostRepository $ databaseHostRepository ,
102108 LocationRepositoryInterface $ locationRepository ,
@@ -106,6 +112,7 @@ public function __construct(
106112 ) {
107113 $ this ->allocationRepository = $ allocationRepository ;
108114 $ this ->config = $ config ;
115+ $ this ->databaseCreationService = $ databaseCreationService ;
109116 $ this ->databaseRepository = $ databaseRepository ;
110117 $ this ->databaseHostRepository = $ databaseHostRepository ;
111118 $ this ->locationRepository = $ locationRepository ;
@@ -583,20 +590,25 @@ public function saveStartup(Request $request, $id)
583590 */
584591 public function newDatabase (Request $ request , $ id )
585592 {
586- $ repo = new DatabaseRepository ;
587-
588- try {
589- $ repo ->create ($ id , $ request ->only (['host ' , 'database ' , 'connection ' ]));
590-
591- Alert::success ('A new database was assigned to this server successfully. ' )->flash ();
592- } catch (DisplayValidationException $ ex ) {
593- return redirect ()->route ('admin.servers.view.database ' , $ id )->withInput ()->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
594- } catch (DisplayException $ ex ) {
595- Alert::danger ($ ex ->getMessage ())->flash ();
596- } catch (\Exception $ ex ) {
597- Log::error ($ ex );
598- Alert::danger ('An exception occured while attempting to add a new database for this server. This error has been logged. ' )->flash ();
599- }
593+ $ this ->databaseCreationService ->create ($ id , [
594+ 'database ' => $ request ->input ('database ' ),
595+ 'remote ' => $ request ->input ('remote ' ),
596+ 'database_host_id ' => $ request ->input ('database_host_id ' ),
597+ ]);
598+ // $repo = new DatabaseRepository;
599+ //
600+ // try {
601+ // $repo->create($id, $request->only(['host', 'database', 'connection']));
602+ //
603+ // Alert::success('A new database was assigned to this server successfully.')->flash();
604+ // } catch (DisplayValidationException $ex) {
605+ // return redirect()->route('admin.servers.view.database', $id)->withInput()->withErrors(json_decode($ex->getMessage()))->withInput();
606+ // } catch (DisplayException $ex) {
607+ // Alert::danger($ex->getMessage())->flash();
608+ // } catch (\Exception $ex) {
609+ // Log::error($ex);
610+ // Alert::danger('An exception occured while attempting to add a new database for this server. This error has been logged.')->flash();
611+ // }
600612
601613 return redirect ()->route ('admin.servers.view.database ' , $ id )->withInput ();
602614 }
0 commit comments