instances added god may help

This commit is contained in:
2026-02-23 12:58:19 +01:00
parent 25370a1a55
commit 99db252f60
290 changed files with 9858 additions and 4914 deletions

View File

@@ -6,7 +6,7 @@ use MintyPHP\DB;
class TenantMicrosoftAuthRepository
{
private static function unwrap($row): ?array
private function unwrap($row): ?array
{
if (!$row || !is_array($row)) {
return null;
@@ -17,16 +17,16 @@ class TenantMicrosoftAuthRepository
return $row;
}
public static function findByTenantId(int $tenantId): ?array
public function findByTenantId(int $tenantId): ?array
{
$row = DB::selectOne(
'select id, tenant_id, enabled, enforce_microsoft_login, sync_profile_on_login, sync_profile_fields, entra_tenant_id, allowed_domains, use_shared_app, client_id_override, client_secret_override_enc, created, modified from tenant_auth_microsoft where tenant_id = ? limit 1',
(string) $tenantId
);
return self::unwrap($row);
return $this->unwrap($row);
}
public static function listByTenantIds(array $tenantIds): array
public function listByTenantIds(array $tenantIds): array
{
$tenantIds = array_values(array_unique(array_map('intval', $tenantIds)));
$tenantIds = array_values(array_filter($tenantIds, static fn ($id) => $id > 0));
@@ -46,7 +46,7 @@ class TenantMicrosoftAuthRepository
$result = [];
foreach ($rows as $row) {
$item = self::unwrap($row);
$item = $this->unwrap($row);
if (!is_array($item)) {
continue;
}
@@ -60,7 +60,7 @@ class TenantMicrosoftAuthRepository
return $result;
}
public static function upsertByTenantId(int $tenantId, array $data): bool
public function upsertByTenantId(int $tenantId, array $data): bool
{
$result = DB::update(
'insert into tenant_auth_microsoft (tenant_id, enabled, enforce_microsoft_login, sync_profile_on_login, sync_profile_fields, entra_tenant_id, allowed_domains, use_shared_app, client_id_override, client_secret_override_enc, created) values (?,?,?,?,?,?,?,?,?,?,NOW()) ' .
@@ -81,5 +81,4 @@ class TenantMicrosoftAuthRepository
return $result !== false;
}
}

View File

@@ -7,7 +7,7 @@ use MintyPHP\Repository\Support\RepoQuery;
class TenantRepository
{
private static function unwrap(?array $row): ?array
private function unwrap(?array $row): ?array
{
if (!$row) {
return null;
@@ -15,7 +15,7 @@ class TenantRepository
return $row['tenants'] ?? null;
}
private static function unwrapList($rows): array
private function unwrapList($rows): array
{
if (!is_array($rows)) {
return [];
@@ -30,15 +30,15 @@ class TenantRepository
return $list;
}
public static function list(): array
public function list(): array
{
$rows = DB::select(
'select id, uuid, description, address, postal_code, city, country, region, vat_id, tax_number, phone, fax, email, support_email, support_phone, billing_email, website, privacy_url, imprint_url, primary_color, default_theme, allow_user_theme, status, status_changed_at, status_changed_by, created_by, modified_by, created, modified from tenants order by id desc'
);
return self::unwrapList($rows);
return $this->unwrapList($rows);
}
public static function listIds(): array
public function listIds(): array
{
$rows = DB::select('select id from tenants');
if (!is_array($rows)) {
@@ -54,7 +54,7 @@ class TenantRepository
return array_values(array_unique($ids));
}
public static function listByIds(array $tenantIds): array
public function listByIds(array $tenantIds): array
{
$tenantIds = array_values(array_unique(array_map('intval', $tenantIds)));
$tenantIds = array_values(array_filter($tenantIds, static fn ($id) => $id > 0));
@@ -67,10 +67,10 @@ class TenantRepository
'select id, uuid, description, address, postal_code, city, country, region, vat_id, tax_number, phone, fax, email, support_email, support_phone, billing_email, website, privacy_url, imprint_url, primary_color, default_theme, allow_user_theme, status, status_changed_at, status_changed_by, created_by, modified_by, created, modified from tenants where id in (' . $placeholders . ')',
...array_map('strval', $tenantIds)
);
return self::unwrapList($rows);
return $this->unwrapList($rows);
}
public static function listActiveIdsByIds(array $tenantIds): array
public function listActiveIdsByIds(array $tenantIds): array
{
$tenantIds = array_values(array_unique(array_map('intval', $tenantIds)));
if (!$tenantIds) {
@@ -98,7 +98,7 @@ class TenantRepository
return array_values(array_unique($ids));
}
public static function listPaged(array $options): array
public function listPaged(array $options): array
{
$search = trim((string) ($options['search'] ?? ''));
$allowedOrder = ['id', 'uuid', 'description', 'status', 'created', 'modified'];
@@ -140,29 +140,29 @@ class TenantRepository
return [
'total' => $total,
'rows' => self::unwrapList($rows),
'rows' => $this->unwrapList($rows),
];
}
public static function find(int $id): ?array
public function find(int $id): ?array
{
$row = DB::selectOne(
'select id, uuid, description, address, postal_code, city, country, region, vat_id, tax_number, phone, fax, email, support_email, support_phone, billing_email, website, privacy_url, imprint_url, primary_color, default_theme, allow_user_theme, status, status_changed_at, status_changed_by, created_by, modified_by, created, modified from tenants where id = ? limit 1',
(string) $id
);
return self::unwrap($row);
return $this->unwrap($row);
}
public static function findByUuid(string $uuid): ?array
public function findByUuid(string $uuid): ?array
{
$row = DB::selectOne(
'select id, uuid, description, address, postal_code, city, country, region, vat_id, tax_number, phone, fax, email, support_email, support_phone, billing_email, website, privacy_url, imprint_url, primary_color, default_theme, allow_user_theme, status, status_changed_at, status_changed_by, created_by, modified_by, created, modified from tenants where uuid = ? limit 1',
$uuid
);
return self::unwrap($row);
return $this->unwrap($row);
}
public static function create(array $data)
public function create(array $data)
{
return DB::insert(
'insert into tenants (uuid, description, address, postal_code, city, country, region, vat_id, tax_number, phone, fax, email, support_email, support_phone, billing_email, website, privacy_url, imprint_url, primary_color, default_theme, allow_user_theme, status, status_changed_at, status_changed_by, created_by, created) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())',
@@ -194,7 +194,7 @@ class TenantRepository
);
}
public static function update(int $id, array $data): bool
public function update(int $id, array $data): bool
{
$fields = [
'description' => $data['description'],
@@ -242,7 +242,7 @@ class TenantRepository
return $result !== false;
}
public static function delete(int $id): bool
public function delete(int $id): bool
{
$result = DB::delete('delete from tenants where id = ?', (string) $id);
return $result !== false;

View File

@@ -6,7 +6,7 @@ use MintyPHP\DB;
class UserTenantRepository
{
public static function listTenantIdsByUserId(int $userId): array
public function listTenantIdsByUserId(int $userId): array
{
$rows = DB::select('select tenant_id from user_tenants where user_id = ?', (string) $userId);
if (!is_array($rows)) {
@@ -22,7 +22,7 @@ class UserTenantRepository
return array_values(array_unique($ids));
}
public static function replaceForUser(int $userId, array $tenantIds): bool
public function replaceForUser(int $userId, array $tenantIds): bool
{
DB::delete('delete from user_tenants where user_id = ?', (string) $userId);
if (!$tenantIds) {
@@ -40,17 +40,17 @@ class UserTenantRepository
return true;
}
public static function countUsersByTenantIds(array $tenantIds): array
public function countUsersByTenantIds(array $tenantIds): array
{
return self::countByTenantIds($tenantIds, false);
return $this->countByTenantIds($tenantIds, false);
}
public static function countActiveUsersByTenantIds(array $tenantIds): array
public function countActiveUsersByTenantIds(array $tenantIds): array
{
return self::countByTenantIds($tenantIds, true);
return $this->countByTenantIds($tenantIds, true);
}
private static function countByTenantIds(array $tenantIds, bool $activeOnly): array
private function countByTenantIds(array $tenantIds, bool $activeOnly): array
{
$tenantIds = array_values(array_unique(array_map('intval', $tenantIds)));
$tenantIds = array_values(array_filter($tenantIds, static fn ($id) => $id > 0));
@@ -74,17 +74,17 @@ class UserTenantRepository
$result = [];
foreach ($rows as $row) {
$tenantId = self::extractIntField($row, 'tenant_id');
$tenantId = $this->extractIntField($row, 'tenant_id');
if ($tenantId <= 0) {
continue;
}
$result[$tenantId] = self::extractIntField($row, 'user_count');
$result[$tenantId] = $this->extractIntField($row, 'user_count');
}
return $result;
}
private static function extractIntField(array $row, string $field): int
private function extractIntField(array $row, string $field): int
{
foreach ($row as $value) {
if (!is_array($value)) {