fix/add-venta #44

Merged
aldarien merged 6 commits from fix/add-venta into develop 2025-10-03 12:13:05 -03:00
11 changed files with 85 additions and 17 deletions

View File

@ -0,0 +1,68 @@
<?php
namespace Incoviba\Common\Implement\Log\Processor;
use Throwable;
use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;
class Exception implements ProcessorInterface
{
public function __invoke(LogRecord $record): LogRecord
{
$context = $record->context;
$changed = false;
array_walk_recursive($context, function (&$item) use (&$changed) {
if (is_a($item, Throwable::class)) {
$item = $this->processException($item);
$changed = true;
}
});
if ($changed) {
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$record->message,
$context,
$record->extra
);
$record = $new_record;
}
if (is_a($record->message, Throwable::class)) {
$exception = $record->message;
$output = $this->processException($exception);
$message = $output['message'];
if (array_key_exists('exception', $context)) {
$context['other_exception'] = $context['exception'];
}
$context['exception'] = $output;
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$message,
$context,
$record->extra
);
$record = $new_record;
}
return $record;
}
protected function processException(Throwable $exception): array
{
$output = [
'class' => get_class($exception),
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
];
if ($exception->getPrevious() !== null) {
$output['previous'] = $this->processException($exception);
}
return $output;
}
}

View File

@ -19,7 +19,7 @@
<div class="header"> <div class="header">
{{$inmobiliaria->abreviacion}} {{$inmobiliaria->abreviacion}}
</div> </div>
<div class="description">{{$inmobiliaria->razon}} {{$inmobiliaria->tipoSociedad->descripcion}}</div> <div class="description">{{$inmobiliaria->razon}} {{$inmobiliaria->tipoSociedad?->descripcion ?? ''}}</div>
<div class="meta">{{$inmobiliaria->rut()}}</div> <div class="meta">{{$inmobiliaria->rut()}}</div>
</div> </div>
</div> </div>

View File

@ -25,6 +25,7 @@ return [
$container->get(Monolog\Processor\MemoryPeakUsageProcessor::class), $container->get(Monolog\Processor\MemoryPeakUsageProcessor::class),
$container->get(Monolog\Processor\PsrLogMessageProcessor::class), $container->get(Monolog\Processor\PsrLogMessageProcessor::class),
$container->get(Monolog\Processor\UidProcessor::class), $container->get(Monolog\Processor\UidProcessor::class),
$container->get(Incoviba\Common\Implement\Log\Processor\Exception::class),
]; ];
}, },
'baseDefaultHandlers' => function(ContainerInterface $container) { 'baseDefaultHandlers' => function(ContainerInterface $container) {

View File

@ -53,7 +53,7 @@ class Money
} }
try { try {
$this->data[$provider] = (array) $this->fetchRedis($redisService, $redisKey); $this->data[$provider] = (array) $this->fetchRedis($redisService, $redisKey);
if (!isset($this->data[$provider][$date->format('Y-m-d')])) { if (!isset($this->data[$provider][$date->format('Y-m-d')]) or $this->data[$provider][$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($redisKey); throw new EmptyRedis($redisKey);
} }
} catch (EmptyRedis) { } catch (EmptyRedis) {

View File

@ -21,7 +21,7 @@ class IPC
$ipcs = []; $ipcs = [];
try { try {
$ipcs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $ipcs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
if (!isset($ipcs[$dateKey])) { if (!isset($ipcs[$dateKey]) or $ipcs[$dateKey] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
} catch (EmptyRedis) { } catch (EmptyRedis) {

View File

@ -48,8 +48,8 @@ class Ine implements Provider
]); ]);
try { try {
$response = $this->client->get($request_uri); $response = $this->client->get($request_uri);
} catch (GuzzleException) { } catch (GuzzleException $exception) {
throw new EmptyResponse($request_uri); throw new EmptyResponse($request_uri, $exception);
} }
$body = $response->getBody(); $body = $response->getBody();
$json = json_decode($body->getContents()); $json = json_decode($body->getContents());

View File

@ -79,13 +79,7 @@ class Queue extends Ideal\Service
try { try {
$this->jobService->update($job); $this->jobService->update($job);
} catch (Update $exception) { } catch (Update $exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => [ $this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]);
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
]]);
} }
return false; return false;
} }

View File

@ -22,7 +22,7 @@ class UF
if ($date === null) { if ($date === null) {
$date = new DateTimeImmutable(); $date = new DateTimeImmutable();
} }
if ($date->diff($today)->days < 0) { if ($date->diff($today)->invert === 1) {
return 0.0; return 0.0;
} }
/** /**
@ -32,7 +32,7 @@ class UF
*/ */
try { try {
$ufs = $this->getRedisUFs(); $ufs = $this->getRedisUFs();
if (!isset($ufs[$date->format('Y-m-d')])) { if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
return $ufs[$date->format('Y-m-d')]; return $ufs[$date->format('Y-m-d')];
@ -54,12 +54,16 @@ class UF
} }
public function updateMany(array $dates): array public function updateMany(array $dates): array
{ {
$today = new DateTimeImmutable();
$ufs = []; $ufs = [];
try { try {
$ufs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $ufs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
} catch (EmptyRedis) {} } catch (EmptyRedis) {}
$updated = []; $updated = [];
foreach ($dates as $date) { foreach ($dates as $date) {
if ($date->diff($today)->invert === 1) {
continue;
}
if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) { if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) {
$uf = $this->moneyService->getUF($date); $uf = $this->moneyService->getUF($date);
if ($uf === 0.0) { if ($uf === 0.0) {

View File

@ -19,7 +19,7 @@ class USD
$usds = []; $usds = [];
try { try {
$usds = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $usds = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
if (!isset($usds[$date->format('Y-m-d')])) { if (!isset($usds[$date->format('Y-m-d')]) or $usds[$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
$usd = $usds[$date->format('Y-m-d')]; $usd = $usds[$date->format('Y-m-d')];

View File

@ -181,7 +181,8 @@ class Propietario extends Service
]); ]);
$filtered_data = array_intersect_key($data, $fields); $filtered_data = array_intersect_key($data, $fields);
try { try {
$direccion = $this->direccionRepository->fetchByCalleAndNumeroAndExtraAndComuna($filtered_data['calle'], $filtered_data['numero'], $filtered_data['extra'], $filtered_data['comuna']); $direccion = $this->direccionRepository->fetchByCalleAndNumeroAndExtraAndComuna($filtered_data['calle'],
$filtered_data['numero'], $filtered_data['extra'], (int) $filtered_data['comuna']);
} catch (EmptyResult) { } catch (EmptyResult) {
try { try {
$direccion = $this->direccionRepository->create($filtered_data); $direccion = $this->direccionRepository->create($filtered_data);

View File

@ -174,7 +174,7 @@ class Reservation extends Ideal\Service\API
$this->reservationRepository->getConnection()->getPDO()->commit(); $this->reservationRepository->getConnection()->getPDO()->commit();
} }
} catch (PDOException $exception) { } catch (PDOException $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception->getTraceAsString()]); $this->logger->warning($exception->getMessage(), ['exception' => $exception]);
if ($this->reservationRepository->getConnection()->getPDO()->inTransaction()) { if ($this->reservationRepository->getConnection()->getPDO()->inTransaction()) {
$this->reservationRepository->getConnection()->getPDO()->rollBack(); $this->reservationRepository->getConnection()->getPDO()->rollBack();
} }