From 5ae1fd73b93b391ba4498cd0c9b6d20f2c1f8f86 Mon Sep 17 00:00:00 2001 From: Alex Barth <alex_b@53995.no-reply.drupal.org> Date: Mon, 20 Sep 2010 15:41:03 +0000 Subject: [PATCH] Upgrade file handling. --- includes/FeedsBatch.inc | 10 +++++++--- plugins/FeedsFileFetcher.inc | 6 ++---- plugins/FeedsParser.inc | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/includes/FeedsBatch.inc b/includes/FeedsBatch.inc index 99d71500..59144c4b 100644 --- a/includes/FeedsBatch.inc +++ b/includes/FeedsBatch.inc @@ -142,6 +142,7 @@ class FeedsBatch { * @see FeedsHTTPBatch */ class FeedsImportBatch extends FeedsBatch { + protected $file_path; protected $title; protected $description; protected $link; @@ -159,6 +160,7 @@ class FeedsImportBatch extends FeedsBatch { FEEDS_PARSING => FEEDS_BATCH_COMPLETE, FEEDS_PROCESSING => FEEDS_BATCH_COMPLETE, ); + $this->file_path = NULL; $this->title = ''; $this->description = ''; $this->link = ''; @@ -189,15 +191,17 @@ class FeedsImportBatch extends FeedsBatch { */ public function getFilePath() { if (!isset($this->file_path)) { - $dir = file_directory_path() .'/feeds'; + $dir = 'public://feeds'; if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { throw new Exception(t('Feeds directory either cannot be created or is not writable.')); } $dest = file_destination($dir . '/' . get_class($this) .'_'. drupal_get_token($this->url) .'_'. time(), FILE_EXISTS_RENAME); - $this->file_path = file_save_data($this->getRaw(), $dest); - if($this->file_path === 0) { + $this->file_path = FALSE; + $file = file_save_data($this->getRaw(), $dest); + if ($file === FALSE) { throw new Exception(t('Cannot write content to %dest', array('%dest' => $dest))); } + $this->file_path = $file->uri; } return $this->file_path; } diff --git a/plugins/FeedsFileFetcher.inc b/plugins/FeedsFileFetcher.inc index 0385458d..a5826715 100644 --- a/plugins/FeedsFileFetcher.inc +++ b/plugins/FeedsFileFetcher.inc @@ -11,8 +11,6 @@ * FeedsFileFetcher. */ class FeedsFileBatch extends FeedsImportBatch { - protected $file_path; - /** * Constructor. */ @@ -87,8 +85,8 @@ class FeedsFileFetcher extends FeedsFetcher { * Override parent::sourceFormValidate(). */ public function sourceFormValidate(&$values) { - $feed_dir = file_directory_path() .'/feeds'; - file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + $feed_dir = 'public://feeds'; + file_prepare_directory($feed_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); // If there is a file uploaded, save it, otherwise validate input on // file. diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc index a7b0acd3..254f2897 100644 --- a/plugins/FeedsParser.inc +++ b/plugins/FeedsParser.inc @@ -247,7 +247,7 @@ class FeedsEnclosure extends FeedsElement { if(empty($this->file) && $this->getValue()) { // Check if this enclosure contains a local file. if (!parse_url($this->getValue(), PHP_URL_SCHEME)) { - if (file_check_location($this->getValue(), file_directory_path())) { + if (strpos($this->getValue(), 'public://') === 0) { if (file_exists($this->getValue())) { $this->file = $this->getValue(); return $this->file; @@ -265,7 +265,8 @@ class FeedsEnclosure extends FeedsElement { $this->file = copy($this->getValue(), $dest) ? $dest : 0; } else { - $this->file = file_save_data($this->getContent(), $dest); + $file = file_save_data($this->getContent(), $dest); + $this->file = $file ? $file->uri : 0; } if ($this->file === 0) { throw new Exception(t('Cannot write content to %dest', array('%dest' => $dest))); -- GitLab