Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 9bfcaa8

Browse files
committed
Added option to overwrite images
1 parent 6d7cb61 commit 9bfcaa8

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ return [
7979
*/
8080
'download_images' => true,
8181
82+
/*
83+
* Enable image overwriting. When set to false, a new image are created with a timestamp suffix, if the image already exists. The default is 'false'.
84+
*/
85+
'overwrite_images' => false,
86+
8287
/*
8388
* Filter out meta data keys prefixed with '_'. The default is 'true'.
8489
*/

config/statamic-wp-import.php

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
*/
88
'download_images' => true,
99

10+
/*
11+
* Enable image overwriting. When set to false, a new image are created with a timestamp suffix, if the image already exists. The default is 'false'.
12+
*/
13+
'overwrite_images' => false,
14+
1015
/*
1116
* Filter out meta data keys prefixed with '_'. The default is 'true'.
1217
*/

src/Helpers/Migrator.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,18 @@ private function downloadAsset(string $url = null, string $collection, string $s
253253

254254
$assetContainer = AssetContainer::findByHandle('assets');
255255

256-
$asset = $assetContainer->makeAsset("{$collection}/{$slug}/{$originalImageName}")
257-
->upload(
258-
new UploadedFile(
259-
Storage::path($tempFile),
260-
$originalImageName,
261-
)
262-
);
256+
$asset = $assetContainer->makeAsset("{$collection}/{$slug}/{$originalImageName}");
257+
258+
if ($asset->exists() && config('statamic-wp-import.overwrite_images')) {
259+
$asset->delete();
260+
}
261+
262+
$asset->upload(
263+
new UploadedFile(
264+
Storage::path($tempFile),
265+
$originalImageName,
266+
)
267+
);
263268

264269
$asset->save();
265270

0 commit comments

Comments
 (0)