mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-15 21:03:45 +02:00
Fix all transaction try/catches, closes #57
This commit is contained in:
@@ -151,51 +151,52 @@ class NodeRepository {
|
||||
$node = Models\Node::findOrFail($id);
|
||||
|
||||
DB::beginTransaction();
|
||||
foreach($allocations as $rawIP => $ports) {
|
||||
$parsedIP = Network::parse($rawIP);
|
||||
foreach($parsedIP as $ip) {
|
||||
foreach($ports as $port) {
|
||||
if (!is_int($port) && !preg_match('/^(\d{1,5})-(\d{1,5})$/', $port)) {
|
||||
throw new DisplayException('The mapping for ' . $port . ' is invalid and cannot be processed.');
|
||||
}
|
||||
if (preg_match('/^(\d{1,5})-(\d{1,5})$/', $port, $matches)) {
|
||||
foreach(range($matches[1], $matches[2]) as $assignPort) {
|
||||
|
||||
try {
|
||||
foreach($allocations as $rawIP => $ports) {
|
||||
$parsedIP = Network::parse($rawIP);
|
||||
foreach($parsedIP as $ip) {
|
||||
foreach($ports as $port) {
|
||||
if (!is_int($port) && !preg_match('/^(\d{1,5})-(\d{1,5})$/', $port)) {
|
||||
throw new DisplayException('The mapping for ' . $port . ' is invalid and cannot be processed.');
|
||||
}
|
||||
if (preg_match('/^(\d{1,5})-(\d{1,5})$/', $port, $matches)) {
|
||||
foreach(range($matches[1], $matches[2]) as $assignPort) {
|
||||
$alloc = Models\Allocation::firstOrNew([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $assignPort
|
||||
]);
|
||||
if (!$alloc->exists) {
|
||||
$alloc->fill([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $assignPort,
|
||||
'assigned_to' => null
|
||||
]);
|
||||
$alloc->save();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$alloc = Models\Allocation::firstOrNew([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $assignPort
|
||||
'port' => $port
|
||||
]);
|
||||
if (!$alloc->exists) {
|
||||
$alloc->fill([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $assignPort,
|
||||
'port' => $port,
|
||||
'assigned_to' => null
|
||||
]);
|
||||
$alloc->save();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$alloc = Models\Allocation::firstOrNew([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $port
|
||||
]);
|
||||
if (!$alloc->exists) {
|
||||
$alloc->fill([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $port,
|
||||
'assigned_to' => null
|
||||
]);
|
||||
$alloc->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::commit();
|
||||
return true;
|
||||
} catch (\Exception $ex) {
|
||||
|
||||
Reference in New Issue
Block a user