Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
08e3cb1
chore: world_heritage-split-command-refactor
zigzagdev Mar 28, 2026
22f12dc
Merge pull request #386 from zigzagdev/chore/delete-command-writing-i…
zigzagdev Mar 28, 2026
9cd28c8
refactor: remove thumbnail relation and image_url from WorldHeritage …
zigzagdev Mar 28, 2026
d152539
fix: replace image_url/thumbnail with images relation in WorldHeritag…
zigzagdev Mar 28, 2026
41b8ab1
refactor: update WorldHeritageQueryServiceInterface
zigzagdev Mar 28, 2026
a92eff3
Merge pull request #387 from zigzagdev/fix/api-detail-layout
zigzagdev Mar 29, 2026
edb5fa1
feat: add Eloquent cast into ImageModel
zigzagdev Mar 29, 2026
1ec6ad6
fix: test content add
zigzagdev Mar 29, 2026
9dcfd6d
Merge pull request #388 from zigzagdev/chore/image_url-queryservice-t…
zigzagdev Mar 29, 2026
483fe27
chore: remove image_url from QueryService & Command
zigzagdev Mar 29, 2026
3814c75
Merge pull request #391 from zigzagdev/chore/remove-image_url-from-qs…
zigzagdev Mar 29, 2026
1fb3883
chore: create new migration file
zigzagdev Mar 29, 2026
85a9865
Merge pull request #393 from zigzagdev/feat/create-drop-migration-file
zigzagdev Mar 29, 2026
8937ebd
fix: failed tests
zigzagdev Mar 29, 2026
4a571c0
feat: drop redundant column
zigzagdev Mar 29, 2026
71a3e0f
chore: delete redundant column from seeder
zigzagdev Mar 29, 2026
7fb4385
fix: import key name
zigzagdev Mar 29, 2026
8fe1569
Merge pull request #394 from zigzagdev/fix/delete-redundant-code
zigzagdev Mar 29, 2026
7c42616
Merge pull request #395 from zigzagdev/feat/clean-up-code
zigzagdev Mar 29, 2026
03a13ca
fix: apply copilot review suggestions
zigzagdev Mar 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/app/Console/Commands/AlgoliaImportWorldHeritages.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public function handle(): int

WorldHeritage::query()
->with([
'countries',
'images' => function ($query) {
$query->where('is_primary', true)->select(['world_heritage_site_id', 'url']);
},
'countries' => function ($query) {
$query->select(['countries.state_party_code', 'countries.name_en', 'countries.name_jp']);
},
])
->select([
'world_heritage_sites.id',
Expand All @@ -63,7 +68,6 @@ public function handle(): int
'world_heritage_sites.category',
'world_heritage_sites.year_inscribed',
'world_heritage_sites.is_endangered',
'world_heritage_sites.image_url',
])
->chunkById($chunk, function ($rows) use ($client, $indexName, $dryRun, &$processed) {
$objects = [];
Expand Down Expand Up @@ -130,7 +134,7 @@ public function handle(): int
'category' => (string) $row->category,
'year_inscribed' => $row->year_inscribed !== null ? (int) $row->year_inscribed : null,
'is_endangered' => (bool) $row->is_endangered,
'thumbnail_url' => $row->image_url !== null ? (string) $row->image_url : null,
'thumbnail_url' => $row->images->first()?->url,
'state_party_codes' => $statePartyCodes,
'country_names_jp' => $countryCount > 1 ? $countryNamesJp : [],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function handle(): int
'latitude' => $this->toNullableFloat($row['latitude'] ?? null),
'longitude' => $this->toNullableFloat($row['longitude'] ?? null),
'short_description' => $this->toNullableString($row['short_description'] ?? null),
'image_url' => $this->toNullableString($row['image_url'] ?? null),
'unesco_site_url' => $this->toNullableString($row['unesco_site_url'] ?? null),
'created_at' => $now,
'updated_at' => $now,
Expand Down
178 changes: 76 additions & 102 deletions src/app/Console/Commands/SplitWorldHeritageJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ public function handle(): int
$normalizer = app(CountryCodeNormalizer::class);

$logged = 0;
$logSkip = function (string $reason, int $index, mixed $idNo = null, array $extra = []) use ($logLimit, &$logged): void {
$logSkip = function (
string $reason,
int $index,
mixed $idNo = null,
array $extra =
[]
Comment on lines +102 to +103
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for $extra is split across lines (array $extra = then []). This is valid PHP but inconsistent with the surrounding formatting and will likely be rewritten by Pint; please format it as a single parameter line (array $extra = []) or use a standard multiline style.

Suggested change
array $extra =
[]
array $extra = []

Copilot uses AI. Check for mistakes.
) use ($logLimit, &$logged): void {
if ($logLimit <= 0) {
return;
}
Expand Down Expand Up @@ -324,9 +330,9 @@ public function handle(): int
];
} else {
if (($countries[$code3]['name_en'] ?? null) === $code3) {
$better = $names[$idx] ?? $names[0] ?? null;
if (is_string($better) && trim($better) !== '') {
$countries[$code3]['name_en'] = trim($better);
$betterName = $names[$idx] ?? $names[0] ?? null;
if (is_string($betterName) && trim($betterName) !== '') {
$countries[$code3]['name_en'] = trim($betterName);
}
}
if (($countries[$code3]['region'] ?? null) === null && $region !== null) {
Expand Down Expand Up @@ -609,14 +615,14 @@ private function extractIsoCodes(mixed $v): array
$out = [];
$seen = [];

foreach ($parts as $p) {
$p = strtoupper($p);
if ($p === '') {
foreach ($parts as $part) {
$part = strtoupper($part);
if ($part === '') {
continue;
}
if (!isset($seen[$p])) {
$seen[$p] = true;
$out[] = $p;
if (!isset($seen[$part])) {
$seen[$part] = true;
$out[] = $part;
}
}

Expand All @@ -632,8 +638,8 @@ private function normalizeStatesNames(mixed $statesNames): array
$seen = [];
$out = [];

foreach ($statesNames as $v) {
$name = trim((string) $v);
foreach ($statesNames as $stateName) {
$name = trim((string) $stateName);
if ($name === '') {
continue;
}
Expand All @@ -650,49 +656,49 @@ private function extractImageUrls(array $row): array
{
$urls = [];

$main = $row['main_image_url']['url'] ?? null;
if (is_string($main)) {
$main = trim($main);
if ($main !== '') {
$urls[] = $main;
$mainImageUrl = $row['main_image_url']['url'] ?? null;
if (is_string($mainImageUrl)) {
$mainImageUrl = trim($mainImageUrl);
if ($mainImageUrl !== '') {
$urls[] = $mainImageUrl;
}
}

$images = $row['images_urls'] ?? null;
$imageUrls = $row['images_urls'] ?? null;

if (is_string($images)) {
$parts = preg_split('/\s*,\s*/', trim($images)) ?: [];
foreach ($parts as $p) {
$p = trim($p);
if ($p !== '') {
$urls[] = $p;
if (is_string($imageUrls)) {
$parts = preg_split('/\s*,\s*/', trim($imageUrls)) ?: [];
foreach ($parts as $part) {
$part = trim($part);
if ($part !== '') {
$urls[] = $part;
}
}
}

if (is_array($images)) {
foreach ($images as $p) {
if (!is_string($p)) {
if (is_array($imageUrls)) {
foreach ($imageUrls as $imageUrl) {
if (!is_string($imageUrl)) {
continue;
}
$p = trim($p);
if ($p !== '') {
$urls[] = $p;
$imageUrl = trim($imageUrl);
if ($imageUrl !== '') {
$urls[] = $imageUrl;
}
}
}

$seen = [];
$out = [];
foreach ($urls as $u) {
if (isset($seen[$u])) {
$deduplicated = [];
foreach ($urls as $url) {
if (isset($seen[$url])) {
continue;
}
$seen[$u] = true;
$out[] = $u;
$seen[$url] = true;
$deduplicated[] = $url;
}

return $out;
return $deduplicated;
}

private function normalizeSiteRowImportReady(array $row, int $siteId): array
Expand Down Expand Up @@ -735,8 +741,6 @@ private function normalizeSiteRowImportReady(array $row, int $siteId): array
'latitude' => isset($lat) ? (is_numeric($lat) ? (float) $lat : null) : null,
'longitude' => isset($lon) ? (is_numeric($lon) ? (float) $lon : null) : null,
'short_description' => $this->stringOrNull($row['short_description_en'] ?? null),
'image_url' => $this->stringOrNull($row['image_url'] ?? null),
'primary_image_url' => $this->stringOrNull($row['image_url'] ?? null),
'unesco_site_url' => $this->stringOrNull($row['unesco_site_url'] ?? ($row['url'] ?? null)),
];
}
Expand Down Expand Up @@ -782,11 +786,11 @@ private function mergeSiteRowPreferExisting(array $existing, array $incoming): a
if (($existing['state_party'] ?? null) === null) {
$iso2List = $this->extractIsoCodes($incoming['iso_codes'] ?? null);
if (count($iso2List) === 1) {
$sp = $this->toIso3OrNull($iso2List[0]);
if ($sp !== null) {
$existing['state_party'] = $sp;
$stateParty = $this->toIso3OrNull($iso2List[0]);
if ($stateParty !== null) {
$existing['state_party'] = $stateParty;
if (($existing['country'] ?? null) === null) {
$existing['country'] = $sp;
$existing['country'] = $stateParty;
}
}
}
Expand All @@ -804,25 +808,9 @@ private function mergeSiteRowPreferExisting(array $existing, array $incoming): a

$fill('short_description', $incoming['short_description_en'] ?? null);

if (($existing['image_url'] ?? null) === null || $existing['image_url'] === '') {
$main = $incoming['main_image_url']['url'] ?? null;
if (is_string($main)) {
$main = trim($main);
if ($main !== '') {
$existing['image_url'] = mb_substr($main, 0, 255);
}
}
}

if (($existing['primary_image_url'] ?? null) !== null) {
$existing['primary_image_url'] = null;
}

if (($existing['unesco_site_url'] ?? null) === null) {
$u = $incoming['unesco_site_url'] ?? ($incoming['url'] ?? null);
if ($u) {
$existing['unesco_site_url'] = $u;
}
$unescoUrl = $incoming['unesco_site_url'] ?? ($incoming['url'] ?? null);
if (($existing['unesco_site_url'] ?? null) === null && $unescoUrl) {
$existing['unesco_site_url'] = $unescoUrl;
}

return $existing;
Expand Down Expand Up @@ -945,11 +933,11 @@ private function cleanOutputDir(string $outDir): void
$files = glob($pattern) ?: [];
$deleted = 0;

foreach ($files as $f) {
if (!is_file($f)) {
foreach ($files as $file) {
if (!is_file($file)) {
continue;
}
if (@unlink($f)) {
if (@unlink($file)) {
$deleted++;
}
}
Expand All @@ -963,30 +951,17 @@ private function extractCriteriaList(mixed $criteriaTxt): array
return [];
}

$s = trim($criteriaTxt);
if ($s === '') {
$stringText = trim($criteriaTxt);
if ($stringText === '') {
return [];
}

preg_match_all('/\(([ivx]+)\)/i', $s, $m);
if (!isset($m[1]) || !is_array($m[1])) {
preg_match_all('/\(([ivx]+)\)/i', $stringText, $matches);
if (!isset($matches[1]) || !is_array($matches[1])) {
return [];
}

$out = [];
$seen = [];
foreach ($m[1] as $v) {
$v = strtolower(trim((string) $v));
if ($v === '') {
continue;
}
if (!isset($seen[$v])) {
$seen[$v] = true;
$out[] = $v;
}
}

return $out;
return $this->deduplicateCriteria($matches[1]);
}

private function resolveCriteriaList(array $row): array
Expand All @@ -1001,12 +976,7 @@ private function resolveCriteriaList(array $row): array
return $criteria;
}

$criteria = $this->extractCriteriaFromJustification($row['justification_en'] ?? null);
if ($criteria !== []) {
return $criteria;
}

return [];
return $this->extractCriteriaFromJustification($row['justification_en'] ?? null);
}

private function extractCriteriaFromJustification(mixed $justificationEn): array
Expand All @@ -1015,37 +985,41 @@ private function extractCriteriaFromJustification(mixed $justificationEn): array
return [];
}

$s = trim($justificationEn);
if ($s === '') {
$stringText = trim($justificationEn);
if ($stringText === '') {
return [];
}

$pos = stripos($s, 'criterion');
$pos = stripos($stringText, 'criterion');
if ($pos === false) {
$pos = stripos($s, 'criteria');
$pos = stripos($stringText, 'criteria');
}
if ($pos === false) {
return [];
}

$slice = substr($s, $pos, 600);
$slice = substr($stringText, $pos, 600);

preg_match_all('/\(([ivx]+)\)/i', $slice, $m);
if (!isset($m[1]) || !is_array($m[1]) || $m[1] === []) {
preg_match_all('/\(([ivx]+)\)/i', $slice, $matches);
if (!isset($matches[1]) || !is_array($matches[1]) || $matches[1] === []) {
return [];
}

return $this->deduplicateCriteria($matches[1]);
}

private function deduplicateCriteria(array $criteriaMatches): array
{
$out = [];
$seen = [];
foreach ($m[1] as $v) {
$v = strtolower(trim((string) $v));
if ($v === '') {

foreach ($criteriaMatches as $criterion) {
$criterion = strtolower(trim((string) $criterion));
if ($criterion === '' || isset($seen[$criterion])) {
continue;
}
if (!isset($seen[$v])) {
$seen[$v] = true;
$out[] = $v;
}
$seen[$criterion] = true;
$out[] = $criterion;
}

return $out;
Expand Down
1 change: 0 additions & 1 deletion src/app/Models/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Models;

use App\Models\WorldHeritage;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

Expand Down
8 changes: 7 additions & 1 deletion src/app/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Image extends Model
{
Expand All @@ -23,6 +22,13 @@ class Image extends Model
'updated_at',
];

public function casts(): array
{
return [
'is_primary' => 'boolean',
];
}
Comment on lines +25 to +30
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other models in this codebase (e.g. WorldHeritage), consider declaring this as protected function casts(): array (or using a $casts property). While increasing visibility works in PHP, keeping it consistent helps tooling and readability.

Copilot uses AI. Check for mistakes.

public function worldHeritage()
{
return $this->belongsTo(WorldHeritage::class, 'world_heritage_site_id', 'id');
Expand Down
5 changes: 0 additions & 5 deletions src/app/Models/WorldHeritage.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class WorldHeritage extends Model
'longitude',
'short_description',
'unesco_site_url',
'thumbnail_image_id',
];

protected $hidden = [
Expand All @@ -61,10 +60,6 @@ public function images(): HasMany
->orderBy('sort_order', 'asc');
}

public function thumbnail(): BelongsTo
{
return $this->belongsTo(Image::class, 'thumbnail_image_id');
}
protected function casts(): array
{
return [
Expand Down
Loading
Loading