Skip to content

Commit 2e134b7

Browse files
committed
Set out some roach traps to catch all these 🐛
1 parent 3362348 commit 2e134b7

File tree

8 files changed

+24
-25
lines changed

8 files changed

+24
-25
lines changed

app/Http/Controllers/API/NodeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function allocations(Request $request)
187187
*/
188188
public function allocationsView(Request $request, $id)
189189
{
190-
return Models\Allocation::where('assigned_to', $id)->get()->toArray();
190+
return Models\Allocation::where('server_id', $id)->get()->toArray();
191191
}
192192

193193
/**

app/Http/Controllers/Admin/NodesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function postView(Request $request, $id)
159159

160160
public function deallocateSingle(Request $request, $node, $allocation)
161161
{
162-
$query = Models\Allocation::where('node', $node)->whereNull('assigned_to')->where('id', $allocation)->delete();
162+
$query = Models\Allocation::where('node', $node)->whereNull('server_id')->where('id', $allocation)->delete();
163163
if ((int) $query === 0) {
164164
return response()->json([
165165
'error' => 'Unable to find an allocation matching those details to delete.',
@@ -171,7 +171,7 @@ public function deallocateSingle(Request $request, $node, $allocation)
171171

172172
public function deallocateBlock(Request $request, $node)
173173
{
174-
$query = Models\Allocation::where('node', $node)->whereNull('assigned_to')->where('ip', $request->input('ip'))->delete();
174+
$query = Models\Allocation::where('node', $node)->whereNull('server_id')->where('ip', $request->input('ip'))->delete();
175175
if ((int) $query === 0) {
176176
Alert::danger('There was an error while attempting to delete allocations on that IP.')->flash();
177177

app/Http/Controllers/Admin/ServersController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function postNewServerGetNodes(Request $request)
115115
], 500);
116116
}
117117

118-
return response()->json(Models\Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get());
118+
return response()->json(Models\Node::select('id', 'name', 'public')->where('location_id', $request->input('location'))->get());
119119
}
120120

121121
/**
@@ -132,7 +132,7 @@ public function postNewServerGetIps(Request $request)
132132
], 500);
133133
}
134134

135-
$ips = Models\Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get();
135+
$ips = Models\Allocation::where('node_id', $request->input('node'))->whereNull('server_id')->get();
136136
$listing = [];
137137

138138
foreach ($ips as &$ip) {

app/Http/Controllers/Server/AjaxController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function postSetPrimary(Request $request, $uuid)
181181
}
182182

183183
try {
184-
$allocation = $server->allocations->where('id', $request->input('allocation'))->where('assigned_to', $server->id)->first();
184+
$allocation = $server->allocations->where('id', $request->input('allocation'))->where('server_id', $server->id)->first();
185185
if (! $allocation) {
186186
return response()->json([
187187
'error' => 'No allocation matching your request was found in the system.',

app/Observers/ServerObserver.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ServerObserver
3737
use DispatchesJobs;
3838

3939
/**
40-
* Listen to the Server deleted event.
40+
* Listen to the Server creating event.
4141
*
4242
* @param Server $server [description]
4343
* @return [type] [description]
@@ -48,7 +48,7 @@ public function creating(Server $server)
4848
}
4949

5050
/**
51-
* Listen to the Server deleted event.
51+
* Listen to the Server created event.
5252
*
5353
* @param Server $server [description]
5454
* @return [type] [description]
@@ -58,20 +58,18 @@ public function created(Server $server)
5858
event(new Events\Server\Created($server));
5959

6060
// Queue Notification Email
61-
$server->load('user', 'node', 'service.option');
62-
6361
$server->user->notify((new ServerCreated([
6462
'name' => $server->name,
6563
'memory' => $server->memory,
6664
'node' => $server->node->name,
6765
'service' => $server->service->name,
68-
'option' => $server->service->option->name,
66+
'option' => $server->option->name,
6967
'uuidShort' => $server->uuidShort,
7068
])));
7169
}
7270

7371
/**
74-
* Listen to the Server deleted event.
72+
* Listen to the Server deleting event.
7573
*
7674
* @param Server $server [description]
7775
* @return [type] [description]

app/Repositories/NodeRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function addAllocations($id, array $allocations)
220220
'ip' => $ip,
221221
'port' => $assignPort,
222222
'ip_alias' => $setAlias,
223-
'assigned_to' => null,
223+
'server_id' => null,
224224
]);
225225
$alloc->save();
226226
}
@@ -237,7 +237,7 @@ public function addAllocations($id, array $allocations)
237237
'ip' => $ip,
238238
'port' => $port,
239239
'ip_alias' => $setAlias,
240-
'assigned_to' => null,
240+
'server_id' => null,
241241
]);
242242
$alloc->save();
243243
}

app/Repositories/ServerRepository.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@ public function create(array $data)
144144
// We know the node exists because of 'exists:nodes,id' in the validation
145145
if (! $autoDeployed) {
146146
if (! isset($data['allocation_id'])) {
147-
$allocation = Models\Allocation::where('ip', $data['ip'])->where('port', $data['port'])->where('node', $data['node'])->whereNull('assigned_to')->first();
147+
$model = Models\Allocation::where('ip', $data['ip'])->where('port', $data['port']);
148148
} else {
149-
$allocation = Models\Allocation::where('id', $data['allocation'])->where('node', $data['node'])->whereNull('assigned_to')->first();
149+
$model = Models\Allocation::where('id', $data['allocation_id']);
150150
}
151+
$allocation = $model->where('node_id', $data['node_id'])->whereNull('server_id')->first();
151152
}
152153

153154
// Something failed in the query, either that combo doesn't exist, or it is in use.
@@ -159,7 +160,7 @@ public function create(array $data)
159160
// We know the service and option exists because of the validation.
160161
// We need to verify that the option exists for the service, and then check for
161162
// any required variable fields. (fields are labeled env_<env_variable>)
162-
$option = Models\ServiceOption::where('id', $data['option'])->where('service_id', $data['service'])->first();
163+
$option = Models\ServiceOption::where('id', $data['option_id'])->where('service_id', $data['service_id'])->first();
163164
if (! $option) {
164165
throw new DisplayException('The requested service option does not exist for the specified service.');
165166
}
@@ -170,7 +171,7 @@ public function create(array $data)
170171
}
171172

172173
if (! is_null($data['pack_id'])) {
173-
$pack = Models\ServicePack::where('id', $data['pack_id'])->where('option', $data['option_id'])->first();
174+
$pack = Models\ServicePack::where('id', $data['pack_id'])->where('option_id', $data['option_id'])->first();
174175
if (! $pack) {
175176
throw new DisplayException('The requested service pack does not seem to exist for this combination.');
176177
}
@@ -264,7 +265,7 @@ public function create(array $data)
264265
'io' => $data['io'],
265266
'cpu' => $data['cpu'],
266267
'oom_disabled' => (isset($data['oom_disabled'])) ? true : false,
267-
'allocation' => $allocation->id,
268+
'allocation_id' => $allocation->id,
268269
'service_id' => $data['service_id'],
269270
'option_id' => $data['option_id'],
270271
'pack_id' => $data['pack_id'],
@@ -540,7 +541,7 @@ public function changeBuild($id, array $data)
540541

541542
$newPorts = true;
542543
$server->allocations->where('ip', $ip)->where('port', $port)->update([
543-
'assigned_to' => null,
544+
'server_id' => null,
544545
]);
545546
}
546547

@@ -562,8 +563,8 @@ public function changeBuild($id, array $data)
562563
}
563564

564565
$newPorts = true;
565-
Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('assigned_to')->update([
566-
'assigned_to' => $server->id,
566+
Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('server_id')->update([
567+
'server_id' => $server->id,
567568
]);
568569
}
569570

app/Services/DeploymentService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function randomNode($location, array $not = [])
6565
throw new DisplayException('The location passed was not valid and could not be found.');
6666
}
6767

68-
$node = Models\Node::where('location', $useLocation->id)->where('public', 1)->whereNotIn('id', $not)->inRandomOrder()->first();
68+
$node = Models\Node::where('location_id', $useLocation->id)->where('public', 1)->whereNotIn('id', $not)->inRandomOrder()->first();
6969
if (! $node) {
7070
throw new DisplayException("Unable to find a node in location {$useLocation->short} (id: {$useLocation->id}) that is available and has space.");
7171
}
@@ -107,7 +107,7 @@ public static function smartRandomNode($memory, $disk, $location = null)
107107
*/
108108
public static function randomAllocation($node)
109109
{
110-
$allocation = Models\Allocation::where('node', $node)->whereNull('assigned_to')->inRandomOrder()->first();
110+
$allocation = Models\Allocation::where('node_id', $node)->whereNull('server_id')->inRandomOrder()->first();
111111
if (! $allocation) {
112112
throw new DisplayException('No available allocation could be found for the assigned node.');
113113
}
@@ -125,7 +125,7 @@ public static function randomAllocation($node)
125125
protected static function checkNodeAllocation(Models\Node $node, $memory, $disk)
126126
{
127127
if (is_numeric($node->memory_overallocate) || is_numeric($node->disk_overallocate)) {
128-
$totals = Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first();
128+
$totals = Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node_id', $node->id)->first();
129129

130130
// Check memory limits
131131
if (is_numeric($node->memory_overallocate)) {

0 commit comments

Comments
 (0)