Skip to content

Commit 7c42616

Browse files
authored
Merge pull request #395 from zigzagdev/feat/clean-up-code
Feat/clean up code
2 parents 9dcfd6d + 8fe1569 commit 7c42616

8 files changed

Lines changed: 67 additions & 16 deletions

src/app/Console/Commands/AlgoliaImportWorldHeritages.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ public function handle(): int
5151

5252
WorldHeritage::query()
5353
->with([
54-
'countries',
54+
'images' => function ($query) {
55+
$query->where('is_primary', true)->select(['world_heritage_site_id', 'url']);
56+
},
57+
'countries' => function ($query) {
58+
$query->select(['countries.state_party_code', 'countries.name_en', 'countries.name_jp']);
59+
},
5560
])
5661
->select([
5762
'world_heritage_sites.id',
@@ -63,7 +68,6 @@ public function handle(): int
6368
'world_heritage_sites.category',
6469
'world_heritage_sites.year_inscribed',
6570
'world_heritage_sites.is_endangered',
66-
'world_heritage_sites.image_url',
6771
])
6872
->chunkById($chunk, function ($rows) use ($client, $indexName, $dryRun, &$processed) {
6973
$objects = [];
@@ -130,7 +134,7 @@ public function handle(): int
130134
'category' => (string) $row->category,
131135
'year_inscribed' => $row->year_inscribed !== null ? (int) $row->year_inscribed : null,
132136
'is_endangered' => (bool) $row->is_endangered,
133-
'thumbnail_url' => $row->image_url !== null ? (string) $row->image_url : null,
137+
'thumbnail_url' => $row->images->first()?->url,
134138
'state_party_codes' => $statePartyCodes,
135139
'country_names_jp' => $countryCount > 1 ? $countryNamesJp : [],
136140
];

src/app/Console/Commands/ImportWorldHeritageSiteFromSplitFile.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public function handle(): int
9696
'latitude' => $this->toNullableFloat($row['latitude'] ?? null),
9797
'longitude' => $this->toNullableFloat($row['longitude'] ?? null),
9898
'short_description' => $this->toNullableString($row['short_description'] ?? null),
99-
'image_url' => $this->toNullableString($row['image_url'] ?? null),
10099
'unesco_site_url' => $this->toNullableString($row['unesco_site_url'] ?? null),
101100
'created_at' => $now,
102101
'updated_at' => $now,

src/app/Console/Commands/SplitWorldHeritageJson.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public function handle(): int
282282
foreach ($imageUrls as $idx => $url) {
283283
$images[] = [
284284
'world_heritage_site_id' => $siteId,
285-
'url' => hash('sha256', $url),
285+
'url' => $url,
286286
'sort_order' => $idx,
287287
'is_primary' => ($idx === 0) ? 1 : 0,
288288
];

src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_countEachRegionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ private function baseRecord(array $override = []): array
6969
'latitude' => null,
7070
'longitude' => null,
7171
'short_description' => '',
72-
'image_url' => null,
7372
'unesco_site_url' => null,
7473
'created_at' => $now,
7574
'updated_at' => $now,

src/app/Packages/Domains/WorldHeritageReadQueryService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ public function findByIdsPreserveOrder(array $ids): Collection
3333
'world_heritage_sites.latitude',
3434
'world_heritage_sites.longitude',
3535
'world_heritage_sites.short_description',
36-
'world_heritage_sites.image_url',
3736
])
3837
->with([
3938
'countries' => function ($q) {
4039
$q->select('countries.state_party_code', 'countries.name_en', 'countries.name_jp', 'countries.region')
4140
->orderBy('countries.state_party_code', 'asc');
4241
},
42+
'images' => function ($imageQuery) {
43+
$imageQuery->where('is_primary', true)->limit(1);
44+
},
4345
])
4446
->whereIn('world_heritage_sites.id', $ids)
4547
->get()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('world_heritage_sites', function (Blueprint $table) {
15+
$table->dropColumn('image_url');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('world_heritage_sites', function (Blueprint $table) {
25+
$table->string('image_url')->nullable()->after('short_description');
26+
});
27+
}
28+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('world_heritage_sites', function (Blueprint $table) {
15+
$table->dropColumn('primary_image_url');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('world_heritage_sites', function (Blueprint $table) {
25+
$table->string('primary_image_url')->nullable()->after('short_description');
26+
});
27+
}
28+
};

src/database/seeders/WorldHeritageSeeder.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public function run(): void
3232
'latitude' => 34.8394,
3333
'longitude' => 134.6939,
3434
'short_description' => '白鷺城の名で知られる城郭建築の傑作。天守群と縄張りが良好に保存される。',
35-
'image_url' => null,
3635
'unesco_site_url' => 'https://whc.unesco.org/en/list/661',
3736
'created_at' => $now, 'updated_at' => $now,
3837
],
@@ -56,7 +55,6 @@ public function run(): void
5655
'latitude' => null,
5756
'longitude' => null,
5857
'short_description' => '巨樹・照葉樹林に代表される生態系と景観が特筆される島。',
59-
'image_url' => null,
6058
'unesco_site_url' => 'https://whc.unesco.org/en/list/662',
6159
'created_at' => $now, 'updated_at' => $now,
6260
],
@@ -80,7 +78,6 @@ public function run(): void
8078
'latitude' => null,
8179
'longitude' => null,
8280
'short_description' => '日本最大級のブナ天然林を中心とする山地生態系。',
83-
'image_url' => null,
8481
'unesco_site_url' => 'https://whc.unesco.org/en/list/663',
8582
'created_at' => $now, 'updated_at' => $now,
8683
],
@@ -104,7 +101,6 @@ public function run(): void
104101
'latitude' => 0.0,
105102
'longitude' => 0.0,
106103
'short_description' => '京都・宇治・大津に点在する社寺・庭園・城郭などから成る文化遺産群。',
107-
'image_url' => null,
108104
'unesco_site_url' => 'https://whc.unesco.org/en/list/688',
109105
'created_at' => $now, 'updated_at' => $now,
110106
],
@@ -128,7 +124,6 @@ public function run(): void
128124
'latitude' => 0.0,
129125
'longitude' => 0.0,
130126
'short_description' => '氷期後のブナの自然拡散史を示すヨーロッパ各地の原生的ブナ林群から成る越境・連続資産。',
131-
'image_url' => '',
132127
'unesco_site_url' => 'https://whc.unesco.org/en/list/1133',
133128
'created_at' => $now, 'updated_at' => $now,
134129
],
@@ -152,7 +147,6 @@ public function run(): void
152147
'latitude' => 0.0,
153148
'longitude' => 0.0,
154149
'short_description' => '熊野三山・高野山・吉野・大峯を結ぶ霊場と参詣道の文化的景観。',
155-
'image_url' => null,
156150
'unesco_site_url' => 'https://whc.unesco.org/en/list/1142',
157151
'created_at' => $now, 'updated_at' => $now,
158152
],
@@ -176,7 +170,6 @@ public function run(): void
176170
'latitude' => 0.0,
177171
'longitude' => 0.0,
178172
'short_description' => '日本の象徴たる霊峰。信仰・芸術・登拝文化に深い影響を与えた文化的景観。',
179-
'image_url' => null,
180173
'unesco_site_url' => 'https://whc.unesco.org/en/list/1418',
181174
'created_at' => $now, 'updated_at' => $now,
182175
],
@@ -200,7 +193,6 @@ public function run(): void
200193
'latitude' => 0.0,
201194
'longitude' => 0.0,
202195
'short_description' => '中国・カザフスタン・キルギスにまたがるオアシス都市や遺跡群で構成され、東西交流の歴史を物証する文化遺産群。',
203-
'image_url' => '',
204196
'unesco_site_url' => 'https://whc.unesco.org/en/list/1442',
205197
'created_at' => $now, 'updated_at' => $now,
206198
],
@@ -224,7 +216,6 @@ public function run(): void
224216
'latitude' => 0.0,
225217
'longitude' => 0.0,
226218
'short_description' => '中央アジアのザラフシャン谷からカラクム砂漠にかけて展開するオアシス都市・交易遺跡群の連続資産。',
227-
'image_url' => null,
228219
'unesco_site_url' => 'https://whc.unesco.org/en/list/1662',
229220
'created_at' => $now, 'updated_at' => $now,
230221
],

0 commit comments

Comments
 (0)