Skip to content

Commit

Permalink
Ensure images/files are only downloaded when they're set to be imported
Browse files Browse the repository at this point in the history
  • Loading branch information
mbissett committed Jul 20, 2020
1 parent f23bd12 commit 179ae77
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions rapid-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ function import($importData, $parsedData) {

$import_options = $importData['import']['options'][$this->slug];

// Contains all of the import options, not just add-on specific ones
$all_import_options = $importData['import'];

// echo "<pre>";
// print_r($import_options);
// echo "</pre>";
Expand All @@ -340,36 +343,44 @@ function import($importData, $parsedData) {
switch ($field_params['type']) {

case 'image':

if ( $this->can_update_meta( $field_params['slug'], $all_import_options ) ) {

// import the specified image, then set the value of the field to the image ID in the media library
// import the specified image, then set the value of the field to the image ID in the media library

$image_url_or_path = $parsedData[$field_slug][$index];
$image_url_or_path = $parsedData[$field_slug][$index];

$download = $import_options['download_image'][$field_slug];
$download = $import_options['download_image'][$field_slug];

$uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']);
$uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']);

$data[$field_slug] = array(
"attachment_id" => $uploaded_image,
"image_url_or_path" => $image_url_or_path,
"download" => $download
);
$data[$field_slug] = array(
"attachment_id" => $uploaded_image,
"image_url_or_path" => $image_url_or_path,
"download" => $download
);

}

break;

case 'file':

$image_url_or_path = $parsedData[$field_slug][$index];
if ( $this->can_update_meta( $field_params['slug'], $all_import_options ) ) {

$download = $import_options['download_image'][$field_slug];
$image_url_or_path = $parsedData[$field_slug][$index];

$uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']);
$download = $import_options['download_image'][$field_slug];

$data[$field_slug] = array(
"attachment_id" => $uploaded_file,
"image_url_or_path" => $image_url_or_path,
"download" => $download
);
$uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']);

$data[$field_slug] = array(
"attachment_id" => $uploaded_file,
"image_url_or_path" => $image_url_or_path,
"download" => $download
);

}

break;

Expand Down

0 comments on commit 179ae77

Please sign in to comment.