So close, so close. I can do a CSV import (after uploading images to assets/Uploads), but then what happens is the Image Object seems to get messed up...the Filename loses it's path to assets/Uploads and it doesn't even show in the Files admin any more. So it's working, but not really. This is my code:
<?php
class PhotoBulkLoader extends CsvBulkLoader {
public $columnMap = array(
// Other column map titles
'Title' => 'Title',
'Tags' => 'Tags',
'MainCategory' => 'MainCategory',
'Artist' => 'Artist',
'Medium' => 'Medium',
'Image' =>'Image.Filename'
);
public $relationCallbacks = array(
'Image.Filename' => array(
'relationname' => 'Image',
'callback' => 'getImageByFilename'
)
);
public function getImageByFilename(&$obj, $val, $record) {
// sanitise filename
$filename = trim(strtolower(Convert::raw2sql($val)));
$filenamedashes = str_replace(" ", "-", $filename);
// Find one image with the filename
if($filename && $image = DataObject::get_one('Image', "LOWER(\"Filename\") LIKE '%$filename%' OR LOWER(\"Filename\") LIKE '%$filenamedashes%'")){ //ignore case
if($image instanceof Image && $image->isInDB()){
$image->write();
return $image;
}
}
return null;
}
}