"Refreshes a feed based on its schedule.", '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-refresh my_feed_id', 'drush feeds-refresh my_feed_id --nid=2', ), ); $items['feeds-config'] = array( 'description' => "Displays all active importers or displays the config of a given importer (passed as arg).", 'examples' => array( 'drush feeds-config', 'drush feeds-config my_feed_id', ), ); return $items; } /** * Implementation of hook_drush_help(). * * @param * A string with the help section (prepend with 'drush:') * * @return * A string with the help text for your command. */ function feeds_drush_help($section) { switch ($section) { case 'drush:feeds-refresh': return dt("Refreshes a feed based on its schedule."); case 'drush:feeds-queue': return dt("Adds a scheduled feed to the drupal_queue."); case 'drush:feeds-config': return dt("Displays all active importers or displays the config of a given importer (passed as arg)."); } } /** * Refresh a given feed_name based on its schedule. * The feed will not be refresh if it's not scheduled. * * @param string $feed_name */ function drush_feeds_refresh($feed_name) { if (!isset($feed_name) || $feed_name == "") { print 'The importer feed_name is required.'; return FALSE; } if (!($feed_nid = drush_get_option('nid'))) { $feed_nid = 0; } if (variable_get('feeds_scheduler_drush_refresh', FALSE)) { watchdog('Drush Feeds-Refresh', 'Last drush refresh did not complete. Restarting...', array(), WATCHDOG_WARNING); } variable_set('feeds_scheduler_drush_refresh', TRUE); $status = feeds_source($feed_name, $feed_nid)->import(); if ($status != FEEDS_BATCH_COMPLETE) { watchdog('Drush Feeds-Refresh', 'Refresh did not complete.', array(), WATCHDOG_WARNING); } variable_set('feeds_scheduler_drush_refresh', FALSE); } /** * Display the config of a given importer. * * @param string $feed_name */ function drush_feeds_config() { $args = func_get_args(); $feed_name = $args[0]; if (!isset($feed_name) || $feed_name == "") { $importers = feeds_importer_load_all(); drush_print("\nHere is a list of active importers:\n"); foreach ($importers as $importer) { drush_print($importer->config['name'] . " ({$importer->id})"); drush_print(" - " . $importer->config['description']); drush_print(" * " . $importer->config['fetcher']['plugin_key']); drush_print(" * " . $importer->config['parser']['plugin_key']); drush_print(" * " . $importer->config['processor']['plugin_key']); drush_print("\n\n"); } return FALSE; } $sql = "SELECT id, feed_nid, config, source FROM {feeds_source} WHERE id = '%s'"; $result = db_query_range($sql, $feed_name, 0, 1); $feed_info = db_fetch_array($result); if ($feed_info) { $importer = feeds_importer($feed_info['id']); drush_print($importer->config['name']); drush_print(" - " . $importer->config['description']); drush_print(" * " . $importer->config['fetcher']['plugin_key']); drush_print(" * " . $importer->config['parser']['plugin_key']); drush_print(" * " . $importer->config['processor']['plugin_key']); drush_print("\nFeed nid:"); print_r(unserialize($feed_info['feed_nid'])); drush_print("\nSource:"); print_r(unserialize($feed_info['source'])); drush_print("\nConfig:"); print_r(unserialize($feed_info['config'])); } else { drush_print("The importer '$feed_name' does not exist."); } return; }