Cleaned up IPs & Label assignments
Cleaned up IPs & Label assignments when creating, updating and deleting
This commit is contained in:
parent
ff3d840b65
commit
ecc9a61069
|
@ -59,17 +59,6 @@ class DomainsController extends Controller
|
|||
|
||||
$domain_id = Str::random(8);
|
||||
|
||||
Domains::create([
|
||||
'id' => $domain_id,
|
||||
'domain' => $request->domain,
|
||||
'extension' => $request->extension,
|
||||
'ns1' => $request->ns1,
|
||||
'ns2' => $request->ns2,
|
||||
'ns3' => $request->ns3,
|
||||
'provider_id' => $request->provider_id,
|
||||
'owned_since' => $request->owned_since
|
||||
]);
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
@ -85,13 +74,18 @@ class DomainsController extends Controller
|
|||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
$labels_array = [$request->label1, $request->label2, $request->label3, $request->label4];
|
||||
Domains::create([
|
||||
'id' => $domain_id,
|
||||
'domain' => $request->domain,
|
||||
'extension' => $request->extension,
|
||||
'ns1' => $request->ns1,
|
||||
'ns2' => $request->ns2,
|
||||
'ns3' => $request->ns3,
|
||||
'provider_id' => $request->provider_id,
|
||||
'owned_since' => $request->owned_since
|
||||
]);
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned (label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $domain_id]);
|
||||
}
|
||||
}
|
||||
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $domain_id);
|
||||
|
||||
Cache::forget('services_count');//Main page services_count cache
|
||||
Cache::forget('due_soon');//Main page due_soon cache
|
||||
|
@ -125,17 +119,6 @@ class DomainsController extends Controller
|
|||
'price' => 'numeric'
|
||||
]);
|
||||
|
||||
$domain->update([
|
||||
'domain' => $request->domain,
|
||||
'extension' => $request->extension,
|
||||
'ns1' => $request->ns1,
|
||||
'ns2' => $request->ns2,
|
||||
'ns3' => $request->ns3,
|
||||
'provider_id' => $request->provider_id,
|
||||
'owned_since' => $request->owned_since,
|
||||
'active' => (isset($request->is_active)) ? 1 : 0
|
||||
]);
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
@ -153,15 +136,20 @@ class DomainsController extends Controller
|
|||
'active' => (isset($request->is_active)) ? 1 : 0
|
||||
]);
|
||||
|
||||
$deleted = DB::table('labels_assigned')->where('service_id', '=', $domain->id)->delete();
|
||||
$domain->update([
|
||||
'domain' => $request->domain,
|
||||
'extension' => $request->extension,
|
||||
'ns1' => $request->ns1,
|
||||
'ns2' => $request->ns2,
|
||||
'ns3' => $request->ns3,
|
||||
'provider_id' => $request->provider_id,
|
||||
'owned_since' => $request->owned_since,
|
||||
'active' => (isset($request->is_active)) ? 1 : 0
|
||||
]);
|
||||
|
||||
$labels_array = [$request->label1, $request->label2, $request->label3, $request->label4];
|
||||
Labels::deleteLabelsAssignedTo($domain->id);
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned ( label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $domain->id]);
|
||||
}
|
||||
}
|
||||
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $domain->id);
|
||||
|
||||
Cache::forget('services_count');//Main page services_count cache
|
||||
Cache::forget('due_soon');//Main page due_soon cache
|
||||
|
|
|
@ -46,12 +46,6 @@ class MiscController extends Controller
|
|||
|
||||
$ms_id = Str::random(8);
|
||||
|
||||
Misc::create([
|
||||
'id' => $ms_id,
|
||||
'name' => $request->name,
|
||||
'owned_since' => $request->owned_since
|
||||
]);
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
@ -67,6 +61,12 @@ class MiscController extends Controller
|
|||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
Misc::create([
|
||||
'id' => $ms_id,
|
||||
'name' => $request->name,
|
||||
'owned_since' => $request->owned_since
|
||||
]);
|
||||
|
||||
Cache::forget('services_count');//Main page services_count cache
|
||||
Cache::forget('due_soon');//Main page due_soon cache
|
||||
Cache::forget('recently_added');//Main page recently_added cache
|
||||
|
|
|
@ -62,6 +62,27 @@ class ResellerController extends Controller
|
|||
|
||||
$reseller_id = Str::random(8);
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
||||
Pricing::create([
|
||||
'service_id' => $reseller_id,
|
||||
'service_type' => 3,
|
||||
'currency' => $request->currency,
|
||||
'price' => $request->price,
|
||||
'term' => $request->payment_term,
|
||||
'as_usd' => $as_usd,
|
||||
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
|
||||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
if (!is_null($request->dedicated_ip)) {
|
||||
IPs::insertIP($reseller_id, $request->dedicated_ip);
|
||||
}
|
||||
|
||||
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $reseller_id);
|
||||
|
||||
Reseller::create([
|
||||
'id' => $reseller_id,
|
||||
'main_domain' => $request->domain,
|
||||
|
@ -82,41 +103,6 @@ class ResellerController extends Controller
|
|||
'db_limit' => $request->db
|
||||
]);
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
||||
Pricing::create([
|
||||
'service_id' => $reseller_id,
|
||||
'service_type' => 3,
|
||||
'currency' => $request->currency,
|
||||
'price' => $request->price,
|
||||
'term' => $request->payment_term,
|
||||
'as_usd' => $as_usd,
|
||||
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
|
||||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
if (!is_null($request->dedicated_ip)) {
|
||||
IPs::create(
|
||||
[
|
||||
'id' => Str::random(8),
|
||||
'service_id' => $reseller_id,
|
||||
'address' => $request->dedicated_ip,
|
||||
'is_ipv4' => (filter_var($request->dedicated_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1,
|
||||
'active' => 1
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$labels_array = [$request->label1, $request->label2, $request->label3, $request->label4];
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned (label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $reseller_id]);
|
||||
}
|
||||
}
|
||||
|
||||
Cache::forget('services_count');//Main page services_count cache
|
||||
Cache::forget('due_soon');//Main page due_soon cache
|
||||
Cache::forget('recently_added');//Main page recently_added cache
|
||||
|
@ -228,25 +214,14 @@ class ResellerController extends Controller
|
|||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
$deleted = DB::table('labels_assigned')->where('service_id', '=', $request->id)->delete();
|
||||
Labels::deleteLabelsAssignedTo($request->id);
|
||||
|
||||
$labels_array = [$request->label1, $request->label2, $request->label3, $request->label4];
|
||||
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $request->id);
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned ( label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $request->id]);
|
||||
}
|
||||
}
|
||||
|
||||
$delete_ip = DB::table('ips')->where('service_id', '=', $request->id)->delete();
|
||||
IPs::deleteIPsAssignedTo($request->id);
|
||||
|
||||
if (isset($request->dedicated_ip)) {
|
||||
DB::insert('INSERT INTO ips (id, address, service_id, is_ipv4) values (?, ?, ?, ?)', [
|
||||
Str::random(8),
|
||||
$request->dedicated_ip,
|
||||
$request->id,
|
||||
(filter_var($request->dedicated_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1
|
||||
]);
|
||||
IPs::insertIP($request->id, $request->dedicated_ip);
|
||||
}
|
||||
|
||||
Cache::forget('services_count');//Main page services_count cache
|
||||
|
|
|
@ -109,6 +109,29 @@ class ServerController extends Controller
|
|||
|
||||
$server_id = Str::random(8);
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
||||
Pricing::create([
|
||||
'service_id' => $server_id,
|
||||
'service_type' => 1,
|
||||
'currency' => $request->currency,
|
||||
'price' => $request->price,
|
||||
'term' => $request->payment_term,
|
||||
'as_usd' => $as_usd,
|
||||
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
|
||||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
if (!is_null($request->ip1)) {
|
||||
IPs::insertIP($server_id, $request->ip1);
|
||||
}
|
||||
|
||||
if (!is_null($request->ip2)) {
|
||||
IPs::insertIP($server_id, $request->ip2);
|
||||
}
|
||||
|
||||
Server::create([
|
||||
'id' => $server_id,
|
||||
'hostname' => $request->hostname,
|
||||
|
@ -132,52 +155,7 @@ class ServerController extends Controller
|
|||
'show_public' => (isset($request->show_public)) ? 1 : 0
|
||||
]);
|
||||
|
||||
if (!is_null($request->ip1)) {
|
||||
IPs::create(
|
||||
[
|
||||
'id' => Str::random(8),
|
||||
'service_id' => $server_id,
|
||||
'address' => $request->ip1,
|
||||
'is_ipv4' => (filter_var($request->ip1, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1,
|
||||
'active' => 1
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_null($request->ip2)) {
|
||||
IPs::create(
|
||||
[
|
||||
'id' => Str::random(8),
|
||||
'service_id' => $server_id,
|
||||
'address' => $request->ip2,
|
||||
'is_ipv4' => (filter_var($request->ip2, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1,
|
||||
'active' => 1
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
||||
Pricing::create([
|
||||
'service_id' => $server_id,
|
||||
'service_type' => 1,
|
||||
'currency' => $request->currency,
|
||||
'price' => $request->price,
|
||||
'term' => $request->payment_term,
|
||||
'as_usd' => $as_usd,
|
||||
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
|
||||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
$labels_array = [$request->label1, $request->label2, $request->label3, $request->label4];
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned (label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $server_id]);
|
||||
}
|
||||
}
|
||||
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $server_id);
|
||||
|
||||
Cache::forget('services_count');//Main page services_count cache
|
||||
Cache::forget('due_soon');//Main page due_soon cache
|
||||
|
@ -256,9 +234,10 @@ class ServerController extends Controller
|
|||
'next_due_date' => 'date'
|
||||
]);
|
||||
|
||||
$server_id = $request->server_id;
|
||||
|
||||
DB::table('servers')
|
||||
->where('id', $request->server_id)
|
||||
->where('id', $server_id)
|
||||
->update([
|
||||
'hostname' => $request->hostname,
|
||||
'server_type' => $request->server_type,
|
||||
|
@ -287,7 +266,7 @@ class ServerController extends Controller
|
|||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
||||
DB::table('pricings')
|
||||
->where('service_id', $request->server_id)
|
||||
->where('service_id', $server_id)
|
||||
->update([
|
||||
'service_type' => 1,
|
||||
'currency' => $request->currency,
|
||||
|
@ -299,27 +278,16 @@ class ServerController extends Controller
|
|||
'active' => (isset($request->is_active)) ? 1 : 0
|
||||
]);
|
||||
|
||||
$deleted = DB::table('labels_assigned')->where('service_id', '=', $server->id)->delete();
|
||||
Labels::deleteLabelsAssignedTo($server_id);
|
||||
|
||||
$labels_array = [$request->label1, $request->label2, $request->label3, $request->label4];
|
||||
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $server_id);
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned ( label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $request->server_id]);
|
||||
}
|
||||
}
|
||||
|
||||
$deleted = DB::table('ips')->where('service_id', '=', $server->id)->delete();
|
||||
IPs::deleteIPsAssignedTo($server_id);
|
||||
|
||||
for ($i = 1; $i <= 8; $i++) {//Max of 8 ips
|
||||
$obj = 'ip' . $i;
|
||||
if (isset($request->$obj) && !is_null($request->$obj)) {
|
||||
DB::insert('INSERT INTO ips (id, address, service_id, is_ipv4) values (?, ?, ?, ?)', [
|
||||
Str::random(8),
|
||||
$request->$obj,
|
||||
$request->server_id,
|
||||
(filter_var($request->$obj, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1
|
||||
]);
|
||||
IPs::insertIP($server_id, $request->$obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,31 @@ class SharedController extends Controller
|
|||
|
||||
$shared_id = Str::random(8);
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
||||
Pricing::create([
|
||||
'service_id' => $shared_id,
|
||||
'service_type' => 2,
|
||||
'currency' => $request->currency,
|
||||
'price' => $request->price,
|
||||
'term' => $request->payment_term,
|
||||
'as_usd' => $as_usd,
|
||||
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
|
||||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
Labels::deleteLabelsAssignedTo($shared_id);
|
||||
|
||||
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $shared_id);
|
||||
|
||||
IPs::deleteIPsAssignedTo($shared_id);
|
||||
|
||||
if (!is_null($request->dedicated_ip)) {
|
||||
IPs::insertIP($shared_id, $request->dedicated_ip);
|
||||
}
|
||||
|
||||
Shared::create([
|
||||
'id' => $shared_id,
|
||||
'main_domain' => $request->domain,
|
||||
|
@ -79,41 +104,6 @@ class SharedController extends Controller
|
|||
'db__limit' => $request->db
|
||||
]);
|
||||
|
||||
$pricing = new Pricing();
|
||||
|
||||
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||
|
||||
Pricing::create([
|
||||
'service_id' => $shared_id,
|
||||
'service_type' => 2,
|
||||
'currency' => $request->currency,
|
||||
'price' => $request->price,
|
||||
'term' => $request->payment_term,
|
||||
'as_usd' => $as_usd,
|
||||
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
|
||||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
$labels_array = [$request->label1, $request->label2, $request->label3, $request->label4];
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned (label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $shared_id]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($request->dedicated_ip)) {
|
||||
IPs::create(
|
||||
[
|
||||
'id' => Str::random(8),
|
||||
'service_id' => $shared_id,
|
||||
'address' => $request->dedicated_ip,
|
||||
'is_ipv4' => (filter_var($request->dedicated_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1,
|
||||
'active' => 1
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Cache::forget('services_count');//Main page services_count cache
|
||||
Cache::forget('due_soon');//Main page due_soon cache
|
||||
Cache::forget('recently_added');//Main page recently_added cache
|
||||
|
@ -223,25 +213,14 @@ class SharedController extends Controller
|
|||
'next_due_date' => $request->next_due_date,
|
||||
]);
|
||||
|
||||
$deleted = DB::table('labels_assigned')->where('service_id', '=', $request->id)->delete();
|
||||
Labels::deleteLabelsAssignedTo($request->id);
|
||||
|
||||
$labels_array = [$request->label1, $request->label2, $request->label3, $request->label4];
|
||||
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $request->id);
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned ( label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $request->id]);
|
||||
}
|
||||
}
|
||||
|
||||
$delete_ip = DB::table('ips')->where('service_id', '=', $request->id)->delete();
|
||||
IPs::deleteIPsAssignedTo($request->id);
|
||||
|
||||
if (isset($request->dedicated_ip)) {
|
||||
DB::insert('INSERT INTO ips (id, address, service_id, is_ipv4) values (?, ?, ?, ?)', [
|
||||
Str::random(8),
|
||||
$request->dedicated_ip,
|
||||
$request->id,
|
||||
(filter_var($request->dedicated_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1
|
||||
]);
|
||||
IPs::insertIP($request->id, $request->dedicated_ip);
|
||||
}
|
||||
|
||||
Cache::forget('services_count');//Main page services_count cache
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class IPs extends Model
|
||||
{
|
||||
|
@ -21,4 +22,17 @@ class IPs extends Model
|
|||
DB::table('ips')->where('service_id', '=', $service_id)->delete();
|
||||
}
|
||||
|
||||
public static function insertIP(string $service_id, string $address)
|
||||
{
|
||||
self::create(
|
||||
[
|
||||
'id' => Str::random(8),
|
||||
'service_id' => $service_id,
|
||||
'address' => $address,
|
||||
'is_ipv4' => (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1,
|
||||
'active' => 1
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,4 +24,13 @@ class Labels extends Model
|
|||
DB::table('labels_assigned')->where('label_id', '=', $label_id)->delete();
|
||||
}
|
||||
|
||||
public static function insertLabelsAssigned(array $labels_array, string $service_id)
|
||||
{
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!is_null($labels_array[($i - 1)])) {
|
||||
DB::insert('INSERT INTO labels_assigned (label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $service_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user