2626
2727use Illuminate \Database \DatabaseManager ;
2828use Illuminate \Contracts \Encryption \Encrypter ;
29+ use Pterodactyl \Contracts \Repository \DatabaseRepositoryInterface ;
30+ use Pterodactyl \Exceptions \DisplayException ;
2931use Pterodactyl \Extensions \DynamicDatabaseConnection ;
3032use Pterodactyl \Contracts \Repository \DatabaseHostRepositoryInterface ;
3133
@@ -36,6 +38,11 @@ class DatabaseHostService
3638 */
3739 protected $ database ;
3840
41+ /**
42+ * @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
43+ */
44+ protected $ databaseRepository ;
45+
3946 /**
4047 * @var \Pterodactyl\Extensions\DynamicDatabaseConnection
4148 */
@@ -55,17 +62,20 @@ class DatabaseHostService
5562 * DatabaseHostService constructor.
5663 *
5764 * @param \Illuminate\Database\DatabaseManager $database
65+ * @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
5866 * @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
5967 * @param \Pterodactyl\Extensions\DynamicDatabaseConnection $dynamic
6068 * @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
6169 */
6270 public function __construct (
6371 DatabaseManager $ database ,
72+ DatabaseRepositoryInterface $ databaseRepository ,
6473 DatabaseHostRepositoryInterface $ repository ,
6574 DynamicDatabaseConnection $ dynamic ,
6675 Encrypter $ encrypter
6776 ) {
6877 $ this ->database = $ database ;
78+ $ this ->databaseRepository = $ databaseRepository ;
6979 $ this ->dynamic = $ dynamic ;
7080 $ this ->encrypter = $ encrypter ;
7181 $ this ->repository = $ repository ;
@@ -111,6 +121,7 @@ public function create(array $data)
111121 * @return mixed
112122 *
113123 * @throws \Pterodactyl\Exceptions\Model\DataValidationException
124+ * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
114125 */
115126 public function update ($ id , array $ data )
116127 {
@@ -142,6 +153,11 @@ public function update($id, array $data)
142153 */
143154 public function delete ($ id )
144155 {
145- return $ this ->repository ->deleteIfNoDatabases ($ id );
156+ $ count = $ this ->databaseRepository ->findCountWhere ([['database_host_id ' , '= ' , $ id ]]);
157+ if ($ count > 0 ) {
158+ throw new DisplayException (trans ('admin/exceptions.databases.delete_has_databases ' ));
159+ }
160+
161+ return $ this ->repository ->delete ($ id );
146162 }
147163}
0 commit comments