74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\Domain\Modal;
|
|
|
|
use App\Models\Domain;
|
|
use Livewire\Attributes\On;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class DomainDeleteModal extends ModalComponent
|
|
{
|
|
public int $domainId;
|
|
public string $domain;
|
|
public int $mailboxes = 0;
|
|
public int $aliases = 0;
|
|
|
|
/** Sicherheits-Input (User muss Domain schreiben) */
|
|
public string $confirm = '';
|
|
|
|
public function mount(int $domainId): void
|
|
{
|
|
$d = Domain::withCount(['mailUsers as mailboxes','mailAliases as aliases'])->findOrFail($domainId);
|
|
|
|
if ($d->is_system) {
|
|
$this->dispatch('toast', type:'forbidden', badge:'System-Domain',
|
|
text:'Diese Domain ist als System-Domain markiert und kann nicht gelöscht werden.', duration:6000);
|
|
$this->dispatch('closeModal');
|
|
return;
|
|
}
|
|
|
|
$this->domainId = $d->id;
|
|
$this->domain = $d->domain;
|
|
$this->mailboxes = (int) $d->mailboxes;
|
|
$this->aliases = (int) $d->aliases;
|
|
}
|
|
|
|
#[On('domain:delete')]
|
|
public function delete(): void
|
|
{
|
|
$d = Domain::withCount(['mailUsers as mailboxes','mailAliases as aliases'])->findOrFail($this->domainId);
|
|
|
|
if ($d->is_system) {
|
|
$this->dispatch('toast', type:'forbidden', badge:'System-Domain', text:'System-Domain kann nicht gelöscht werden.', duration:6000);
|
|
$this->dispatch('closeModal'); return;
|
|
}
|
|
|
|
if ($d->mailboxes > 0 || $d->aliases > 0) {
|
|
$this->dispatch('toast', type:'forbidden', badge:'Domain',
|
|
text:'Löschen blockiert: Es sind noch Postfächer oder Aliasse vorhanden.', duration:0);
|
|
return;
|
|
}
|
|
|
|
if (trim(strtolower($this->confirm)) !== strtolower($d->domain)) {
|
|
$this->dispatch('toast', type:'failed', badge:'Domain', text:'Bestätigung stimmt nicht.', duration:6000);
|
|
return;
|
|
}
|
|
|
|
$name = $d->domain;
|
|
$d->delete();
|
|
|
|
$this->dispatch('domain-updated'); // damit die Liste neu lädt
|
|
$this->dispatch('toast',
|
|
type:'done', badge:'Domain', title:'Domain gelöscht',
|
|
text:'Die Domain <b>'.e($name).'</b> wurde erfolgreich entfernt.', duration:6000);
|
|
$this->dispatch('closeModal');
|
|
}
|
|
|
|
public static function modalMaxWidth(): string { return 'md'; }
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.ui.domain.modal.domain-delete-modal');
|
|
}
|
|
}
|