instances added god may help
This commit is contained in:
@@ -2,12 +2,6 @@
|
||||
|
||||
namespace MintyPHP\Service\Import\Profile;
|
||||
|
||||
use MintyPHP\Repository\Access\RoleRepository;
|
||||
use MintyPHP\Repository\Org\DepartmentRepository;
|
||||
use MintyPHP\Repository\Tenant\TenantRepository;
|
||||
use MintyPHP\Repository\User\UserRepository;
|
||||
use MintyPHP\Service\User\UserService;
|
||||
|
||||
class UserImportProfile implements ImportProfileInterface
|
||||
{
|
||||
/**
|
||||
@@ -15,6 +9,10 @@ class UserImportProfile implements ImportProfileInterface
|
||||
*/
|
||||
private ?array $allowedLocales = null;
|
||||
|
||||
public function __construct(private readonly UserImportGateway $gateway)
|
||||
{
|
||||
}
|
||||
|
||||
public function key(): string
|
||||
{
|
||||
return 'users';
|
||||
@@ -159,7 +157,7 @@ class UserImportProfile implements ImportProfileInterface
|
||||
|
||||
public function dryRunRow(array $normalized, array $context): array
|
||||
{
|
||||
$existing = UserRepository::findByEmail((string) ($normalized['email'] ?? ''));
|
||||
$existing = $this->gateway->findUserByEmail((string) ($normalized['email'] ?? ''));
|
||||
if ($existing) {
|
||||
return ['status' => 'skipped', 'code' => 'email_exists'];
|
||||
}
|
||||
@@ -168,7 +166,7 @@ class UserImportProfile implements ImportProfileInterface
|
||||
|
||||
public function commitRow(array $normalized, array $context): array
|
||||
{
|
||||
$existing = UserRepository::findByEmail((string) ($normalized['email'] ?? ''));
|
||||
$existing = $this->gateway->findUserByEmail((string) ($normalized['email'] ?? ''));
|
||||
if ($existing) {
|
||||
return ['status' => 'skipped', 'code' => 'email_exists'];
|
||||
}
|
||||
@@ -201,11 +199,11 @@ class UserImportProfile implements ImportProfileInterface
|
||||
if ((int) ($normalized['active'] ?? 1) === 1) {
|
||||
$input['active'] = 1;
|
||||
} else {
|
||||
// UserService::createFromAdmin expects a present-but-null value for inactive state.
|
||||
// The admin create flow expects a present-but-null value for inactive state.
|
||||
$input['active'] = null;
|
||||
}
|
||||
|
||||
$result = UserService::createFromAdmin($input, (int) ($context['current_user_id'] ?? 0));
|
||||
$result = $this->gateway->createUserFromAdmin($input, (int) ($context['current_user_id'] ?? 0));
|
||||
if (!($result['ok'] ?? false)) {
|
||||
$errors = $result['errors'] ?? [];
|
||||
$message = is_array($errors) && isset($errors[0]) ? (string) $errors[0] : t('User can not be registered');
|
||||
@@ -335,9 +333,9 @@ class UserImportProfile implements ImportProfileInterface
|
||||
{
|
||||
$tenant = null;
|
||||
if ($this->isUuid($value)) {
|
||||
$tenant = TenantRepository::findByUuid($value);
|
||||
$tenant = $this->gateway->findTenantByUuid($value);
|
||||
} elseif (ctype_digit($value)) {
|
||||
$tenant = TenantRepository::find((int) $value);
|
||||
$tenant = $this->gateway->findTenantById((int) $value);
|
||||
}
|
||||
|
||||
if (!$tenant) {
|
||||
@@ -350,9 +348,9 @@ class UserImportProfile implements ImportProfileInterface
|
||||
{
|
||||
$role = null;
|
||||
if ($this->isUuid($value)) {
|
||||
$role = RoleRepository::findByUuid($value);
|
||||
$role = $this->gateway->findRoleByUuid($value);
|
||||
} elseif (ctype_digit($value)) {
|
||||
$role = RoleRepository::find((int) $value);
|
||||
$role = $this->gateway->findRoleById((int) $value);
|
||||
}
|
||||
|
||||
if (!$role) {
|
||||
@@ -365,9 +363,9 @@ class UserImportProfile implements ImportProfileInterface
|
||||
{
|
||||
$department = null;
|
||||
if ($this->isUuid($value)) {
|
||||
$department = DepartmentRepository::findByUuid($value);
|
||||
$department = $this->gateway->findDepartmentByUuid($value);
|
||||
} elseif (ctype_digit($value)) {
|
||||
$department = DepartmentRepository::find((int) $value);
|
||||
$department = $this->gateway->findDepartmentById((int) $value);
|
||||
}
|
||||
|
||||
if (!$department) {
|
||||
|
||||
Reference in New Issue
Block a user