diff --git a/sites/all/modules/contrib/feeds/feeds.drush.inc b/sites/all/modules/contrib/feeds/feeds.drush.inc index eae732d..8b0ef61 100644 --- a/sites/all/modules/contrib/feeds/feeds.drush.inc +++ b/sites/all/modules/contrib/feeds/feeds.drush.inc @@ -52,7 +52,7 @@ function feeds_drush_command() { '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.', + 'drush feeds-import feed_name --stdin=xml' => 'Import whatever is entered in stdin.', ), ); @@ -208,11 +208,12 @@ function drush_feeds_import($feed_name = NULL, $feed_nid = 0) { } $feed_source = feeds_source($feed_name, $feed_nid); + $fetcher_config = $feed_source->importer->fetcher->getConfig(); + $feed_dir = $fetcher_config['directory']; // If a file is specified, set the feeds config to that file. if ($filename = drush_get_option('file')) { // Validate the extension of the file. - $fetcher_config = $feed_source->importer->fetcher->getConfig(); $regex = '/\.(' . preg_replace('/ +/', '|', preg_quote($fetcher_config['allowed_extensions'])) . ')$/i'; if (!preg_match($regex, $filename)) { drush_print(dt('Only files with the following extensions are allowed: !files-allowed.', array('!files-allowed' => $fetcher_config['allowed_extensions']))); @@ -220,7 +221,6 @@ function drush_feeds_import($feed_name = NULL, $feed_nid = 0) { } // Feeds folder configuration. - $feed_dir = $fetcher_config['directory']; file_prepare_directory($feed_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); $filename_schema = $feed_dir . '/' . drupal_basename($filename); // If the file already exists, create it in database if necessary and reuse it. @@ -270,12 +270,18 @@ function drush_feeds_import($feed_name = NULL, $feed_nid = 0) { $feed_source->save(); } - if (drush_get_option('stdin')) { - $feed_dir = 'private://feeds'; + if ($extension = drush_get_option('stdin')) { + // Validate the extension of the file. + $regex = '/(' . preg_replace('/ +/', '|', preg_quote($fetcher_config['allowed_extensions'])) . ')$/i'; + if (!preg_match($regex, $extension)) { + drush_print(dt('Only following extensions are allowed: !files-allowed.', array('!files-allowed' => $fetcher_config['allowed_extensions']))); + return FALSE; + } + drush_log(dt('Importing !feed from stdin.', array('!feed' => $feed_name)), 'notice'); $data = stream_get_contents(STDIN); file_prepare_directory($feed_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); - $file = file_save_data($data, $feed_dir . '/drush_feeds_' . $feed_name . '_' . time()); + $file = file_save_data($data, $feed_dir . '/drush_feeds_' . $feed_name . '_' . time() . '.' . $extension); drush_log(dt('Saved !num bytes to !filename.', array( '!num' => $file->filesize, '!filename' => $file->uri,