mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge branch '111_exports_suite' into testing
This commit is contained in:
@@ -445,7 +445,7 @@ class ExportController extends AbstractController
|
||||
|
||||
$this->logger->notice('[export] choices for an export unserialized', [
|
||||
'key' => $key,
|
||||
'rawData' => json_encode($rawData)
|
||||
'rawData' => json_encode($rawData),
|
||||
]);
|
||||
|
||||
$alias = $rawData['alias'];
|
||||
|
@@ -15,7 +15,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table(name="chill_main_geographical_unit", uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(name="geographical_unit_refid", columns={"layer_id", "unitRefId"})
|
||||
* @ORM\UniqueConstraint(name="geographical_unit_refid", columns={"layer_id", "unitRefId"})
|
||||
* })
|
||||
* @ORM\Entity(readOnly=true)
|
||||
*/
|
||||
@@ -33,6 +33,11 @@ class GeographicalUnit
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=GeographicalUnitLayer::class, inversedBy="units")
|
||||
*/
|
||||
private ?GeographicalUnitLayer $layer;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", nullable=false, options={"default": ""})
|
||||
*/
|
||||
@@ -43,21 +48,14 @@ class GeographicalUnit
|
||||
*/
|
||||
private string $unitRefId;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=GeographicalUnitLayer::class, inversedBy="units")
|
||||
*/
|
||||
private ?GeographicalUnitLayer $layer;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
protected function setId(int $id): self
|
||||
public function getLayer(): ?GeographicalUnitLayer
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
return $this->layer;
|
||||
}
|
||||
|
||||
public function getUnitName(): ?string
|
||||
@@ -65,31 +63,10 @@ class GeographicalUnit
|
||||
return $this->unitName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GeographicalUnitLayer|null
|
||||
*/
|
||||
public function getLayer(): ?GeographicalUnitLayer
|
||||
{
|
||||
return $this->layer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unitRefId
|
||||
* @return GeographicalUnit
|
||||
*/
|
||||
public function setUnitRefId(string $unitRefId): GeographicalUnit
|
||||
{
|
||||
$this->unitRefId = $unitRefId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GeographicalUnitLayer|null $layer
|
||||
* @return GeographicalUnit
|
||||
*/
|
||||
public function setLayer(?GeographicalUnitLayer $layer): GeographicalUnit
|
||||
{
|
||||
$this->layer = $layer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -99,4 +76,18 @@ class GeographicalUnit
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setUnitRefId(string $unitRefId): GeographicalUnit
|
||||
{
|
||||
$this->unitRefId = $unitRefId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function setId(int $id): self
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
@@ -8,7 +17,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table(name="chill_main_geographical_unit_layer", uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(name="geographical_unit_layer_refid", columns={"refId"})
|
||||
* @ORM\UniqueConstraint(name="geographical_unit_layer_refid", columns={"refId"})
|
||||
* })
|
||||
* @ORM\Entity
|
||||
*/
|
||||
@@ -41,45 +50,30 @@ class GeographicalUnitLayer
|
||||
$this->units = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getName(): array
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $name
|
||||
* @return GeographicalUnitLayer
|
||||
*/
|
||||
public function setName(array $name): GeographicalUnitLayer
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRefId(): string
|
||||
{
|
||||
return $this->refId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getUnits(): Collection
|
||||
{
|
||||
return $this->units;
|
||||
}
|
||||
}
|
||||
|
||||
public function setName(array $name): GeographicalUnitLayer
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ namespace Chill\MainBundle\Export;
|
||||
|
||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
@@ -265,16 +264,14 @@ class ExportManager
|
||||
$this->handleAggregators($export, $query, $data[ExportType::AGGREGATOR_KEY], $centers);
|
||||
|
||||
$this->logger->notice('[export] will execute this qb in export', [
|
||||
'dql' => $query->getDQL()
|
||||
'dql' => $query->getDQL(),
|
||||
]);
|
||||
|
||||
} else {
|
||||
throw new UnexpectedValueException('The method `intiateQuery` should return '
|
||||
. 'a `\\Doctrine\\ORM\\NativeQuery` or a `Doctrine\\ORM\\QueryBuilder` '
|
||||
. 'object.');
|
||||
}
|
||||
|
||||
|
||||
$result = $export->getResult($query, $data[ExportType::EXPORT_KEY]);
|
||||
|
||||
if (!is_iterable($result)) {
|
||||
|
@@ -14,9 +14,7 @@ namespace Chill\MainBundle\Form\Type\Export;
|
||||
use Chill\MainBundle\Center\GroupingCenterInterface;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
@@ -49,9 +47,6 @@ class PickCenterType extends AbstractType
|
||||
*/
|
||||
protected array $groupingCenters = [];
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||
*/
|
||||
protected UserInterface $user;
|
||||
|
||||
public function __construct(
|
||||
|
@@ -14,7 +14,6 @@ namespace Chill\MainBundle\Repository;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final class CenterRepository implements CenterRepositoryInterface
|
||||
{
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
@@ -8,11 +17,11 @@ use Doctrine\Persistence\ObjectRepository;
|
||||
interface CenterRepositoryInterface extends ObjectRepository
|
||||
{
|
||||
/**
|
||||
* Return all active centers
|
||||
* Return all active centers.
|
||||
*
|
||||
* Note: this is a teaser: active will comes later on center entity
|
||||
*
|
||||
* @return Center[]
|
||||
*/
|
||||
public function findActive(): array;
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,19 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\GeographicalUnit;
|
||||
use Chill\MainBundle\Entity\GeographicalUnitLayer;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use UnexpectedValueException;
|
||||
|
||||
final class GeographicalUnitLayerLayerRepository implements GeographicalUnitLayerRepositoryInterface
|
||||
{
|
||||
@@ -30,6 +37,15 @@ final class GeographicalUnitLayerLayerRepository implements GeographicalUnitLaye
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
public function findAllHavingUnits(): array
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('l');
|
||||
|
||||
return $qb->where($qb->expr()->gt('SIZE(l.units)', 0))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|GeographicalUnitLayer[]
|
||||
*/
|
||||
@@ -47,13 +63,4 @@ final class GeographicalUnitLayerLayerRepository implements GeographicalUnitLaye
|
||||
{
|
||||
return GeographicalUnitLayer::class;
|
||||
}
|
||||
|
||||
public function findAllHavingUnits(): array
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('l');
|
||||
|
||||
return $qb->where($qb->expr()->gt('SIZE(l.units)', 0))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\GeographicalUnitLayer;
|
||||
@@ -11,4 +20,4 @@ interface GeographicalUnitLayerRepositoryInterface extends ObjectRepository
|
||||
* @return array|GeographicalUnitLayer[]
|
||||
*/
|
||||
public function findAllHavingUnits(): array;
|
||||
}
|
||||
}
|
||||
|
@@ -1,33 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\GeographicalUnit;
|
||||
use Chill\MainBundle\Entity\GeographicalUnitDTO;
|
||||
use Chill\MainBundle\Entity\GeographicalUnitLayer;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class GeographicalUnitRepository implements GeographicalUnitRepositoryInterface
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private EntityRepository $repository;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->repository = $em->getRepository($this->getClassName());
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
|
||||
public function find($id): ?GeographicalUnit
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return only partial object, where the @link{GeographicalUnit::geom} property is not loaded
|
||||
* Will return only partial object, where the @see{GeographicalUnit::geom} property is not loaded.
|
||||
*
|
||||
* @return array|GeographicalUnit[]
|
||||
*/
|
||||
@@ -56,4 +62,4 @@ class GeographicalUnitRepository implements GeographicalUnitRepositoryInterface
|
||||
{
|
||||
return GeographicalUnit::class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
interface GeographicalUnitRepositoryInterface extends ObjectRepository
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ use Chill\MainBundle\Entity\Scope;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final class ScopeRepository implements ScopeRepositoryInterface
|
||||
{
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
@@ -18,6 +27,9 @@ interface ScopeRepositoryInterface extends ObjectRepository
|
||||
public function findAll(): array;
|
||||
|
||||
/**
|
||||
* @param null|mixed $limit
|
||||
* @param null|mixed $offset
|
||||
*
|
||||
* @return Scope[]
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array;
|
||||
@@ -25,4 +37,4 @@ interface ScopeRepositoryInterface extends ObjectRepository
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?Scope;
|
||||
|
||||
public function getClassName(): string;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
|
||||
|
@@ -16,6 +16,7 @@ use Doctrine\DBAL\Statement;
|
||||
use Exception;
|
||||
use LogicException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
@@ -159,8 +160,8 @@ final class AddressReferenceBaseImporter
|
||||
try {
|
||||
$affected = $statement->executeStatement(array_merge(...$this->waitingForInsert));
|
||||
|
||||
if ($affected === 0) {
|
||||
throw new \RuntimeException('no row affected');
|
||||
if (0 === $affected) {
|
||||
throw new RuntimeException('no row affected');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// in some case, we can add debug code here
|
||||
|
@@ -13,11 +13,10 @@ namespace Chill\MainBundle\Service\Import;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Statement;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Exception;
|
||||
use LogicException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
@@ -77,7 +76,7 @@ final class GeographicalUnitBaseImporter
|
||||
string $unitName,
|
||||
string $unitKey,
|
||||
string $geomAsWKT,
|
||||
int $srid = null
|
||||
?int $srid = null
|
||||
): void {
|
||||
$this->initialize();
|
||||
|
||||
@@ -87,7 +86,7 @@ final class GeographicalUnitBaseImporter
|
||||
'unitName' => $unitName,
|
||||
'unitKey' => $unitKey,
|
||||
'geomAsWKT' => $geomAsWKT,
|
||||
'srid' => $srid
|
||||
'srid' => $srid,
|
||||
];
|
||||
|
||||
if (100 <= count($this->waitingForInsert)) {
|
||||
@@ -138,8 +137,10 @@ final class GeographicalUnitBaseImporter
|
||||
}
|
||||
|
||||
$statement = $this->cachingStatements[$forNumber];
|
||||
|
||||
try {
|
||||
$i = 0;
|
||||
|
||||
foreach ($this->waitingForInsert as $insert) {
|
||||
$statement->bindValue(++$i, $insert['layerKey'], Types::STRING);
|
||||
$statement->bindValue(++$i, $insert['layerName'], Types::JSON);
|
||||
@@ -151,8 +152,8 @@ final class GeographicalUnitBaseImporter
|
||||
|
||||
$affected = $statement->executeStatement();
|
||||
|
||||
if ($affected === 0) {
|
||||
throw new \RuntimeException('no row affected');
|
||||
if (0 === $affected) {
|
||||
throw new RuntimeException('no row affected');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
@@ -182,10 +183,10 @@ final class GeographicalUnitBaseImporter
|
||||
private function updateGeographicalUnitTable(): void
|
||||
{
|
||||
$this->defaultConnection->transactional(
|
||||
function() {
|
||||
function () {
|
||||
// 0) create new layers
|
||||
$this->defaultConnection->executeStatement(
|
||||
"
|
||||
"
|
||||
WITH unique_layers AS (
|
||||
SELECT DISTINCT layerKey, layerName FROM geographical_unit_temp
|
||||
)
|
||||
@@ -195,14 +196,15 @@ final class GeographicalUnitBaseImporter
|
||||
layerName,
|
||||
layerKey
|
||||
FROM unique_layers
|
||||
ON CONFLICT (refid)
|
||||
ON CONFLICT (refid)
|
||||
DO UPDATE SET name=EXCLUDED.name
|
||||
");
|
||||
"
|
||||
);
|
||||
|
||||
//1) Add new units
|
||||
$this->logger->info(self::LOG_PREFIX . 'upsert new units');
|
||||
$affected = $this->defaultConnection->executeStatement("INSERT INTO chill_main_geographical_unit
|
||||
(id, geom, unitname, layer_id, unitrefid)
|
||||
$affected = $this->defaultConnection->executeStatement("INSERT INTO chill_main_geographical_unit
|
||||
(id, geom, unitname, layer_id, unitrefid)
|
||||
SELECT
|
||||
nextval('chill_main_geographical_unit_id_seq'),
|
||||
geom,
|
||||
@@ -210,7 +212,7 @@ final class GeographicalUnitBaseImporter
|
||||
layer.id,
|
||||
unitKey
|
||||
FROM geographical_unit_temp JOIN chill_main_geographical_unit_layer AS layer ON layer.refid = layerKey
|
||||
ON CONFLICT (layer_id, unitrefid)
|
||||
ON CONFLICT (layer_id, unitrefid)
|
||||
DO UPDATE
|
||||
SET geom = EXCLUDED.geom, unitname = EXCLUDED.unitname
|
||||
");
|
||||
@@ -219,9 +221,9 @@ final class GeographicalUnitBaseImporter
|
||||
//3) Delete units
|
||||
$this->logger->info(self::LOG_PREFIX . 'soft delete adresses');
|
||||
$affected = $this->defaultConnection->executeStatement('WITH to_delete AS (
|
||||
SELECT cmgu.id
|
||||
SELECT cmgu.id
|
||||
FROM chill_main_geographical_unit AS cmgu
|
||||
JOIN chill_main_geographical_unit_layer AS cmgul ON cmgul.id = cmgu.layer_id
|
||||
JOIN chill_main_geographical_unit_layer AS cmgul ON cmgul.id = cmgu.layer_id
|
||||
JOIN geographical_unit_temp AS gut ON cmgul.refid = gut.layerKey AND cmgu.unitrefid = gut.unitKey
|
||||
)
|
||||
DELETE FROM chill_main_geographical_unit
|
||||
|
@@ -25,6 +25,7 @@ use function is_string;
|
||||
/**
|
||||
* Helper which creates a set of test for aggregators.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
{
|
||||
|
@@ -24,6 +24,7 @@ use function is_string;
|
||||
/**
|
||||
* Helper to test filters.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
abstract class AbstractFilterTest extends KernelTestCase
|
||||
{
|
||||
|
@@ -18,6 +18,7 @@ namespace Chill\MainBundle\Test;
|
||||
* and use tearDownTrait after usage.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @deprecated use @class{Prophecy\PhpUnit\ProphecyTrait} instead
|
||||
*/
|
||||
trait ProphecyTrait
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Services\Import;
|
||||
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
@@ -9,11 +18,18 @@ use Chill\MainBundle\Service\Import\AddressReferenceBaseImporter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class AddressReferenceBaseImporterTest extends KernelTestCase
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AddressReferenceBaseImporterTest extends KernelTestCase
|
||||
{
|
||||
private AddressReferenceBaseImporter $importer;
|
||||
private AddressReferenceRepository $addressReferenceRepository;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private AddressReferenceBaseImporter $importer;
|
||||
|
||||
private PostalCodeRepository $postalCodeRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -30,7 +46,7 @@ class AddressReferenceBaseImporterTest extends KernelTestCase
|
||||
public function testImportAddress(): void
|
||||
{
|
||||
$postalCode = (new PostalCode())
|
||||
->setRefPostalCodeId($postalCodeId = '1234'.uniqid())
|
||||
->setRefPostalCodeId($postalCodeId = '1234' . uniqid())
|
||||
->setPostalCodeSource('testing')
|
||||
->setCode('TEST456')
|
||||
->setName('testing');
|
||||
@@ -54,7 +70,8 @@ class AddressReferenceBaseImporterTest extends KernelTestCase
|
||||
|
||||
$addresses = $this->addressReferenceRepository->findByPostalCodePattern(
|
||||
$postalCode,
|
||||
'Rue test abcc guessed');
|
||||
'Rue test abcc guessed'
|
||||
);
|
||||
|
||||
$this->assertCount(1, $addresses);
|
||||
$this->assertEquals('Rue test abccc-guessed', $addresses[0]->getStreet());
|
||||
@@ -79,12 +96,11 @@ class AddressReferenceBaseImporterTest extends KernelTestCase
|
||||
|
||||
$addresses = $this->addressReferenceRepository->findByPostalCodePattern(
|
||||
$postalCode,
|
||||
'abcc guessed fixed');
|
||||
'abcc guessed fixed'
|
||||
);
|
||||
|
||||
$this->assertCount('1', $addresses);
|
||||
$this->assertEquals( 'Rue test abccc guessed fixed', $addresses[0]->getStreet());
|
||||
$this->assertEquals('Rue test abccc guessed fixed', $addresses[0]->getStreet());
|
||||
$this->assertEquals($previousAddressId, $addresses[0]->getId());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Services\Import;
|
||||
|
||||
use Chill\MainBundle\Service\Import\GeographicalUnitBaseImporter;
|
||||
@@ -8,7 +17,11 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class GeographicalUnitBaseImporterTest extends KernelTestCase
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class GeographicalUnitBaseImporterTest extends KernelTestCase
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
@@ -42,10 +55,10 @@ class GeographicalUnitBaseImporterTest extends KernelTestCase
|
||||
|
||||
$importer->finalize();
|
||||
|
||||
$unit = $this->connection->executeQuery("
|
||||
$unit = $this->connection->executeQuery('
|
||||
SELECT unitname, unitrefid, cmgul.refid AS layerrefid, cmgul.name AS layername, ST_AsText(ST_snapToGrid(ST_Transform(u.geom, 3812), 1)) AS geom
|
||||
FROM chill_main_geographical_unit u JOIN chill_main_geographical_unit_layer cmgul on u.layer_id = cmgul.id
|
||||
WHERE u.unitrefid = ?", ['layer_one']);
|
||||
FROM chill_main_geographical_unit u JOIN chill_main_geographical_unit_layer cmgul on u.layer_id = cmgul.id
|
||||
WHERE u.unitrefid = ?', ['layer_one']);
|
||||
|
||||
$results = $unit->fetchAssociative();
|
||||
|
||||
@@ -71,10 +84,10 @@ class GeographicalUnitBaseImporterTest extends KernelTestCase
|
||||
|
||||
$importer->finalize();
|
||||
|
||||
$unit = $this->connection->executeQuery("
|
||||
$unit = $this->connection->executeQuery('
|
||||
SELECT unitname, unitrefid, cmgul.refid AS layerrefid, cmgul.name AS layername, ST_AsText(ST_snapToGrid(ST_Transform(u.geom, 3812), 1)) AS geom
|
||||
FROM chill_main_geographical_unit u JOIN chill_main_geographical_unit_layer cmgul on u.layer_id = cmgul.id
|
||||
WHERE u.unitrefid = ?", ['layer_one']);
|
||||
FROM chill_main_geographical_unit u JOIN chill_main_geographical_unit_layer cmgul on u.layer_id = cmgul.id
|
||||
WHERE u.unitrefid = ?', ['layer_one']);
|
||||
|
||||
$results = $unit->fetchAssociative();
|
||||
|
||||
@@ -83,7 +96,5 @@ class GeographicalUnitBaseImporterTest extends KernelTestCase
|
||||
$this->assertEquals(json_decode($results['layername'], true), ['fr' => 'Test Layer fixed']);
|
||||
$this->assertEquals($results['layerrefid'], 'test');
|
||||
$this->assertEquals($results['geom'], 'MULTIPOLYGON(((130 120,45 40,10 40,130 120)),((0 0,15 5,40 10,10 20,0 0)))');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Services\Import;
|
||||
|
||||
use Chill\MainBundle\Repository\CountryRepository;
|
||||
@@ -8,16 +17,20 @@ use Chill\MainBundle\Service\Import\PostalCodeBaseImporter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class PostalCodeBaseImporterTest extends KernelTestCase
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PostalCodeBaseImporterTest extends KernelTestCase
|
||||
{
|
||||
private CountryRepository $countryRepository;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private PostalCodeBaseImporter $importer;
|
||||
|
||||
private PostalCodeRepository $postalCodeRepository;
|
||||
|
||||
private CountryRepository $countryRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -34,9 +47,9 @@ class PostalCodeBaseImporterTest extends KernelTestCase
|
||||
{
|
||||
$this->importer->importCode(
|
||||
'BE',
|
||||
'tested with pattern '. ($uniqid = uniqid()),
|
||||
'tested with pattern ' . ($uniqid = uniqid()),
|
||||
'12345',
|
||||
$refPostalCodeId = 'test'.uniqid(),
|
||||
$refPostalCodeId = 'test' . uniqid(),
|
||||
'test',
|
||||
50.0,
|
||||
5.0,
|
||||
@@ -46,8 +59,8 @@ class PostalCodeBaseImporterTest extends KernelTestCase
|
||||
$this->importer->finalize();
|
||||
|
||||
$postalCodes = $this->postalCodeRepository->findByPattern(
|
||||
'with pattern '.$uniqid,
|
||||
$this->countryRepository->findOneBy(['countryCode' => 'BE'])
|
||||
'with pattern ' . $uniqid,
|
||||
$this->countryRepository->findOneBy(['countryCode' => 'BE'])
|
||||
);
|
||||
|
||||
$this->assertCount(1, $postalCodes);
|
||||
@@ -59,7 +72,7 @@ class PostalCodeBaseImporterTest extends KernelTestCase
|
||||
|
||||
$this->importer->importCode(
|
||||
'BE',
|
||||
'tested with adapted pattern '. ($uniqid = uniqid()),
|
||||
'tested with adapted pattern ' . ($uniqid = uniqid()),
|
||||
'12345',
|
||||
$refPostalCodeId,
|
||||
'test',
|
||||
@@ -71,7 +84,7 @@ class PostalCodeBaseImporterTest extends KernelTestCase
|
||||
$this->importer->finalize();
|
||||
|
||||
$postalCodes = $this->postalCodeRepository->findByPattern(
|
||||
'with pattern '.$uniqid,
|
||||
'with pattern ' . $uniqid,
|
||||
$this->countryRepository->findOneBy(['countryCode' => 'BE'])
|
||||
);
|
||||
|
||||
@@ -79,7 +92,4 @@ class PostalCodeBaseImporterTest extends KernelTestCase
|
||||
$this->assertStringStartsWith('tested with adapted pattern', $postalCodes[0]->getName());
|
||||
$this->assertEquals($previousId, $postalCodes[0]->getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Tests\Workflow\EventSubscriber;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
@@ -14,16 +23,22 @@ use Prophecy\Argument;
|
||||
use Prophecy\Call\Call;
|
||||
use Prophecy\Exception\Prediction\FailedPredictionException;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use ReflectionClass;
|
||||
use stdClass;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Component\Workflow\Event\Event;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Workflow\Transition;
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
use Symfony\Component\Workflow\WorkflowInterface;
|
||||
use function count;
|
||||
|
||||
class NotificationOnTransitionTest extends TestCase
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class NotificationOnTransitionTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
@@ -36,11 +51,10 @@ class NotificationOnTransitionTest extends TestCase
|
||||
$entityWorkflow = new EntityWorkflow();
|
||||
$entityWorkflow
|
||||
->setWorkflowName('workflow_name')
|
||||
->setRelatedEntityClass(\stdClass::class)
|
||||
->setRelatedEntityId(1)
|
||||
;
|
||||
->setRelatedEntityClass(stdClass::class)
|
||||
->setRelatedEntityId(1);
|
||||
// force an id to entityWorkflow:
|
||||
$reflection = new \ReflectionClass($entityWorkflow);
|
||||
$reflection = new ReflectionClass($entityWorkflow);
|
||||
$id = $reflection->getProperty('id');
|
||||
$id->setAccessible(true);
|
||||
$id->setValue($entityWorkflow, 1);
|
||||
@@ -48,12 +62,11 @@ class NotificationOnTransitionTest extends TestCase
|
||||
$step = new EntityWorkflowStep();
|
||||
$entityWorkflow->addStep($step);
|
||||
$step->addDestUser($dest)
|
||||
->setCurrentStep('to_state')
|
||||
;
|
||||
->setCurrentStep('to_state');
|
||||
|
||||
$em = $this->prophesize(EntityManagerInterface::class);
|
||||
$em->persist(Argument::type(Notification::class))->should(
|
||||
function($args) use ($dest) {
|
||||
static function ($args) use ($dest) {
|
||||
/** @var Call[] $args */
|
||||
if (1 !== count($args)) {
|
||||
throw new FailedPredictionException('no notification sent');
|
||||
@@ -68,7 +81,8 @@ class NotificationOnTransitionTest extends TestCase
|
||||
if (!$notification->getAddressees()->contains($dest)) {
|
||||
throw new FailedPredictionException('the dest is not notified');
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
$engine = $this->prophesize(EngineInterface::class);
|
||||
$engine->render(Argument::type('string'), Argument::type('array'))
|
||||
|
@@ -41,6 +41,24 @@ class EntityWorkflowTransitionEventSubscriber implements EventSubscriberInterfac
|
||||
$this->userRender = $userRender;
|
||||
}
|
||||
|
||||
public function addDests(Event $event): void
|
||||
{
|
||||
if (!$event->getSubject() instanceof EntityWorkflow) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var EntityWorkflow $entityWorkflow */
|
||||
$entityWorkflow = $event->getSubject();
|
||||
|
||||
foreach ($entityWorkflow->futureDestUsers as $user) {
|
||||
$entityWorkflow->getCurrentStep()->addDestUser($user);
|
||||
}
|
||||
|
||||
foreach ($entityWorkflow->futureDestEmails as $email) {
|
||||
$entityWorkflow->getCurrentStep()->addDestEmail($email);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
@@ -55,23 +73,6 @@ class EntityWorkflowTransitionEventSubscriber implements EventSubscriberInterfac
|
||||
];
|
||||
}
|
||||
|
||||
public function addDests(Event $event): void
|
||||
{
|
||||
if (!$event->getSubject() instanceof EntityWorkflow) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var EntityWorkflow $entityWorkflow */
|
||||
$entityWorkflow = $event->getSubject();
|
||||
foreach ($entityWorkflow->futureDestUsers as $user) {
|
||||
$entityWorkflow->getCurrentStep()->addDestUser($user);
|
||||
}
|
||||
|
||||
foreach ($entityWorkflow->futureDestEmails as $email) {
|
||||
$entityWorkflow->getCurrentStep()->addDestEmail($email);
|
||||
}
|
||||
}
|
||||
|
||||
public function guardEntityWorkflow(GuardEvent $event)
|
||||
{
|
||||
if (!$event->getSubject() instanceof EntityWorkflow) {
|
||||
|
@@ -57,14 +57,15 @@ class NotificationOnTransition implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a notification to:
|
||||
* Send a notification to:.
|
||||
*
|
||||
* * the dests of the new step;
|
||||
* * the users which subscribed to workflow, on each step, or on final
|
||||
*
|
||||
* **Warning** take care that this method must be executed **after** the dest users are added to
|
||||
* the step (@link{EntityWorkflowStep::addDestUser}). Currently, this is done during
|
||||
* @link{EntityWorkflowTransitionEventSubscriber::addDests}.
|
||||
* the step (@see{EntityWorkflowStep::addDestUser}). Currently, this is done during
|
||||
*
|
||||
* @see{EntityWorkflowTransitionEventSubscriber::addDests}.
|
||||
*/
|
||||
public function onCompletedSendNotification(Event $event): void
|
||||
{
|
||||
@@ -77,6 +78,7 @@ class NotificationOnTransition implements EventSubscriberInterface
|
||||
|
||||
/** @var array<string, User> $dests array of unique values, where keys is the object's hash */
|
||||
$dests = [];
|
||||
|
||||
foreach (array_merge(
|
||||
// the subscriber to each step
|
||||
$entityWorkflow->getSubscriberToStep()->toArray(),
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
@@ -9,6 +16,11 @@ use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20220730204216 extends AbstractMigration
|
||||
{
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX chill_main_address_reference_unicity');
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add an unique constraint on addresses references';
|
||||
@@ -18,9 +30,4 @@ final class Version20220730204216 extends AbstractMigration
|
||||
{
|
||||
$this->addSql('CREATE UNIQUE INDEX chill_main_address_reference_unicity ON chill_main_address_reference (refId, source)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX chill_main_address_reference_unicity');
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
@@ -12,6 +19,11 @@ use Doctrine\Migrations\AbstractMigration;
|
||||
*/
|
||||
final class Version20220913174922 extends AbstractMigration
|
||||
{
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER COLUMN geom SET DATA TYPE TEXT');
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Geographical Unit correction';
|
||||
@@ -21,9 +33,4 @@ final class Version20220913174922 extends AbstractMigration
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER COLUMN geom SET DATA TYPE GEOMETRY(MULTIPOLYGON, 4326)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER COLUMN geom SET DATA TYPE TEXT');
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
@@ -9,35 +16,6 @@ use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20221003112151 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add a proper entity for GeographicalUnitLayer';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE SEQUENCE chill_main_geographical_unit_layer_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE TABLE chill_main_geographical_unit_layer (id INT NOT NULL, name JSONB DEFAULT \'[]\'::jsonb NOT NULL, refid TEXT DEFAULT \'\' NOT NULL, PRIMARY KEY(id))');
|
||||
$this->addSql("COMMENT ON COLUMN chill_main_geographical_unit_layer.name IS '(DC2Type:json)';");
|
||||
|
||||
$this->addSql('INSERT INTO chill_main_geographical_unit_layer (id, name, refid)
|
||||
SELECT DISTINCT nextval(\'chill_main_geographical_unit_layer_id_seq\'), jsonb_build_object(\'fr\', layername), layername FROM chill_main_geographical_unit');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD layer_id INT DEFAULT NULL');
|
||||
|
||||
$this->addSql('UPDATE chill_main_geographical_unit SET layer_id = layer.id FROM chill_main_geographical_unit_layer AS layer WHERE layer.refid = chill_main_geographical_unit.layername');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD unitRefId TEXT DEFAULT \'\' NOT NULL');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit DROP layername');
|
||||
$this->addSql("COMMENT ON COLUMN chill_main_geographical_unit.geom IS '(DC2Type:text)';");
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitname TYPE TEXT');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitname SET DEFAULT \'\'');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitname SET NOT NULL');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD CONSTRAINT FK_360A2B2FEA6EFDCD FOREIGN KEY (layer_id) REFERENCES chill_main_geographical_unit_layer (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('CREATE INDEX IDX_360A2B2FEA6EFDCD ON chill_main_geographical_unit (layer_id)');
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->throwIrreversibleMigrationException();
|
||||
@@ -53,6 +31,34 @@ final class Version20221003112151 extends AbstractMigration
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName TYPE VARCHAR(255)');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName DROP DEFAULT');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName DROP NOT NULL');
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add a proper entity for GeographicalUnitLayer';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE SEQUENCE chill_main_geographical_unit_layer_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE TABLE chill_main_geographical_unit_layer (id INT NOT NULL, name JSONB DEFAULT \'[]\'::jsonb NOT NULL, refid TEXT DEFAULT \'\' NOT NULL, PRIMARY KEY(id))');
|
||||
$this->addSql("COMMENT ON COLUMN chill_main_geographical_unit_layer.name IS '(DC2Type:json)';");
|
||||
|
||||
$this->addSql('INSERT INTO chill_main_geographical_unit_layer (id, name, refid)
|
||||
SELECT DISTINCT nextval(\'chill_main_geographical_unit_layer_id_seq\'), jsonb_build_object(\'fr\', layername), layername FROM chill_main_geographical_unit');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD layer_id INT DEFAULT NULL');
|
||||
|
||||
$this->addSql('UPDATE chill_main_geographical_unit SET layer_id = layer.id FROM chill_main_geographical_unit_layer AS layer WHERE layer.refid = chill_main_geographical_unit.layername');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD unitRefId TEXT DEFAULT \'\' NOT NULL');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit DROP layername');
|
||||
$this->addSql("COMMENT ON COLUMN chill_main_geographical_unit.geom IS '(DC2Type:text)';");
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitname TYPE TEXT');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitname SET DEFAULT \'\'');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitname SET NOT NULL');
|
||||
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD CONSTRAINT FK_360A2B2FEA6EFDCD FOREIGN KEY (layer_id) REFERENCES chill_main_geographical_unit_layer (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('CREATE INDEX IDX_360A2B2FEA6EFDCD ON chill_main_geographical_unit (layer_id)');
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
@@ -9,6 +16,13 @@ use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20221003132620 extends AbstractMigration
|
||||
{
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX geographical_unit_layer_refid');
|
||||
$this->addSql('DROP INDEX geographical_unit_refid');
|
||||
$this->addSql('DROP INDEX chill_internal_geographical_unit_layer_geom_idx');
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Create indexes and unique constraints on geographical unit entities';
|
||||
@@ -20,11 +34,4 @@ final class Version20221003132620 extends AbstractMigration
|
||||
$this->addSql('CREATE UNIQUE INDEX geographical_unit_refid ON chill_main_geographical_unit (layer_id, unitRefId)');
|
||||
$this->addSql('CREATE INDEX chill_internal_geographical_unit_layer_geom_idx ON chill_main_geographical_unit USING GIST (layer_id, geom)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX geographical_unit_layer_refid');
|
||||
$this->addSql('DROP INDEX geographical_unit_refid');
|
||||
$this->addSql('DROP INDEX chill_internal_geographical_unit_layer_geom_idx');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user