From 2bac177618e8629898ed1f1e13f6dcd368c94d73 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 2 Aug 2022 19:16:52 +1000 Subject: [PATCH] Some service host/domain updates, including schema updates --- app/Http/Controllers/ServiceController.php | 35 --- app/Models/DomainRegistrar.php | 5 - app/Models/DomainTld.php | 35 --- app/Models/HostServer.php | 10 - app/Models/Service/Domain.php | 20 ++ app/Models/Service/Host.php | 23 +- app/Models/SupplierHostServer.php | 11 + composer.json | 2 +- composer.lock | 22 +- ..._08_02_155407_convert_domain_registrar.php | 70 ++++++ public/css/fixes.css | 18 ++ .../service/widget/domain/update.blade.php | 209 ++++++------------ .../service/widget/host/update.blade.php | 163 +++++--------- 13 files changed, 283 insertions(+), 340 deletions(-) delete mode 100644 app/Models/DomainTld.php delete mode 100644 app/Models/HostServer.php create mode 100644 app/Models/SupplierHostServer.php create mode 100644 database/migrations/2022_08_02_155407_convert_domain_registrar.php diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index a38152d..cef2169 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -228,41 +228,6 @@ class ServiceController extends Controller } } - /** - * Edit a domain service details - * - * @param Request $request - * @param Service $o - * @return RedirectResponse - * @deprecated - use update() - */ - public function domain_edit(Request $request,Service $o) - { - session()->flash('service_update',TRUE); - - $validation = $request->validate([ - 'service.domain_name' => ['required',function($attribute,$value,$fail) use ($request,$o) { - if (Service\Domain::where('domain_name',$value) - ->where('domain_tld_id',Arr::get($request,'service.domain_tld_id')) - ->when($o->type,function($q) use ($o) { return $q->where('id','<>',$o->type->id); }) - ->count() > 0) - { - $fail('Domain already exists.'); - } - }], - 'service.domain_expire' => 'required|date', - 'service.domain_tld_id' => 'required|exists:ab_domain_tld,id', - 'service.domain_registrar_id' => 'required|exists:ab_domain_registrar,id', - 'service.registrar_account' => 'required', - 'service.registrar_username' => 'required|string|min:5', - 'service.registrar_ns' => 'required|string|min:5', - ]); - - $o->type->forceFill($validation['service'])->save(); - - return redirect()->back()->with('success','Record updated.'); - } - /** * List all the domains managed by the user * diff --git a/app/Models/DomainRegistrar.php b/app/Models/DomainRegistrar.php index c343408..a72999d 100644 --- a/app/Models/DomainRegistrar.php +++ b/app/Models/DomainRegistrar.php @@ -5,12 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Leenooks\Traits\ScopeActive; -/** - * @deprecated - */ class DomainRegistrar extends Model { use ScopeActive; - - protected $table = 'ab_domain_registrar'; } \ No newline at end of file diff --git a/app/Models/DomainTld.php b/app/Models/DomainTld.php deleted file mode 100644 index 373ddcb..0000000 --- a/app/Models/DomainTld.php +++ /dev/null @@ -1,35 +0,0 @@ -hasMany(Service::class); - } - - /* ATTRIBUTES */ - - public function getNameAttribute($value): string - { - return strtoupper($value); - } - - public function getPriceGroupAttribute($value): array - { - return unserialize($value); - } -} \ No newline at end of file diff --git a/app/Models/HostServer.php b/app/Models/HostServer.php deleted file mode 100644 index 6313eda..0000000 --- a/app/Models/HostServer.php +++ /dev/null @@ -1,10 +0,0 @@ - 'nullable|string|min:2', + 'tld_id' => 'required|exists:tlds,id', + 'expire_at' => 'required|date', + 'domain_registrar_id' => 'required|exists:domain_registrars,id', + 'registrar_account' => 'nullable|string', + 'registrar_ns' => 'nullable|string', + 'registrar_username' => 'nullable|string', + ]; + } + /* RELATIONS */ public function registrar() diff --git a/app/Models/Service/Host.php b/app/Models/Service/Host.php index 6af41c0..35bec09 100644 --- a/app/Models/Service/Host.php +++ b/app/Models/Service/Host.php @@ -2,7 +2,7 @@ namespace App\Models\Service; -use App\Models\HostServer; +use App\Models\SupplierHostServer; use App\Traits\ServiceDomains; /** @@ -20,6 +20,25 @@ class Host extends Type public function provider() { - return $this->belongsTo(HostServer::class,'host_server_id'); + return $this->belongsTo(SupplierHostServer::class,'supplier_host_server_id'); + } + + /* OVERRIDES */ + + /** + * Service update validation + * + * @return array + */ + public function validation(): array + { + return [ + 'domain_name' => 'nullable|string|min:2', + 'tld_id' => 'required|exists:tlds,id', + 'expire_at' => 'required|date', + 'supplier_host_server_id' => 'required|exists:supplier_host_servers,id', + 'host_username' => 'nullable|string', + 'host_password' => 'nullable|string', + ]; } } \ No newline at end of file diff --git a/app/Models/SupplierHostServer.php b/app/Models/SupplierHostServer.php new file mode 100644 index 0000000..90b5c4a --- /dev/null +++ b/app/Models/SupplierHostServer.php @@ -0,0 +1,11 @@ +datetime('created_at')->nullable()->after('id'); + $table->datetime('updated_at')->nullable()->after('created_at'); + + $table->dropForeign('ab_domain_registrar_site_id_foreign'); + $table->dropIndex('ab_domain_registrar_id_site_id_index'); + + $table->foreign(['site_id'])->references(['id'])->on('sites'); + }); + + Schema::table('service_domain', function (Blueprint $table) { + $table->foreign(['domain_registrar_id','site_id'])->references(['id','site_id'])->on('domain_registrars'); + }); + + DB::statement('RENAME TABLE ab_host_server TO supplier_host_servers'); + DB::statement('ALTER TABLE supplier_host_servers MODIFY active tinyint(1) DEFAULT NULL,MODIFY debug tinyint(1) DEFAULT NULL'); + DB::statement('ALTER TABLE supplier_host_servers MODIFY id int unsigned auto_increment,MODIFY site_id int unsigned NOT NULL,MODIFY max_accounts int unsigned DEFAULT NULL'); + DB::statement('ALTER TABLE supplier_host_servers MODIFY notes longtext DEFAULT NULL'); + + Schema::table('supplier_host_servers', function (Blueprint $table) { + $table->datetime('created_at')->nullable()->after('id'); + $table->datetime('updated_at')->nullable()->after('created_at'); + + $table->integer('supplier_id')->unsigned()->nullable(); + + $table->foreign(['site_id'])->references(['id'])->on('sites'); + $table->foreign(['supplier_id'])->references(['id'])->on('suppliers'); + }); + + DB::statement('ALTER TABLE service_host RENAME COLUMN host_server_id TO supplier_host_server_id'); + DB::statement('ALTER TABLE service_host MODIFY supplier_host_server_id int unsigned DEFAULT NULL'); + + Schema::table('service_host', function (Blueprint $table) { + $table->foreign(['supplier_host_server_id','site_id'])->references(['id','site_id'])->on('supplier_host_servers'); + }); + + DB::statement('DROP TABLE ab_domain_tld'); + //delete from ab_host_server where id=0; + //alter table service_host modify host_server_id int unsigned default null; + //update service_host set host_server_id=NULL where host_server_id=0 + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + abort(500,'Cant go back'); + } +}; diff --git a/public/css/fixes.css b/public/css/fixes.css index 344a045..5bd3062 100644 --- a/public/css/fixes.css +++ b/public/css/fixes.css @@ -110,4 +110,22 @@ span.select2-selection.select2-selection--single > span.select2-selection__rende .card-header.bg-dark .nav-pills .nav-link:not(.active):hover { background-color: #6c757d; color: #ffffff; +} + +/* Fixes to select2, to make sure col-x widths are honoured */ +.select2-selection.select2-selection--single { + height: calc(2.25rem + 2px) !important; +} +.select2.select2-container.select2-container--default { + display: flex; + flex: 1 1 auto; +} +.select2.select2-container.select2-container--default .selection { + width: 100%; +} + +/* Render the invalid red when a select container fails validation */ +.is-invalid + .select2-container--default .select2-selection--single, +.is-invalid + .select2-container--default .select2-selection--multiple { + border: 1px solid #dc3545; } \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/service/widget/domain/update.blade.php b/resources/views/theme/backend/adminlte/service/widget/domain/update.blade.php index 90d5355..57a4b1f 100644 --- a/resources/views/theme/backend/adminlte/service/widget/domain/update.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/domain/update.blade.php @@ -1,145 +1,97 @@
-
-
+
+
- + +
.
- + @foreach(\App\Models\TLD::orderBy('name')->get() as $oo) + @endforeach - @error('domain.domain_name') + @error('domain_name') + {{ $message }} + @enderror + @error('tld_id') {{ $message }} - @else - Domain Name is required. @enderror
- Licensed Domain Name.
-
-
- -
-
- -
- - - @error('domain.domain_expire') - {{ $message }} - @else - Domain Expiry is required. - @enderror - -
- Date Domain Expires. -
+
+ @include('adminlte::widget.form_date',[ + 'label'=>'Expiry', + 'id'=>'expire_at', + 'old'=>'domain.expire_at', + 'name'=>'domain[expire_at]', + 'value'=>$o->expire_at ? $o->expire_at->format('Y-m-d') : ($o->connect_at ? $o->connect_at->addMonths($o->contract_term)->format('Y-m-d') : ''), + ]) +
+
+ +
+

Registrar Details

+ +
+
+ @include('adminlte::widget.form_select',[ + 'label'=>'Registrar', + 'icon'=>'fas fa-handshake', + 'id'=>'domain_registrar_id', + 'old'=>'domain.domain_registrar_id', + 'name'=>'domain[domain_registrar_id]', + 'options'=>\App\Models\DomainRegistrar::active()->orderBy('name')->get()->transform(function($item) { return ['id'=>$item->id,'value'=>$item->name]; }), + 'value'=>$o->domain_registrar_id ?? '', + ]) +
+ +
+ @include('adminlte::widget.form_text',[ + 'label'=>'Registrar Account', + 'icon'=>'fas fa-user-circle', + 'id'=>'registrar_account', + 'old'=>'domain.registrar_account', + 'name'=>'domain[registrar_account]', + 'value'=>$o->registrar_account ?? '', + ])
-
-
- -
-
- -
- - - - @error('domain.domain_registrar_id') - {{ $message }} - @else - Domain Registrar is required. - @enderror - -
- Domain Name Registrar. -
+
+ @include('adminlte::widget.form_select',[ + 'label'=>'DNS Location', + 'icon'=>'fas fa-project-diagram', + 'id'=>'registrar_ns', + 'old'=>'domain.registrar_ns', + 'name'=>'domain[registrar_ns]', + 'options'=>\App\Models\Service\Domain::select('registrar_ns')->distinct()->orderBy('registrar_ns')->get()->transform(function($item) { return ['id'=>$item->registrar_ns,'value'=>$item->registrar_ns]; }), + 'value'=>$o->registrar_ns ?? '', + 'addvalues'=>TRUE, + ])
-
-
- -
-
- -
- - - @error('domain.registrar_account') - {{ $message }} - @else - Registrar Account ID is required. - @enderror - -
- Registrar Account ID. -
-
-
- -
-
-
- -
-
- -
- - - @error('domain.registrar_ns') - {{ $message }} - @else - DNS Details is required. - @enderror - -
- Domain DNS details. -
-
- -
-
- -
-
- -
- - - @error('domain.registrar_username') - {{ $message }} - @else - Registrar Username is required. - @enderror - -
- Registrar Username ID. -
+
+ @include('adminlte::widget.form_text',[ + 'label'=>'Registrar Username', + 'icon'=>'fas fa-user', + 'id'=>'registrar_username', + 'old'=>'domain.registrar_username', + 'name'=>'domain[registrar_username]', + 'value'=>$o->registrar_username ?? '', + ])
@@ -147,33 +99,12 @@ @css(select2) @js(select2,autofocus) - - -@append +@append \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/service/widget/host/update.blade.php b/resources/views/theme/backend/adminlte/service/widget/host/update.blade.php index 2aff793..bc5ecdf 100644 --- a/resources/views/theme/backend/adminlte/service/widget/host/update.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/host/update.blade.php @@ -1,115 +1,85 @@
- -
-
+
+
- + +
.
- + @foreach(\App\Models\TLD::orderBy('name')->get() as $oo) + @endforeach - @error('host.domain_name') - {{ $message }} - @else - Domain Name is required. - @enderror - -
- Domain Name -
-
- - -
-
- -
-
- -
- - - @error('host.host_expire') + @error('domain_name') + {{ $message }} + @enderror + @error('tld_id') {{ $message }} @enderror
- Hosting Expires
+ +
+ @include('adminlte::widget.form_date',[ + 'label'=>'Expiry', + 'id'=>'expire_at', + 'old'=>'host.expire_at', + 'name'=>'host[expire_at]', + 'value'=>$o->expire_at ? $o->expire_at->format('Y-m-d') : ($o->connect_at ? $o->connect_at->addMonths($o->contract_term)->format('Y-m-d') : ''), + ]) +
+
+ +
+

Hosting Details

+ +
+
+ @include('adminlte::widget.form_select',[ + 'label'=>'Hosting Server', + 'icon'=>'fas fa-handshake', + 'id'=>'supplier_host_server_id', + 'old'=>'host.supplier_host_server_id', + 'name'=>'host[supplier_host_server_id]', + 'options'=>\App\Models\SupplierHostServer::active()->orderBy('name')->get()->transform(function($item) { return ['id'=>$item->id,'value'=>$item->name]; }), + 'value'=>$o->supplier_host_server_id ?? '', + ]) +
- {{-- - -
-
- -
-
- -
- - - @error('host.admin_url') - {{ $message }} - @enderror - -
- Admin URL -
-
- --}} -
- -
- -
-
- -
-
- -
- - - @error('host.host_username') - {{ $message }} - @enderror - -
- Admin USER -
+
+ @include('adminlte::widget.form_text',[ + 'label'=>'Admin User', + 'icon'=>'fas fa-user', + 'id'=>'host_username', + 'old'=>'host.host_username', + 'name'=>'host[host_username]', + 'value'=>$o->host_username ?? '', + ])
- -
-
- -
-
- -
- - - @error('host.host_password') - {{ $message }} - @enderror - -
- Admin PASSWORD -
+
+ @include('adminlte::widget.form_text',[ + 'label'=>'Admin Password', + 'icon'=>'fas fa-lock', + 'id'=>'host_password', + 'old'=>'host.host_password', + 'name'=>'host[host_password]', + 'value'=>$o->host_password ?? '', + ])
@@ -117,23 +87,12 @@ @css(select2) @js(select2,autofocus) - - @append \ No newline at end of file