Skip to content

Commit bc3366b

Browse files
committed
Repository interface improvements
1 parent 1f4f602 commit bc3366b

23 files changed

+829
-179
lines changed

app/Contracts/Repository/DatabaseHostInterface.php renamed to app/Contracts/Repository/DatabaseHostRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace Pterodactyl\Contracts\Repository;
2626

27-
interface DatabaseHostInterface extends RepositoryInterface
27+
interface DatabaseHostRepositoryInterface extends RepositoryInterface
2828
{
2929
/**
3030
* Delete a database host from the DB if there are no databases using it.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository;
26+
27+
interface DatabaseRepositoryInterface extends RepositoryInterface
28+
{
29+
/**
30+
* Create a new database if it does not already exist on the host with
31+
* the provided details.
32+
*
33+
* @param array $data
34+
* @return mixed
35+
*
36+
* @throws \Pterodactyl\Exceptions\DisplayException
37+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
38+
*/
39+
public function createIfNotExists(array $data);
40+
41+
/**
42+
* Create a new database on a given connection.
43+
*
44+
* @param string $database
45+
* @param null|string $connection
46+
* @return bool
47+
*/
48+
public function createDatabase($database, $connection = null);
49+
50+
/**
51+
* Create a new database user on a given connection.
52+
*
53+
* @param string $username
54+
* @param string $remote
55+
* @param string $password
56+
* @param null|string $connection
57+
* @return bool
58+
*/
59+
public function createUser($username, $remote, $password, $connection = null);
60+
61+
/**
62+
* Give a specific user access to a given database.
63+
*
64+
* @param string $database
65+
* @param string $username
66+
* @param string $remote
67+
* @param null|string $connection
68+
* @return bool
69+
*/
70+
public function assignUserToDatabase($database, $username, $remote, $connection = null);
71+
72+
/**
73+
* Flush the privileges for a given connection.
74+
*
75+
* @param null|string $connection
76+
* @return mixed
77+
*/
78+
public function flush($connection = null);
79+
80+
/**
81+
* Drop a given database on a specific connection.
82+
*
83+
* @param string $database
84+
* @param null|string $connection
85+
* @return bool
86+
*/
87+
public function dropDatabase($database, $connection = null);
88+
89+
/**
90+
* Drop a given user on a specific connection.
91+
*
92+
* @param string $username
93+
* @param string $remote
94+
* @param null|string $connection
95+
* @return mixed
96+
*/
97+
public function dropUser($username, $remote, $connection = null);
98+
}

app/Contracts/Repository/RepositoryInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,11 @@ public function update($id, array $fields, $validate = true, $force = false);
138138
* @return mixed
139139
*/
140140
public function massUpdate(array $where, array $fields);
141+
142+
/**
143+
* Return all records from the model.
144+
*
145+
* @return mixed
146+
*/
147+
public function all();
141148
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository;
26+
27+
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
28+
29+
interface ServerRepositoryInterface extends RepositoryInterface, SearchableInterface
30+
{
31+
/**
32+
* Returns a listing of all servers that exist including relationships.
33+
*
34+
* @param int $paginate
35+
* @return mixed
36+
*/
37+
public function getAllServers($paginate);
38+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository;
26+
27+
interface ServiceRepositoryInterface extends RepositoryInterface
28+
{
29+
/**
30+
* Return a service or all services with their associated options, variables, and packs.
31+
*
32+
* @param int $id
33+
* @return \Illuminate\Support\Collection
34+
*/
35+
public function getWithOptions($id = null);
36+
}

app/Extensions/DynamicDatabaseConnection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace Pterodactyl\Extensions;
2626

27-
use Pterodactyl\Contracts\Repository\DatabaseHostInterface;
27+
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
2828
use Pterodactyl\Models\DatabaseHost;
2929
use Illuminate\Contracts\Encryption\Encrypter;
3030
use Illuminate\Config\Repository as ConfigRepository;
@@ -46,20 +46,20 @@ class DynamicDatabaseConnection
4646
protected $encrypter;
4747

4848
/**
49-
* @var \Pterodactyl\Contracts\Repository\DatabaseHostInterface
49+
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
5050
*/
5151
protected $repository;
5252

5353
/**
5454
* DynamicDatabaseConnection constructor.
5555
*
56-
* @param \Illuminate\Config\Repository $config
57-
* @param \Pterodactyl\Contracts\Repository\DatabaseHostInterface $repository
58-
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
56+
* @param \Illuminate\Config\Repository $config
57+
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
58+
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
5959
*/
6060
public function __construct(
6161
ConfigRepository $config,
62-
DatabaseHostInterface $repository,
62+
DatabaseHostRepositoryInterface $repository,
6363
Encrypter $encrypter
6464
) {
6565
$this->config = $config;

app/Http/Controllers/Admin/DatabaseController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use Pterodactyl\Models\DatabaseHost;
2929
use Prologue\Alerts\AlertsMessageBag;
3030
use Pterodactyl\Http\Controllers\Controller;
31-
use Pterodactyl\Services\Administrative\DatabaseHostService;
31+
use Pterodactyl\Services\Database\DatabaseHostService;
3232
use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest;
3333

3434
class DatabaseController extends Controller
@@ -49,7 +49,7 @@ class DatabaseController extends Controller
4949
protected $locationModel;
5050

5151
/**
52-
* @var \Pterodactyl\Services\Administrative\DatabaseHostService
52+
* @var \Pterodactyl\Services\Database\DatabaseHostService
5353
*/
5454
protected $service;
5555

@@ -59,7 +59,7 @@ class DatabaseController extends Controller
5959
* @param \Prologue\Alerts\AlertsMessageBag $alert
6060
* @param \Pterodactyl\Models\DatabaseHost $hostModel
6161
* @param \Pterodactyl\Models\Location $locationModel
62-
* @param \Pterodactyl\Services\Administrative\DatabaseHostService $service
62+
* @param \Pterodactyl\Services\Database\DatabaseHostService $service
6363
*/
6464
public function __construct(
6565
AlertsMessageBag $alert,

app/Http/Controllers/Admin/ServersController.php

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424

2525
namespace Pterodactyl\Http\Controllers\Admin;
2626

27+
use Illuminate\Contracts\Config\Repository as ConfigRepository;
2728
use Log;
2829
use Alert;
2930
use Javascript;
31+
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
32+
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
33+
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
34+
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
3035
use Pterodactyl\Models;
3136
use Illuminate\Http\Request;
3237
use GuzzleHttp\Exception\TransferException;
@@ -39,34 +44,70 @@
3944

4045
class ServersController extends Controller
4146
{
47+
/**
48+
* @var \Illuminate\Contracts\Config\Repository
49+
*/
50+
protected $config;
51+
52+
/**
53+
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
54+
*/
55+
protected $databaseRepository;
56+
57+
/**
58+
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
59+
*/
60+
protected $locationRepository;
61+
62+
/**
63+
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
64+
*/
65+
protected $repository;
66+
67+
/**
68+
* @var \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface
69+
*/
70+
protected $serviceRepository;
71+
72+
public function __construct(
73+
ConfigRepository $config,
74+
DatabaseRepositoryInterface $databaseRepository,
75+
LocationRepositoryInterface $locationRepository,
76+
ServerRepositoryInterface $repository,
77+
ServiceRepositoryInterface $serviceRepository
78+
) {
79+
$this->config = $config;
80+
$this->databaseRepository = $databaseRepository;
81+
$this->locationRepository = $locationRepository;
82+
$this->repository = $repository;
83+
$this->serviceRepository = $serviceRepository;
84+
}
85+
4286
/**
4387
* Display the index page with all servers currently on the system.
4488
*
45-
* @param \Illuminate\Http\Request $request
4689
* @return \Illuminate\View\View
4790
*/
48-
public function index(Request $request)
91+
public function index()
4992
{
50-
$servers = Models\Server::with('node', 'user', 'allocation');
51-
52-
if (! is_null($request->input('query'))) {
53-
$servers->search($request->input('query'));
54-
}
55-
5693
return view('admin.servers.index', [
57-
'servers' => $servers->paginate(25),
94+
'servers' => $this->repository->getAllServers(
95+
$this->config->get('pterodactyl.paginate.admin.servers')
96+
),
5897
]);
5998
}
6099

61100
/**
62101
* Display create new server page.
63102
*
64-
* @param \Illuminate\Http\Request $request
65103
* @return \Illuminate\View\View
104+
*
105+
* @throws \Exception
66106
*/
67-
public function create(Request $request)
107+
public function create()
68108
{
69-
$services = Models\Service::with('options.packs', 'options.variables')->get();
109+
$services = $this->serviceRepository->getWithOptions();
110+
70111
Javascript::put([
71112
'services' => $services->map(function ($item) {
72113
return array_merge($item->toArray(), [
@@ -76,7 +117,7 @@ public function create(Request $request)
76117
]);
77118

78119
return view('admin.servers.new', [
79-
'locations' => Models\Location::all(),
120+
'locations' => $this->locationRepository->all(),
80121
'services' => $services,
81122
]);
82123
}
@@ -115,7 +156,7 @@ public function store(Request $request)
115156
* Returns a tree of all avaliable nodes in a given location.
116157
*
117158
* @param \Illuminate\Http\Request $request
118-
* @return array
159+
* @return \Illuminate\Support\Collection
119160
*/
120161
public function nodes(Request $request)
121162
{

0 commit comments

Comments
 (0)