mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-11-04 03:08:25 +00:00 
			
		
		
		
	Fixed: take layer into account for unicity of geographical unit's keys
This commit is contained in:
		@@ -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={"unitRefId"})
 | 
			
		||||
 *      @ORM\UniqueConstraint(name="geographical_unit_refid", columns={"layer_id", "unitRefId"})
 | 
			
		||||
 * })
 | 
			
		||||
 * @ORM\Entity(readOnly=true)
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
@@ -137,11 +137,6 @@ final class GeographicalUnitBaseImporter
 | 
			
		||||
            $this->cachingStatements[$forNumber] = $this->defaultConnection->prepare($sql);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->logger->debug(self::LOG_PREFIX . ' inserting pending addresses', [
 | 
			
		||||
            'number' => $forNumber,
 | 
			
		||||
            'first' => $this->waitingForInsert[0] ?? null,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $statement = $this->cachingStatements[$forNumber];
 | 
			
		||||
        try {
 | 
			
		||||
            $i = 0;
 | 
			
		||||
@@ -215,7 +210,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 (unitrefid) 
 | 
			
		||||
            ON CONFLICT (layer_id, unitrefid) 
 | 
			
		||||
            DO UPDATE
 | 
			
		||||
            SET geom = EXCLUDED.geom, unitname = EXCLUDED.unitname
 | 
			
		||||
        ");
 | 
			
		||||
@@ -223,10 +218,15 @@ final class GeographicalUnitBaseImporter
 | 
			
		||||
 | 
			
		||||
                //3) Delete units
 | 
			
		||||
                $this->logger->info(self::LOG_PREFIX . 'soft delete adresses');
 | 
			
		||||
                $affected = $this->defaultConnection->executeStatement('DELETE FROM chill_main_geographical_unit
 | 
			
		||||
            WHERE
 | 
			
		||||
                unitrefid NOT IN (SELECT distinct unitKey FROM geographical_unit_temp)
 | 
			
		||||
        ');
 | 
			
		||||
                $affected = $this->defaultConnection->executeStatement('WITH to_delete AS (
 | 
			
		||||
                    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 geographical_unit_temp AS gut ON cmgul.refid = gut.layerKey AND cmgu.unitrefid = gut.unitKey
 | 
			
		||||
                )
 | 
			
		||||
                DELETE FROM chill_main_geographical_unit
 | 
			
		||||
                WHERE id NOT IN (SELECT id FROM to_delete)
 | 
			
		||||
                ');
 | 
			
		||||
                $this->logger->info(self::LOG_PREFIX . 'addresses deleted', ['deleted' => $affected]);
 | 
			
		||||
            }
 | 
			
		||||
        );
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,8 @@ final class Version20221003132620 extends AbstractMigration
 | 
			
		||||
    public function up(Schema $schema): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->addSql('CREATE UNIQUE INDEX geographical_unit_layer_refid ON chill_main_geographical_unit_layer (refId)');
 | 
			
		||||
        $this->addSql('CREATE UNIQUE INDEX geographical_unit_refid ON chill_main_geographical_unit (unitRefId)');
 | 
			
		||||
        $this->addSql('CREATE INDEX chill_internal_geographical_unit_layer_geom_idx ON chill_main_geographical_unit USING GIST (geom)');
 | 
			
		||||
        $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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user