32 lines
917 B
PHP
32 lines
917 B
PHP
<?php
|
|
|
|
use MintyPHP\Support\Flash;
|
|
use MintyPHP\Support\Guard;
|
|
use MintyPHP\Router;
|
|
use MintyPHP\Service\TenantService;
|
|
use MintyPHP\Service\PermissionService;
|
|
use MintyPHP\Service\AuthService;
|
|
|
|
Guard::requireLogin();
|
|
Guard::requirePermissionOrForbidden(PermissionService::TENANTS_DELETE);
|
|
|
|
$uuid = trim((string) ($id ?? ''));
|
|
if ($uuid === '') {
|
|
Router::redirect('admin/tenants');
|
|
}
|
|
|
|
$result = TenantService::deleteByUuid($uuid);
|
|
if (!($result['ok'] ?? false)) {
|
|
Flash::error('Tenant not found', 'admin/tenants', 'tenant_not_found');
|
|
Router::redirect('admin/tenants');
|
|
}
|
|
|
|
// Refresh session tenant data (removes deleted tenant, switches if it was current)
|
|
$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
|
|
if ($currentUserId > 0) {
|
|
AuthService::loadTenantDataIntoSession($currentUserId);
|
|
}
|
|
|
|
Flash::success('Tenant deleted', 'admin/tenants', 'tenant_deleted');
|
|
Router::redirect('admin/tenants');
|