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

Commit

Permalink
Added option to overwrite images
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzdk committed Sep 15, 2021
1 parent 6d7cb61 commit 9bfcaa8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ return [
*/
'download_images' => true,
/*
* 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'.
*/
'overwrite_images' => false,
/*
* Filter out meta data keys prefixed with '_'. The default is 'true'.
*/
Expand Down
5 changes: 5 additions & 0 deletions config/statamic-wp-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
*/
'download_images' => true,

/*
* 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'.
*/
'overwrite_images' => false,

/*
* Filter out meta data keys prefixed with '_'. The default is 'true'.
*/
Expand Down
19 changes: 12 additions & 7 deletions src/Helpers/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,18 @@ private function downloadAsset(string $url = null, string $collection, string $s

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

$asset = $assetContainer->makeAsset("{$collection}/{$slug}/{$originalImageName}")
->upload(
new UploadedFile(
Storage::path($tempFile),
$originalImageName,
)
);
$asset = $assetContainer->makeAsset("{$collection}/{$slug}/{$originalImageName}");

if ($asset->exists() && config('statamic-wp-import.overwrite_images')) {
$asset->delete();
}

$asset->upload(
new UploadedFile(
Storage::path($tempFile),
$originalImageName,
)
);

$asset->save();

Expand Down

0 comments on commit 9bfcaa8

Please sign in to comment.