Skip to content

Commit 7f74b0f

Browse files
authored
Merge pull request #364 from zigzagdev/feat/study_region-infra
Feat/study region infra
2 parents ab5b6c9 + 2e4344c commit 7f74b0f

17 files changed

+810
-296
lines changed

docker-compose.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
version: '3.8'
2+
23
services:
34
app:
45
build:
56
context: .
67
dockerfile: ./environment/local/docker/Dockerfile
78
image: wha-api:local
9+
container_name: heritage-app
810
ports:
911
- "8700:8080"
1012
environment:
@@ -14,10 +16,9 @@ services:
1416
working_dir: /var/www
1517
volumes:
1618
- ./src:/var/www
17-
- vendor_data:/var/www/vendor
18-
- cache_data:/var/www/bootstrap/cache
19-
- composer_cache:/var/www/.composer
20-
networks: [ heritage-net ]
19+
command: tail -f /dev/null
20+
networks:
21+
- heritage-net
2122

2223
mysql:
2324
image: mysql:8.0
@@ -32,7 +33,21 @@ services:
3233
volumes:
3334
- db_data:/var/lib/mysql
3435
- ./environment/mysql-init:/docker-entrypoint-initdb.d:ro
35-
networks: [ heritage-net ]
36+
networks:
37+
- heritage-net
38+
39+
mysql_test:
40+
image: mysql:8.0
41+
container_name: heritage-mysql-test
42+
environment:
43+
MYSQL_ROOT_PASSWORD: world-heritage
44+
MYSQL_USER: world-heritage
45+
MYSQL_PASSWORD: world-heritage
46+
MYSQL_DATABASE: world_heritage_test
47+
ports:
48+
- "2307:3306"
49+
networks:
50+
- heritage-net
3651

3752
phpmyadmin:
3853
image: phpmyadmin/phpmyadmin:latest
@@ -44,14 +59,13 @@ services:
4459
PMA_PASSWORD: world-heritage
4560
ports:
4661
- "127.0.0.1:8081:80"
47-
depends_on: [ mysql ]
48-
networks: [ heritage-net ]
62+
depends_on:
63+
- mysql
64+
networks:
65+
- heritage-net
4966

5067
networks:
5168
heritage-net:
5269

5370
volumes:
54-
db_data:
55-
vendor_data:
56-
cache_data:
57-
composer_cache:
71+
db_data:

src/app/Console/Commands/AlgoliaImportWorldHeritages.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Algolia\AlgoliaSearch\Api\SearchClient;
66
use App\Models\WorldHeritage;
77
use Illuminate\Console\Command;
8+
use App\Support\StudyRegionResolver;
89

910
class AlgoliaImportWorldHeritages extends Command
1011
{
@@ -100,6 +101,21 @@ public function handle(): int
100101
$countryNameJp = $countryNamesJp[0] ?? null;
101102
}
102103

104+
$resolvedStudyRegions = StudyRegionResolver::resolveManyFromRecord(
105+
siteId: (int) $row->id,
106+
country: $country,
107+
statePartyCodes: $statePartyCodes,
108+
);
109+
110+
$studyRegions = array_map(
111+
static fn ($region) => $region->value,
112+
$resolvedStudyRegions
113+
);
114+
115+
$primaryStudyRegion = count($studyRegions) === 1
116+
? $studyRegions[0]
117+
: null;
118+
103119
$objects[] = [
104120
'objectID' => (string) $row->id,
105121
'id' => (int) $row->id,
@@ -109,12 +125,13 @@ public function handle(): int
109125
'country' => $country,
110126
'country_name_jp' => $countryNameJp,
111127
'region' => (string) $row->region,
112-
'study_region' => (string) $row->study_region,
128+
'study_region' => $primaryStudyRegion,
129+
'study_regions' => $studyRegions,
113130
'category' => (string) $row->category,
114131
'year_inscribed' => $row->year_inscribed !== null ? (int) $row->year_inscribed : null,
115132
'is_endangered' => (bool) $row->is_endangered,
116133
'thumbnail_url' => $row->image_url !== null ? (string) $row->image_url : null,
117-
'state_party_codes' => $countryCount > 1 ? $statePartyCodes : [],
134+
'state_party_codes' => $statePartyCodes,
118135
'country_names_jp' => $countryCount > 1 ? $countryNamesJp : [],
119136
];
120137
}
@@ -127,6 +144,7 @@ public function handle(): int
127144
$processed += count($objects);
128145
return;
129146
}
147+
130148
if ((int) $row->id === 1133) {
131149
dd([
132150
'state_party_codes' => $statePartyCodes,

src/app/Console/Commands/DumpUnescoWorldHeritageJson.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,14 +456,12 @@ private function normalizeRow(array $row): array
456456
'name_ru' => $row['name_ru'] ?? null,
457457
'name_ar' => $row['name_ar'] ?? null,
458458
'name_zh' => $row['name_zh'] ?? null,
459-
460459
'short_description_en' => $row['short_description_en'] ?? null,
461460
'short_description_fr' => $row['short_description_fr'] ?? null,
462461
'short_description_es' => $row['short_description_es'] ?? null,
463462
'short_description_ru' => $row['short_description_ru'] ?? null,
464463
'short_description_ar' => $row['short_description_ar'] ?? null,
465464
'short_description_zh' => $row['short_description_zh'] ?? null,
466-
467465
'description_en' => $row['description_en'] ?? null,
468466
'justification_en' => $row['justification_en'] ?? null,
469467
'criteria' => $row['criteria_txt'] ?? null,
@@ -473,19 +471,15 @@ private function normalizeRow(array $row): array
473471
'date_end' => $row['date_end'] ?? null,
474472
'danger_list' => $row['danger_list'] ?? null,
475473
'area_hectares' => $toFloat($row['area_hectares'] ?? null),
476-
477474
'category' => $row['category'] ?? null,
478475
'category_id' => $toInt($row['category_id'] ?? null),
479-
480476
'states_names' => is_array($row['states_names'] ?? null) ? $row['states_names'] : [],
481477
'iso_codes' => $row['iso_codes'] ?? null,
482478
'region' => $row['region'] ?? null,
483479
'region_code' => $row['region_code'] ?? null,
484480
'transboundary' => $toBool($row['transboundary'] ?? null),
485-
486-
'image_url' => $row['image_url'] ?? null,
481+
'image_url' => $row['main_image_url'] ?? null,
487482
'images_urls' => $images,
488-
489483
'uuid' => $row['uuid'] ?? null,
490484
'id_no' => $row['id_no'] ?? null,
491485
'coordinates' => $row['coordinates'] ?? null,

src/app/Console/Commands/ImportWorldHeritageFromJson.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private function mapFromUnescoApiRow(array $row): array
144144
'name' => $row['name_en'] ?? $row['name'] ?? null,
145145
'region' => $row['region_en'] ?? $row['region'] ?? null,
146146
'state_party' => $statePartyIso3,
147-
'study_region' => StudyRegionResolver::resolve($countryName)->value,
147+
'study_region' => StudyRegionResolver::resolveFromCountry($countryName)->value,
148148
'category' => $row['category'] ?? $row['type'] ?? null,
149149
'criteria' => $row['criteria'] ?? null,
150150
'year_inscribed' => $this->toNullableInt($row['date_inscribed'] ?? $row['year_inscribed'] ?? null),

src/app/Console/Commands/SplitWorldHeritageJson.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ private function normalizeSiteRowImportReady(array $row, int $siteId): array
722722
'name' => $this->stringOrFallback($row['name_en'] ?? null, (string) $siteId),
723723
'name_jp' => $this->stringOrNull($row['name_jp'] ?? null),
724724
'study_region' => $countryName
725-
? StudyRegionResolver::resolve($countryName)->value
725+
? StudyRegionResolver::resolveFromCountry($countryName)->value
726726
: null,
727727
'country' => $country,
728728
'region' => $region,
@@ -735,8 +735,8 @@ private function normalizeSiteRowImportReady(array $row, int $siteId): array
735735
'latitude' => isset($lat) ? (is_numeric($lat) ? (float) $lat : null) : null,
736736
'longitude' => isset($lon) ? (is_numeric($lon) ? (float) $lon : null) : null,
737737
'short_description' => $this->stringOrNull($row['short_description_en'] ?? null),
738-
'image_url' => null,
739-
'primary_image_url' => null,
738+
'image_url' => $this->stringOrNull($row['image_url'] ?? null),
739+
'primary_image_url' => $this->stringOrNull($row['image_url'] ?? null),
740740
'unesco_site_url' => $this->stringOrNull($row['unesco_site_url'] ?? ($row['url'] ?? null)),
741741
];
742742
}
@@ -748,7 +748,7 @@ private function mergeSiteRowPreferExisting(array $existing, array $incoming): a
748748
$countryName = $stateNames[0] ?? null;
749749

750750
if ($countryName) {
751-
$existing['study_region'] = StudyRegionResolver::resolve($countryName)->value;
751+
$existing['study_region'] = StudyRegionResolver::resolveFromCountry($countryName)->value;
752752
}
753753
}
754754

src/app/Packages/Domains/Adapter/AlgoliaWorldHeritageSearchAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function search(
6060
* Region filter (exact match).
6161
*/
6262
if ($this->hasValue($query->region)) {
63-
$filters[] = 'region:"' . $this->escapeForQuotedString($query->region) . '"';
63+
$filters[] = 'study_region:"' . $this->escapeForQuotedString($query->region) . '"';
6464
}
6565

6666
/**
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Packages\Domains\StudyRegion;
4+
5+
class CountryAliases
6+
{
7+
public const MAPPING = [
8+
'United States of America' => 'United States',
9+
'USA' => 'United States',
10+
11+
'Russian Federation' => 'Russia',
12+
13+
'Republic of Korea' => 'South Korea',
14+
'Korea, Republic of' => 'South Korea',
15+
16+
'Democratic People\'s Republic of Korea' => 'North Korea',
17+
'Korea (Democratic People\'s Republic of)' => 'North Korea',
18+
19+
'Republic of Moldova' => 'Moldova',
20+
21+
"Côte d’Ivoire" => "Cote d'Ivoire",
22+
"Côte d'Ivoire" => "Cote d'Ivoire",
23+
24+
'Lao People\'s Democratic Republic' => 'Laos',
25+
'Syrian Arab Republic' => 'Syria',
26+
'Türkiye' => 'Turkey',
27+
28+
'Viet Nam' => 'Vietnam',
29+
'Czechia' => 'Czech Republic',
30+
31+
'United Kingdom of Great Britain and Northern Ireland' => 'United Kingdom',
32+
'Netherlands (Kingdom of the)' => 'Netherlands',
33+
'Bolivia (Plurinational State of)' => 'Bolivia',
34+
'Venezuela (Bolivarian Republic of)' => 'Venezuela',
35+
36+
'Iran (Islamic Republic of)' => 'Iran',
37+
'Micronesia (Federated States of)' => 'Federated States of Micronesia',
38+
'Palestine, State of' => 'Palestine',
39+
'State of Palestine' => 'Palestine',
40+
'United Republic of Tanzania' => 'Tanzania',
41+
'North Macedonia' => 'North Macedonia',
42+
'The former Yugoslav Republic of Macedonia' => 'North Macedonia',
43+
44+
'Holy See' => 'Vatican City',
45+
'Congo' => 'Republic of the Congo',
46+
'Cabo Verde' => 'Cape Verde',
47+
];
48+
}

0 commit comments

Comments
 (0)