public function row($row, array $data, $settings)
{
// See if map and data match (could not be due to malformed csv)
if (count($settings['map']) != count($data)) {
// Log errors when unsuccessful
$this->log[$row] = craft()->import_history->log($settings['history'], $row, array(array(Craft::t('Columns and data did not match, could be due to malformed CSV row.'))));
return;
}
// Check what service we're gonna need
if (!($service = $this->getService($settings['type']))) {
throw new Exception(Craft::t('Unknown Element Type Service called.'));
}
// Map data to fields
$fields = array_combine($settings['map'], $data);
// If set, remove fields that will not be imported
if (isset($fields['dont'])) {
unset($fields['dont']);
}
// Set up a model to save according to element type
$entry = $service->setModel($settings);
// If unique is non-empty array, we're replacing or deleting
if (is_array($settings['unique']) && count($settings['unique']) > 1) {
$entry = $this->replaceOrDelete($row, $settings, $service, $fields, $entry);
if ($entry === null) {
return;
}
}
// Prepare element model
$entry = $service->prepForElementModel($fields, $entry);
try {
// Hook to prepare as appropriate fieldtypes
array_walk($fields, function (&$data, $handle) {
return craft()->plugins->call('registerImportOperation', array(&$data, $handle));
});
} catch (Exception $e) {
// Something went terribly wrong, assume its only this row
$this->log[$row] = craft()->import_history->log($settings['history'], $row, array('exception' => array($e->getMessage())));
}
// Set fields on entry model
$entry->setContentFromPost($fields);
try {
// Hook called after all the field values are set, allowing for modification
// of the entire entry before it's saved. Include the mapping table and row data.
craft()->plugins->call('modifyImportRow', array($entry, $settings['map'], $data));
} catch (Exception $e) {
// Something went terribly wrong, assume its only this row
$this->log[$row] = craft()->import_history->log($settings['history'], $row, array('exception' => array($e->getMessage())));
}
try {
// Log
if (!$service->save($entry, $settings)) {
// Log errors when unsuccessful
$this->log[$row] = craft()->import_history->log($settings['history'], $row, $entry->getErrors());
} else {
// Some functions need calling after saving
$service->callback($fields, $entry);
}
} catch (Exception $e) {
// Something went terribly wrong, assume its only this row
$this->log[$row] = craft()->import_history->log($settings['history'], $row, array('exception' => array($e->getMessage())));
}
}