You are here

function feed_import_import_feed_from_json in Feed Import 7.3

Import a feed from a json file.

Parameters

string $json The JSON encoded feed configuration:

array $options An array of options to add to $json configuration:

bool $cleanup TRUE to reset import information:

Return value

mixed A feed configuration object on success or false on error

1 call to feed_import_import_feed_from_json()
feed_import_import_feed_form_submit in ./feed_import.module
Import form submit

File

./feed_import.module, line 2399
User interface, cron functions for feed_import module

Code

function feed_import_import_feed_from_json($json, array $options = array(), $cleanup = TRUE, $keep_id = FALSE) {
  if ($code = @json_decode($json, TRUE)) {

    // Get an empty feed configuration.
    $ef = FeedImport::getEmptyFeed();

    // Add options.
    $code = $options + $code;

    // Add empty feed items.
    $code += $ef;

    // Add settings options if any.
    if (!empty($options['settings'])) {
      $code['settings'] = $options['settings'] + $code['settings'];
    }

    // Add empty feed settings.
    $code['settings'] += $ef['settings'];

    // Not needed anymore.
    unset($json, $ef, $options);
    if (!$keep_id) {
      unset($code['id']);
    }

    // Convert to object.
    $code = (object) $code;

    // Cleanup import info.
    if ($cleanup) {
      $code->cron_import = 0;
      $code->last_run = 0;
      $code->last_run_duration = 0;
      $code->last_run_items = 0;
    }

    // Check for group, if no group then use machine_name as group.
    if (empty($code->settings['hashes']['options']['group'])) {
      $code->settings['hashes']['options']['group'] = $code->machine_name;
    }

    // Save feed.
    if (FeedImport::saveFeed($code)) {
      return $code;
    }
  }
  return FALSE;
}