Hello,

i have about 500 nodes I want to import into drupal. Normally there are 5 pictures assigned to a node. I do import the image_field as followed:

/firmen/dpm1_1_md.jpg||/firmen/dpm1_2_md.jpg||/firmen/dpm1_3_md.jpg||/firmen/dpm1_4_md.jpg||/firmen/dpm1_5_md.jpg

This works fine, but unforetenatly not every node has 5 pictures, so the script does only import 200 nodes, because in 300 nodes some pictures are missing.

Is there any possibility to just skip a picture if it is not existent?

Thanks alot,

greetings,

bastian

Comments

Robrecht Jacques’s picture

Assigned: spamwelle » Unassigned

Do you mean that the input "a||b||c||d||e" is wrong because eg "a" and "c" are not copied to the right location for some rows? So node_import detects the error and bails out?

Do you suggest that I add a "import a row if there are errors any way"? (not possible with current design because of form validation)

Do you suggest that I add a "ignore files that are not present"? (could be possible)

Would it not be easier to make sure your input file is correct?

spamwelle’s picture

it would be option c)

If the picture is not on the ftp, try the next one and just save the pictures which are present.

The old software just took the user-id (like dpm100) and checked within an array if the pictures exist on the server - after that it put out all the existing pictures for this user. no nice coding.

So option c would be great.

spamwelle’s picture

It would be very great if you could find a solution. I would definitly make a donation via paypal :-)

cjdavis’s picture

This is almost easy. Simply comment out the call to node_import_input_error() in function node_import_check_filepath, located in node_import.inc around line 1240. I also added a message during preview so I can see what is and is not skipped. So the entire function becomes:

/**
 * Check if the value points to a valid filepath.
 *
 * Uses: $field['to_directory'], $options['from_directory'], $options['manually_moved'].
 */
function node_import_check_filepath(&$value, $field, $options, $preview) {
  // No need to check empty values.
  if (drupal_strlen($value) == 0) {
    return TRUE;
  }

  // Where should be file be located?
  $find_in = isset($options['from_directory']) ? $options['from_directory'] : '';
  $find_in = variable_get('node_import:ftp:directory', 'imports') . (strlen($find_in) > 0 ? '/'. $find_in : '');
  if (isset($options['manually_moved']) && $options['manually_moved']) {
    $find_in = isset($field['to_directory']) ? $field['to_directory'] : '';
  }
  $find_in = file_create_path($find_in);

  // Check if the file exists.
  $filepath = $find_in .'/'. $value;
  if (file_check_location($filepath, $find_in) && file_exists($filepath)) {
    $value = $filepath;
    if ($preview) drupal_set_message(t('File %filepath will be imported.', array('%filepath' => $filepath)));
    return TRUE;
  }

  // skip missing files
  //node_import_input_error(t('Input error: %value is not allowed for %name (not a file in %path).', array('%value' => $value, '%name' => $field['title'], '%path' => $find_in)));
  if ($preview) drupal_set_message(t('File %filepath not found. Skipping.', array('%filepath' => $filepath)));
  $value = '';
  return FALSE;
}
spamwelle’s picture

Status: Active » Closed (fixed)

thanks. worked perfect.