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

Commit

Permalink
Removed the "import" prefix in image path
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzdk committed Sep 14, 2021
1 parent 3c63dfc commit db3aedc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ By the time you read this there might be others. Consult [the documentation](htt

### A note regarding images

Only the featured image will be downloaded. Multiple featured images, images added with ACF and other plugins, are not downloaded. Featured images will be downloaded to the "assets" container into a folder called "imports/{collection_handle}", and saved on a field on the entry called "featured_image".
Only the featured image will be downloaded. Multiple featured images, images added with ACF and other plugins, are not downloaded. Featured images will be downloaded to the "assets" container into a folder called "{collection_handle}/{entry_slug}", and saved on a field on the entry called "featured_image".

You can use the events above to do your own downloading of images and what not. I have done this myself with great success 👍

Expand Down
8 changes: 4 additions & 4 deletions src/Helpers/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private function createEntries()
]));

if (config('statamic-wp-import.download_images')) {
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', $collection);
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', $collection, $slug);

if ($asset) {
$entry->set('featured_image', $asset->path());
Expand Down Expand Up @@ -220,7 +220,7 @@ private function createPages()
]));

if (config('statamic-wp-import.download_images')) {
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', 'pages');
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', 'pages', $slug);

if ($asset) {
$page->set('featured_image', $asset->path());
Expand All @@ -237,7 +237,7 @@ private function createPages()
* @param string|null $url
* @return Asset|bool
*/
private function downloadAsset(string $url = null, string $container): Asset|bool
private function downloadAsset(string $url = null, string $collection, string $slug): Asset|bool
{
if (!$url) {
return false;
Expand All @@ -251,7 +251,7 @@ private function downloadAsset(string $url = null, string $container): Asset|boo

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

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

0 comments on commit db3aedc

Please sign in to comment.