Skip to content

Commit 2f49a87

Browse files
authored
Merge pull request #367 from zigzagdev/feat/implement-study-region
Feat/implement study region
2 parents ab5b6c9 + 3cf7c11 commit 2f49a87

42 files changed

Lines changed: 1268 additions & 1690 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docker-compose.yml

Lines changed: 24 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,8 @@ 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+
networks:
20+
- heritage-net
2121

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

3751
phpmyadmin:
3852
image: phpmyadmin/phpmyadmin:latest
@@ -44,14 +58,13 @@ services:
4458
PMA_PASSWORD: world-heritage
4559
ports:
4660
- "127.0.0.1:8081:80"
47-
depends_on: [ mysql ]
48-
networks: [ heritage-net ]
61+
depends_on:
62+
- mysql
63+
networks:
64+
- heritage-net
4965

5066
networks:
5167
heritage-net:
5268

5369
volumes:
54-
db_data:
55-
vendor_data:
56-
cache_data:
57-
composer_cache:
70+
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function search(
5959
/**
6060
* Region filter (exact match).
6161
*/
62-
if ($this->hasValue($query->region)) {
63-
$filters[] = 'region:"' . $this->escapeForQuotedString($query->region) . '"';
62+
if ($query->region !== null) {
63+
$filters[] = 'study_region:"' . $this->escapeForQuotedString($query->region->value) . '"';
6464
}
6565

6666
/**

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

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)