commande pour enlever les duplications de Places

This commit is contained in:
Tykayn 2025-08-02 15:14:13 +02:00 committed by tykayn
parent 37fd162824
commit eee5d6349a
4 changed files with 217 additions and 6 deletions

View file

@ -0,0 +1,68 @@
# Changes Implemented on 2025-08-02
## Issue Description
1. Create a command to remove duplicate Places, keeping only one. Sort places by OSM object type and OSM ID, and delete if the same information is found twice in a row.
2. When processing a city ("labourage"), use the city name found in the API that links INSEE code to city name to define the city name if it's different. Also use this for the command that creates Stats objects from Requests, not the place name from the request.
## Changes Made
### 1. New Command to Remove Duplicate Places
Created a new command `app:remove-duplicate-places` that:
- Gets all places sorted by OSM type and ID
- Finds duplicates by comparing consecutive places
- Removes the duplicates, keeping the first occurrence
The command supports:
- `--dry-run` option to show duplicates without removing them
- `--zip-code` option to process only places with a specific ZIP code
Usage:
```bash
# Show duplicates without removing them
php bin/console app:remove-duplicate-places --dry-run
# Remove duplicates for a specific ZIP code
php bin/console app:remove-duplicate-places --zip-code=75001
# Remove all duplicates
php bin/console app:remove-duplicate-places
```
### 2. City Name Updates from API
#### During Labourage Process
Modified `ProcessLabourageQueueCommand` to update the city name from the API after labourage:
- After setting the labourage completion date, it gets the city name from the API using the `get_city_osm_from_zip_code` method
- If the API returns a city name and it's different from the current name, it updates the Stats entity with the new name
- It logs the name change for information
#### When Creating Stats from Requests
Modified `CreateStatsFromDemandesCommand` to use the API-provided city name:
- It now tries to get the city name from the API based on the INSEE code
- If the API returns a city name, it uses that for the Stats object
- If the API doesn't return a name, it falls back to using the query from the first Demande (the previous behavior)
- It logs which source was used for the city name
## Testing
To test these changes:
1. Test the duplicate removal command:
```bash
php bin/console app:remove-duplicate-places --dry-run
```
2. Test the city name updates during labourage:
```bash
php bin/console app:process-labourage-queue
```
3. Test the Stats creation from Requests:
```bash
php bin/console app:create-stats-from-demandes
```