@@ -22,36 +22,38 @@ public function handle(): void
22
22
23
23
Article::unsyncedImages ()->chunk (100 , function ($ articles ) {
24
24
$ articles ->each (function ($ article ) {
25
- $ imageData = $ this ->fetchUnsplashImageDataFromId ($ article-> hero_image_id );
25
+ $ imageData = $ this ->fetchUnsplashImageDataFromId ($ article );
26
26
27
27
if (! is_null ($ imageData )) {
28
28
$ article ->hero_image_url = $ imageData ['image_url ' ];
29
29
$ article ->hero_image_author_name = $ imageData ['author_name ' ];
30
30
$ article ->hero_image_author_url = $ imageData ['author_url ' ];
31
31
$ article ->save ();
32
+ } else {
33
+ $ this ->warn ("Failed to fetch image data for image {$ article ->hero_image_id }" );
32
34
}
33
35
});
34
36
});
35
37
}
36
38
37
- protected function fetchUnsplashImageDataFromId (string $ imageId ): ?array
39
+ protected function fetchUnsplashImageDataFromId (Article $ article ): ?array
38
40
{
39
41
$ response = Http::retry (3 , 100 , throw: false )
40
42
->withToken (config ('services.unsplash.access_key ' ), 'Client-ID ' )
41
- ->get ("https://api.unsplash.com/photos/ {$ imageId }" );
43
+ ->get ("https://api.unsplash.com/photos/ {$ article -> hero_image_id }" );
42
44
43
45
if ($ response ->failed ()) {
44
- logger ()-> error ( ' Failed to get raw image url from unsplash for ' , [
45
- ' imageId ' => $ imageId ,
46
- ' response ' => $ response -> json (),
47
- ] );
46
+ $ article -> hero_image_id = null ;
47
+ $ article -> save ();
48
+
49
+ $ this -> warn ( " Failed to fetch image data for image { $ article -> hero_image_id }" );
48
50
49
51
return null ;
50
52
}
51
53
52
54
$ response = $ response ->json ();
53
55
54
- // Trigger as download...
56
+ // Trigger as Unsplash download...
55
57
Http::retry (3 , 100 , throw: false )
56
58
->withToken (config ('services.unsplash.access_key ' ), 'Client-ID ' )
57
59
->get ($ response ['links ' ]['download_location ' ]);
0 commit comments