Cambio en queue para que no quede pegado esperando respuesta en cli.
Chequeo de servicios externos para agregar elementos pendientes.
This commit is contained in:
@ -20,6 +20,18 @@ class Persona extends Ideal\Service
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getAll(null|string|array $orderBy = null): array
|
||||
{
|
||||
try {
|
||||
try {
|
||||
$ruts = $this->personaRepository->fetchMissing();
|
||||
$this->addMissingPropietarios($ruts);
|
||||
} catch (Implement\Exception\EmptyResult | Read | Create) {}
|
||||
return array_map([$this, 'process'], $this->personaRepository->fetchAll($orderBy));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param int $rut
|
||||
* @return Model\Persona
|
||||
@ -29,7 +41,7 @@ class Persona extends Ideal\Service
|
||||
{
|
||||
try {
|
||||
return $this->process($this->personaRepository->fetchById($rut));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
try {
|
||||
$this->propietarioRepository->fetchById($rut);
|
||||
return $this->add(compact('rut'));
|
||||
@ -91,6 +103,60 @@ class Persona extends Ideal\Service
|
||||
}
|
||||
return $this->process($persona);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ruts
|
||||
* @param bool $load
|
||||
* @return array
|
||||
* @throws Create
|
||||
* @throws Read
|
||||
*/
|
||||
public function addMissingPropietarios(array $ruts, bool $load = false): ?array
|
||||
{
|
||||
try {
|
||||
$propietarios = $this->propietarioRepository->fetchByRuts($ruts);
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
$data = [];
|
||||
$datos = [];
|
||||
foreach ($propietarios as $i => $propietario) {
|
||||
$data []= [
|
||||
'rut' => $propietario->rut,
|
||||
'digito' => $propietario->dv,
|
||||
'nombres' => $propietario->nombres,
|
||||
'apellido_paterno' => $propietario->apellidos['paterno'],
|
||||
'apellido_materno' => $propietario->apellidos['materno'],
|
||||
];
|
||||
$datos []= [
|
||||
'persona_rut' => $propietario->rut,
|
||||
'direccion_id' => $propietario->datos?->direccion_id,
|
||||
'email' => $propietario->datos?->email,
|
||||
'telefono' => $propietario->datos?->telefono,
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$personas = $this->personaRepository->saveMissing($data);
|
||||
} catch (PDOException|Implement\Exception\EmptyResult $exception) {
|
||||
throw new Create(__CLASS__, $exception);
|
||||
}
|
||||
$personasRuts = array_map(function(Model\Persona $persona) {
|
||||
return $persona->rut;
|
||||
}, $personas);
|
||||
$datos = array_filter($datos, function($row) use ($personasRuts) {
|
||||
return in_array($row['persona_rut'], $personasRuts);
|
||||
});
|
||||
try {
|
||||
$this->datosPersonaRepository->saveMissing($datos);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Create(__CLASS__, $exception);
|
||||
}
|
||||
if ($load) {
|
||||
return array_map([$this, 'process'], $personas);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function edit(Model\Persona $persona, array $data): Model\Persona
|
||||
{
|
||||
$filteredData = $this->personaRepository->filterData($data);
|
||||
|
Reference in New Issue
Block a user