Newer
Older
$targets[$mapping['target']] = $parser->getSourceElement($source, $result, $mapping['source']);
Alex Barth
committed
}
}
return $targets;
}
/**
* Adds Feeds specific information on $entity->feeds_item.
*
* @param $entity
* The entity object to be populated with new item info.
* @param $feed_nid
* The feed nid of the source that produces this entity.
* @param $hash
* The fingerprint of the source item.
*/
protected function newItemInfo($entity, $feed_nid, $hash = '') {
$entity->feeds_item = new stdClass();
$entity->feeds_item->is_new = TRUE;
$entity->feeds_item->entity_type = $this->entityType();
$entity->feeds_item->id = $this->id;
$entity->feeds_item->feed_nid = $feed_nid;
$entity->feeds_item->imported = REQUEST_TIME;
$entity->feeds_item->hash = $hash;
$entity->feeds_item->url = '';
$entity->feeds_item->guid = '';
}
/**
* Loads existing entity information and places it on $entity->feeds_item.
*
* @param $entity
* The entity object to load item info for. Id key must be present.
*
* @return
* TRUE if item info could be loaded, false if not.
*/
protected function loadItemInfo($entity) {
$entity_info = entity_get_info($this->entityType());
$key = $entity_info['entity keys']['id'];
if ($item_info = feeds_item_info_load($this->entityType(), $entity->$key)) {
$entity->feeds_item = $item_info;
return TRUE;
}
return FALSE;
}
/**
* Create MD5 hash of item and mappings array.
*
* Include mappings as a change in mappings may have an affect on the item
* produced.
*
* @return Always returns a hash, even with empty, NULL, FALSE:
* Empty arrays return 40cd750bba9870f18aada2478b24840a
* Empty/NULL/FALSE strings return d41d8cd98f00b204e9800998ecf8427e
*/
protected function hash($item) {
return hash('md5', serialize($item) . serialize($this->config['mappings']));
Chris Leppanen
committed
* Retrieves the MD5 hash of $entity_id from the database.
*
* @return string
* Empty string if no item is found, hash otherwise.
*/
protected function getHash($entity_id) {
Chris Leppanen
committed
if ($hash = db_query("SELECT hash FROM {feeds_item} WHERE entity_type = :type AND entity_id = :id", array(':type' => $this->entityType(), ':id' => $entity_id))->fetchField()) {
// Return with the hash.
return $hash;
}
return '';
}
/**
* Creates a log message for when an exception occured during import.
*
* @param Exception $e
* The exception that was throwned during processing the item.
* @param $entity
* The entity object.
* @param $item
* The parser result for this entity.
*
* @return string
* The message to log.
*/
protected function createLogMessage(Exception $e, $entity, $item) {
include_once DRUPAL_ROOT . '/includes/utility.inc';
$message = $e->getMessage();
$message .= '<h3>Original item</h3>';
$message .= '<pre>' . check_plain(drupal_var_export($item)) . '</pre>';
$message .= '<h3>Entity</h3>';
$message .= '<pre>' . check_plain(drupal_var_export($entity)) . '</pre>';
return $message;
}
megachriz
committed
/**
* Overrides FeedsPlugin::dependencies().
*/
public function dependencies() {
$dependencies = parent::dependencies();
// Find out which module defined the entity type.
$info = $this->entityInfo();
if (isset($info['module'])) {
$dependencies[$info['module']] = $info['module'];
}
return $dependencies;
}
class FeedsProcessorBundleNotDefined extends Exception {}