diff --git a/feeds.drush.inc b/feeds.drush.inc index 7d2f1d1..afaa0d5 100644 --- a/feeds.drush.inc +++ b/feeds.drush.inc @@ -47,10 +47,12 @@ function feeds_drush_command() { 'nid' => 'The nid of the feeds importer that will be refreshed. Optional.', 'file' => 'The file to import by the feed importer. Optional.', 'http' => 'The source to import by the feed importer. Optional.', + 'stdin' => 'Read the file to import from stdin. Optional.', ), 'examples' => array( 'drush feeds-import feed_name' => 'Import the feed feed_name', 'drush feeds-import feed_name --nid=2' => 'Import feed_name associated with nid 2', + 'drush feeds-import feed_name --stdin' => 'Import whatever is entered in stdin.', ), ); @@ -268,6 +270,22 @@ function drush_feeds_import($feed_name = NULL, $feed_nid = 0) { $feed_source->save(); } + if (drush_get_option('stdin')) { + drush_log(dt('Importing !feed from stdin.', array('!feed' => $feed_name)), 'notice'); + $data = stream_get_contents(STDIN); + $file = file_save_data($data, 'private://feeds/drush_feeds_' . $feed_name . '_' . time()); + drush_log(dt('Saved !num bytes to !filename.', array( + '!num' => $file->filesize, + '!filename' => $file->uri, + )), 'notice'); + + $config = $feed_source->getConfig(); + $config['FeedsFileFetcher']['fid'] = $file->fid; + $config['FeedsFileFetcher']['source'] = $file->uri; + $feed_source->setConfig($config); + $feed_source->save(); + } + drush_log(dt('Preparing batch.')); // Set the batch operations. $batch = array(