Support forums

Please check @brandnewbox_uk for support status updates.

Search     Advanced Search
Rows ignored on import due to image filename not in system  
Posted: 27 July 2018 01:24 PM —  
Newbie
Rank
Total Posts:  16
Joined  2011-06-18

Hi Andrew

EE 4.3.1
DataGrab 3.0.3

I have a situation where the client has supplied a CSV file of entry data with an image column containing a filename and a folder of images. I’ve imported the images into EE using Sync which creates the necessary file database entries and then on importing the CSV the image name is checked against the sync’ed images.

However I’ve discovered that some of the CSV rows contain filenames that do not exist among the imported images which means that the row is ignored during the DataGrab import returning “invalid selection” errors which is thrown by EE’s File Validation function.

It’s not feasible for me to ask the client to rework their data to exclude filenames where the images don’t exist as they don’t have that ability. So what I need to be able to do in this case is create an option for file filedtypes where if the image is not found in the system to set the field data value to NULL or empty and allow the row to be inserted with or without the image.

Where in your code would you suggest I start hacking this into place?

Many thanks

David

Profile
 
Posted: 27 July 2018 06:29 PM —   [ # 1 ]  
Newbie
Rank
Total Posts:  16
Joined  2011-06-18

Quick update on this. I’ve been tinkering around in your fieldtypes/datagrab_file.php file and added a final_post_data() function where I was able to check if the image file specified in $data[‘field_id_’.$field_id] exists on the server. I had hoped that by doing this and then setting this same value to an empty string if the file does not exist that would solve the problem but no. It appears that the default EE validation is still being processed after this point and the row is still be ignored due the invalid selection error.

I’m not sure if there’s another way round this?

Profile
 
Posted: 27 July 2018 07:39 PM —   [ # 2 ]  
Newbie
Rank
Total Posts:  16
Joined  2011-06-18

Final update. All sorted and solved!

With my previous update I was just being a numpty because what I was attempting does work. I added this function to datagrab_file.php

function final_post_data( $DG, $item, $field_id, $field, &$data, $update = FALSE ) {

  $filename = dirname($_SERVER['DOCUMENT_ROOT']) . '/html/uploads/store/' . preg_replace('/^{filedir_(\d+)}/', '', $data['field_id_'.$field_id]);

  if(! file_exists($filename)){
   $data['field_id_'.$field_id] = '';
  }

 }

Hopefully this might help someone else one day…

Profile
 

‹‹ XML Imports via File Path fail with error      Match existing entries via entry_id in DataGrab ››

Select A Theme