diff --git a/core/Repository/CustomField/TenantCustomFieldDefinitionRepository.php b/core/Repository/CustomField/TenantCustomFieldDefinitionRepository.php index 1c34173..657d398 100644 --- a/core/Repository/CustomField/TenantCustomFieldDefinitionRepository.php +++ b/core/Repository/CustomField/TenantCustomFieldDefinitionRepository.php @@ -48,8 +48,7 @@ class TenantCustomFieldDefinitionRepository implements TenantCustomFieldDefiniti public function listByTenantIds(array $tenantIds, bool $onlyActive = true): array { - $tenantIds = array_values(array_unique(array_map('intval', $tenantIds))); - $tenantIds = array_values(array_filter($tenantIds, static fn ($id) => $id > 0)); + $tenantIds = toIntIds($tenantIds); if (!$tenantIds) { return []; } @@ -65,8 +64,7 @@ class TenantCustomFieldDefinitionRepository implements TenantCustomFieldDefiniti public function listFilterableByTenantIds(array $tenantIds): array { - $tenantIds = array_values(array_unique(array_map('intval', $tenantIds))); - $tenantIds = array_values(array_filter($tenantIds, static fn ($id) => $id > 0)); + $tenantIds = toIntIds($tenantIds); if (!$tenantIds) { return []; } diff --git a/core/Repository/CustomField/TenantCustomFieldOptionRepository.php b/core/Repository/CustomField/TenantCustomFieldOptionRepository.php index 25b9e3c..1700a81 100644 --- a/core/Repository/CustomField/TenantCustomFieldOptionRepository.php +++ b/core/Repository/CustomField/TenantCustomFieldOptionRepository.php @@ -24,8 +24,7 @@ class TenantCustomFieldOptionRepository implements TenantCustomFieldOptionReposi public function listByDefinitionIds(array $definitionIds, bool $onlyActive = true): array { - $definitionIds = array_values(array_unique(array_map('intval', $definitionIds))); - $definitionIds = array_values(array_filter($definitionIds, static fn ($id) => $id > 0)); + $definitionIds = toIntIds($definitionIds); if (!$definitionIds) { return []; } diff --git a/core/Repository/Tenant/TenantLdapAuthRepository.php b/core/Repository/Tenant/TenantLdapAuthRepository.php index a359e07..3ef084b 100644 --- a/core/Repository/Tenant/TenantLdapAuthRepository.php +++ b/core/Repository/Tenant/TenantLdapAuthRepository.php @@ -31,8 +31,7 @@ class TenantLdapAuthRepository implements TenantLdapAuthRepositoryInterface 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)); + $tenantIds = toIntIds($tenantIds); if (!$tenantIds) { return []; } diff --git a/core/Repository/Tenant/TenantMicrosoftAuthRepository.php b/core/Repository/Tenant/TenantMicrosoftAuthRepository.php index 022f468..7f2c4e6 100644 --- a/core/Repository/Tenant/TenantMicrosoftAuthRepository.php +++ b/core/Repository/Tenant/TenantMicrosoftAuthRepository.php @@ -29,8 +29,7 @@ class TenantMicrosoftAuthRepository implements TenantMicrosoftAuthRepositoryInte 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)); + $tenantIds = toIntIds($tenantIds); if (!$tenantIds) { return []; } diff --git a/core/Repository/Tenant/TenantRepository.php b/core/Repository/Tenant/TenantRepository.php index 0b4fefb..d15b477 100644 --- a/core/Repository/Tenant/TenantRepository.php +++ b/core/Repository/Tenant/TenantRepository.php @@ -82,8 +82,7 @@ class TenantRepository implements TenantRepositoryInterface } if (array_key_exists('tenantIds', $options)) { $tenantIds = $options['tenantIds']; - $tenantIds = is_array($tenantIds) ? array_values(array_unique(array_map('intval', $tenantIds))) : []; - $tenantIds = array_values(array_filter($tenantIds, static fn ($id) => $id > 0)); + $tenantIds = is_array($tenantIds) ? toIntIds($tenantIds) : []; if ($tenantIds) { $where[] = 'tenants.id in (???)'; $params[] = $tenantIds; diff --git a/core/Repository/Tenant/UserTenantRepository.php b/core/Repository/Tenant/UserTenantRepository.php index 1ff6d26..b571423 100644 --- a/core/Repository/Tenant/UserTenantRepository.php +++ b/core/Repository/Tenant/UserTenantRepository.php @@ -53,8 +53,7 @@ class UserTenantRepository implements UserTenantRepositoryInterface 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)); + $tenantIds = toIntIds($tenantIds); if (!$tenantIds) { return []; } diff --git a/core/Service/Tenant/TenantScopeService.php b/core/Service/Tenant/TenantScopeService.php index 6563a67..446ff30 100644 --- a/core/Service/Tenant/TenantScopeService.php +++ b/core/Service/Tenant/TenantScopeService.php @@ -90,7 +90,7 @@ class TenantScopeService public function filterTenantIdsForUser(array $tenantIds, int $userId): array { - $tenantIds = array_values(array_unique(array_map('intval', $tenantIds))); + $tenantIds = toIntIds($tenantIds); $userTenantIds = $this->getUserTenantIds($userId); if (!$userTenantIds) { return []; @@ -104,9 +104,9 @@ class TenantScopeService array $existingTenantIds, array $allowedTenantIds ): array { - $requestedTenantIds = array_values(array_unique(array_map('intval', $requestedTenantIds))); - $existingTenantIds = array_values(array_unique(array_map('intval', $existingTenantIds))); - $allowedTenantIds = array_values(array_unique(array_map('intval', $allowedTenantIds))); + $requestedTenantIds = toIntIds($requestedTenantIds); + $existingTenantIds = toIntIds($existingTenantIds); + $allowedTenantIds = toIntIds($allowedTenantIds); if (!$allowedTenantIds) { return $existingTenantIds; @@ -165,7 +165,7 @@ class TenantScopeService private function filterActiveTenantIds(array $tenantIds): array { - $tenantIds = array_values(array_unique(array_map('intval', $tenantIds))); + $tenantIds = toIntIds($tenantIds); if (!$tenantIds) { return []; }