Skip to content
Snippets Groups Projects
Commit 5ae1fd73 authored by Alex Barth's avatar Alex Barth
Browse files

Upgrade file handling.

parent 0be4cf20
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
......@@ -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.
......
......@@ -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)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment