You are here

public static function FeedImport::processFeed in Feed Import 7.2

Same name and namespace in other branches
  1. 7 feed_import.inc.php \FeedImport::processFeed()

This function is choosing process function and executes it

Parameters

array $feed: Feed info array

1 call to FeedImport::processFeed()
feed_import_import_items in ./feed_import.module
Import feed and set report

File

./feed_import.inc.php, line 218
Feed import class for parsing and processing content.

Class

FeedImport
@file Feed import class for parsing and processing content.

Code

public static function processFeed(array $feed) {

  // Reset report.
  self::$report = array(
    'rescheduled' => 0,
    'updated' => 0,
    'new' => 0,
    'total' => 0,
    'start' => time(),
    'time' => 0,
    'parse' => 0,
    'errors' => array(),
  );

  // Check if entity save/load functions exists.
  if (self::checkFunctions($feed['entity_info']['#entity'])) {

    // Alter feed info before process.
    drupal_alter('feed_import_feed_info', $feed);

    // Set language as first element.
    if (isset($feed['xpath']['#items']['language'])) {
      $feed['xpath']['#items'] = array_merge(array(
        'language' => NULL,
      ), $feed['xpath']['#items']);
    }

    // Set error handler.
    set_error_handler(array(
      __CLASS__,
      'errorHandler',
    ));
    $func = $feed['xpath']['#process_function'];
    $functions = self::processFunctions();
    if (!$func || !isset($functions[$func])) {

      // Get first function if there's no specified function.
      $func = self::processFunctions();
      $func = reset($func);
    }
    else {
      $func = $functions[$func];
    }
    $func = $func['function'];
    unset($functions);

    // Get property temp name to store hash value.
    self::$tempHash = variable_get('feed_import_hash_property', self::$tempHash);

    // Reset generated hashes
    self::$generatedHashes = array();

    // Give import time (for large imports).
    // Well, if safe mode is on this cannot be done so it may break import.
    if (!ini_get('safe_mode')) {
      set_time_limit(0);
    }

    // Prepare filters.
    $param = variable_get('feed_import_field_param_name', '[field]');
    foreach ($feed['xpath']['#items'] as &$item) {
      self::prepareFilters($item['#filter'], $param);
      self::prepareFilters($item['#pre_filter'], $param);
    }

    // Call process function to get processed items.
    $items = call_user_func($func, $feed);

    // Parse report.
    self::$report['parse'] = time();

    // Save items.
    if (!empty($items)) {
      self::saveEntities($feed, $items);
    }

    // Restore error handler.
    restore_error_handler();
  }
  else {

    // Report that vital functions are missing.
    self::$report['errors'][] = array(
      'error' => t('Missing @entity_save() or @entity_load() function!', array(
        '@entity' => $feed['entity_info']['#entity'],
      )),
      'error number' => '',
      'line' => '',
      'file' => '',
    );

    // This will produce 0 seconds for parse.
    self::$report['parse'] = self::$report['start'];
  }

  // Set total time report.
  self::$report['time'] = time() - self::$report['start'];
  self::$report['parse'] -= self::$report['start'];
}