mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 11:33:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -13,12 +13,7 @@ namespace Chill\MainBundle\Service\Import;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Statement;
|
||||
use Exception;
|
||||
use LogicException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
final class AddressReferenceBaseImporter
|
||||
{
|
||||
@@ -71,16 +66,16 @@ final class AddressReferenceBaseImporter
|
||||
string $street,
|
||||
string $streetNumber,
|
||||
string $source,
|
||||
?float $lat = null,
|
||||
?float $lon = null,
|
||||
?int $srid = null
|
||||
float $lat = null,
|
||||
float $lon = null,
|
||||
int $srid = null
|
||||
): void {
|
||||
if (!$this->isInitialized) {
|
||||
$this->initialize($source);
|
||||
}
|
||||
|
||||
if ($this->currentSource !== $source) {
|
||||
throw new LogicException('Cannot store addresses from different sources during same import. Execute finalize to commit inserts before changing the source');
|
||||
throw new \LogicException('Cannot store addresses from different sources during same import. Execute finalize to commit inserts before changing the source');
|
||||
}
|
||||
|
||||
$this->waitingForInsert[] = [
|
||||
@@ -95,7 +90,7 @@ final class AddressReferenceBaseImporter
|
||||
$srid,
|
||||
];
|
||||
|
||||
if (100 <= count($this->waitingForInsert)) {
|
||||
if (100 <= \count($this->waitingForInsert)) {
|
||||
$this->doInsertPending();
|
||||
}
|
||||
}
|
||||
@@ -122,7 +117,7 @@ final class AddressReferenceBaseImporter
|
||||
|
||||
private function doInsertPending(): void
|
||||
{
|
||||
if (!array_key_exists($forNumber = count($this->waitingForInsert), $this->cachingStatements)) {
|
||||
if (!\array_key_exists($forNumber = \count($this->waitingForInsert), $this->cachingStatements)) {
|
||||
$sql = strtr(self::INSERT, [
|
||||
'{{ values }}' => implode(
|
||||
', ',
|
||||
@@ -130,7 +125,7 @@ final class AddressReferenceBaseImporter
|
||||
),
|
||||
]);
|
||||
|
||||
$this->logger->debug(self::LOG_PREFIX . ' generated sql for insert', [
|
||||
$this->logger->debug(self::LOG_PREFIX.' generated sql for insert', [
|
||||
'sql' => $sql,
|
||||
'forNumber' => $forNumber,
|
||||
]);
|
||||
@@ -142,7 +137,7 @@ final class AddressReferenceBaseImporter
|
||||
return;
|
||||
}
|
||||
|
||||
$this->logger->debug(self::LOG_PREFIX . ' inserting pending addresses', [
|
||||
$this->logger->debug(self::LOG_PREFIX.' inserting pending addresses', [
|
||||
'number' => $forNumber,
|
||||
'first' => $this->waitingForInsert[0] ?? null,
|
||||
]);
|
||||
@@ -153,11 +148,11 @@ final class AddressReferenceBaseImporter
|
||||
$affected = $statement->executeStatement(array_merge(...$this->waitingForInsert));
|
||||
|
||||
if (0 === $affected) {
|
||||
throw new RuntimeException('no row affected');
|
||||
throw new \RuntimeException('no row affected');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
// in some case, we can add debug code here
|
||||
//dump($this->waitingForInsert);
|
||||
// dump($this->waitingForInsert);
|
||||
throw $e;
|
||||
} finally {
|
||||
$this->waitingForInsert = [];
|
||||
@@ -178,8 +173,8 @@ final class AddressReferenceBaseImporter
|
||||
'CREATE INDEX idx_ref_add_temp ON reference_address_temp (refid)'
|
||||
);
|
||||
|
||||
//1) Add new addresses
|
||||
$this->logger->info(self::LOG_PREFIX . 'upsert new addresses');
|
||||
// 1) Add new addresses
|
||||
$this->logger->info(self::LOG_PREFIX.'upsert new addresses');
|
||||
$affected = $this->defaultConnection->executeStatement("INSERT INTO chill_main_address_reference
|
||||
(id, postcode_id, refid, street, streetnumber, municipalitycode, source, point, createdat, deletedat, updatedat)
|
||||
SELECT
|
||||
@@ -198,16 +193,16 @@ final class AddressReferenceBaseImporter
|
||||
ON CONFLICT (refid, source) DO UPDATE
|
||||
SET postcode_id = excluded.postcode_id, refid = excluded.refid, street = excluded.street, streetnumber = excluded.streetnumber, municipalitycode = excluded.municipalitycode, source = excluded.source, point = excluded.point, updatedat = NOW(), deletedAt = NULL
|
||||
");
|
||||
$this->logger->info(self::LOG_PREFIX . 'addresses upserted', ['upserted' => $affected]);
|
||||
$this->logger->info(self::LOG_PREFIX.'addresses upserted', ['upserted' => $affected]);
|
||||
|
||||
//3) Delete addresses
|
||||
$this->logger->info(self::LOG_PREFIX . 'soft delete adresses');
|
||||
// 3) Delete addresses
|
||||
$this->logger->info(self::LOG_PREFIX.'soft delete adresses');
|
||||
$affected = $this->defaultConnection->executeStatement('UPDATE chill_main_address_reference
|
||||
SET deletedat = NOW()
|
||||
WHERE
|
||||
chill_main_address_reference.refid NOT IN (SELECT refid FROM reference_address_temp WHERE source LIKE ?)
|
||||
AND chill_main_address_reference.source LIKE ?
|
||||
', [$this->currentSource, $this->currentSource]);
|
||||
$this->logger->info(self::LOG_PREFIX . 'addresses deleted', ['deleted' => $affected]);
|
||||
$this->logger->info(self::LOG_PREFIX.'addresses deleted', ['deleted' => $affected]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user