"Displays all importers or displays the config of a given importer (passed as arg).", 'examples' => array( 'drush feeds-list', ), ); $items['feeds-import'] = array( 'description' => "Import a feed.", 'arguments' => array( 'feed-name' => 'The name of the feed importer that will be refreshed. Mandatory.', ), 'options' => array( 'nid' => 'The nid of the feed importer that will be refreshed. Optional.', ), 'examples' => array( 'drush feeds-import feed_name', 'drush feeds-import feed_name --nid=2', ), ); $items['feeds-clear'] = array( 'description' => "Clear a feed.", 'arguments' => array( 'feed-name' => 'The name of the feed importer that will be clear. Mandatory.', ), 'options' => array( 'nid' => 'The nid of the feed importer that will be clear. Optional.', ), 'examples' => array( 'drush feeds-clear feed_name', 'drush feeds-clear feed_name --nid=2', ), ); return $items; } /** * Get a list of all feeds importers. */ function drush_feeds_list() { $rows = array(array(dt('Name'), dt('Description'), dt('Attached to'), dt('Status'), dt('State'))); foreach (feeds_importer_load_all(TRUE) as $k => $i) { if ($i->export_type == EXPORT_IN_CODE) { $state = t('Default'); } else if ($i->export_type == EXPORT_IN_DATABASE) { $state = t('Normal'); } else if ($i->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) { $state = t('Overridden'); } $rows[] = array( ($i->config['name'] . '('. $i->id.')'), $i->config['description'], $i->config['content_type'] ? dt(node_get_types('name', $i->config['content_type'])) : dt('none'), $i->disabled ? dt('Disabled') : dt('Enabled'), $state ); } drush_print_table($rows, TRUE); } /** * Import a given feed_name. * The feed will be refresh regardless of it's scheduled. * * @param string $feed_name */ function drush_feeds_import($feed_name) { if (!isset($feed_name) || $feed_name == "") { drush_print(dt('The importer feed_name is required.')); return FALSE; } if (!($feed_nid = drush_get_option('nid'))) { $feed_nid = 0; } while (TRUE) { $status = feeds_source($feed_name, $feed_nid)->import(); if ($status != FEEDS_BATCH_COMPLETE) { if (is_float($status)) { $status = number_format($status * 100); drush_print(dt('The !name feed is !percent% completed.', array('!name' => $feed_name, '!percent' => $status))); continue; } else { watchdog('Drush Feeds-Import', 'Refresh did not complete.', array(), WATCHDOG_WARNING); } } else { drush_print(dt('The !name feed was successfully imported.', array('!name' => $feed_name))); break; } } } /** * Clear a given feed_name. * The feed will be clear regardless of it's scheduled. * * @param string $feed_name */ function drush_feeds_clear($feed_name) { if (!isset($feed_name) || $feed_name == "") { drush_print(dt('The importer feed_name is required.')); return FALSE; } if (!($feed_nid = drush_get_option('nid'))) { $feed_nid = 0; } $status = feeds_source($feed_name, $feed_nid)->clear(); if ($status != FEEDS_BATCH_COMPLETE) { watchdog('Drush Feeds-Clear', 'Clear did not complete.', array(), WATCHDOG_WARNING); } else { drush_print(dt('The !name feed was successfully cleared.', array('!name' => $feed_name))); } }