1
0
forked from poc/pds

Updated alignment and validation logic on import

This commit is contained in:
dhanabalan
2026-01-13 16:44:42 +05:30
parent 2521c04f03
commit bf6b973fd1

View File

@@ -54,31 +54,28 @@ class UserImporter extends Importer
public function resolveRecord(): ?User
{
$warnMsg = [];
$plantCod = $this->data['plant'];
$plant = null;
if (Str::length($this->data['plant']) > 0) {
if (Str::length($this->data['plant']) < 4 || !is_numeric($this->data['plant']) || !preg_match('/^[1-9]\d{3,}$/', $this->data['plant'])) {
$warnMsg[] = "Invalid plant code found!";
}
else {
$plant = Plant::where('code', $this->data['plant'])->first();
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found!';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = "Plant not found";
}
else {
$warnMsg[] = 'Plant not found';
} else {
$plant = $plant->id ?? null;
}
}
}
if (Str::length($this->data['name']) < 1) {
$warnMsg[] = "User name not found!";
if (Str::length($this->data['name']) < 3) {
$warnMsg[] = 'Invalid user name found!';
}
// || !is_numeric($this->data['code']) || !preg_match('/^[1-9]\d{3,}$/', $this->data['code'])
if (Str::length($this->data['email']) < 5) {
$warnMsg[] = "Invalid email found!";
$warnMsg[] = 'Invalid email found!';
}
if (Str::length($this->data['password']) < 3) {
$warnMsg[] = "Invalid password found!";
$warnMsg[] = 'Invalid password found!';
}
// Validate roles if provided
$roles = [];
@@ -93,9 +90,8 @@ class UserImporter extends Importer
$warnMsg[] = "Role : '{$roleName}' does not exist!";
}
}
}
else {
$warnMsg[] = "User roles not found!";
} else {
$warnMsg[] = 'User roles not found!';
}
if (! empty($warnMsg)) {