Skip to content

Commit a405199

Browse files
committed
WIP
1 parent 1c32da4 commit a405199

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

app/Console/Commands/SyncArticleImages.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function handle(): void
3232
Article::published()->chunk(100, function ($articles) {
3333
$articles->each(function ($article) {
3434
if ($this->checkShouldArticleBeSynced($article)) {
35-
$imageData = $this->fetchUnsplashImageDataFromId($article->hero_image);
35+
$imageData = $this->fetchUnsplashImageDataFromId($article->hero_image_id);
3636

3737
if (!is_null($imageData)) {
3838
$article->hero_image_url = $imageData['image_url'];
@@ -47,7 +47,7 @@ public function handle(): void
4747

4848
protected function checkShouldArticleBeSynced(Article $article): bool
4949
{
50-
if (!$article->hero_image || $article->hasHeroImage()) {
50+
if (!$article->hero_image_id || $article->hasHeroImage()) {
5151
return false;
5252
}
5353

app/Models/Article.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class Article extends Model implements Feedable
4444
'body',
4545
'original_url',
4646
'slug',
47-
'hero_image',
47+
'hero_image_id',
4848
'hero_image_url',
4949
'hero_image_author_name',
5050
'hero_image_author_url',
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('articles', function (Blueprint $table) {
15+
$table->renameColumn('hero_image', 'hero_image_id');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('articles', function (Blueprint $table) {
25+
$table->renameColumn('hero_image_id', 'hero_image');
26+
});
27+
}
28+
};

tests/Integration/Commands/SyncArticleImagesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
});
2727

2828
$article = Article::factory()->create([
29-
'hero_image' => 'sxiSod0tyYQ',
29+
'hero_image_id' => 'sxiSod0tyYQ',
3030
'submitted_at' => now(),
3131
'approved_at' => now(),
3232
]);

0 commit comments

Comments
 (0)