You are here

public function FeedsFetcherResult::getFilePath in Feeds 8.2

Get a path to a temporary file containing the resource provided by the fetcher.

File will be deleted after DRUPAL_MAXIMUM_TEMP_FILE_AGE.

Return value

A path to a file containing the raw content as a source.

Throws

Exception If an unexpected problem occurred.

1 method overrides FeedsFetcherResult::getFilePath()
FeedsFileFetcherResult::getFilePath in lib/Drupal/feeds/FeedsFileFetcherResult.php
Overrides parent::getFilePath().

File

lib/Drupal/feeds/FeedsFetcherResult.php, line 42

Class

FeedsFetcherResult
Base class for all fetcher results.

Namespace

Drupal\feeds

Code

public function getFilePath() {
  if (!isset($this->file_path)) {
    $destination = 'public://feeds';
    if (!file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
      throw new Exception(t('Feeds directory either cannot be created or is not writable.'));
    }
    $this->file_path = FALSE;
    if ($file = file_save_data($this
      ->getRaw(), $destination . '/' . get_class($this) . REQUEST_TIME)) {
      $file->status = 0;
      $file
        ->save();
      $this->file_path = $file->uri;
    }
    else {
      throw new Exception(t('Cannot write content to %dest', array(
        '%dest' => $destination,
      )));
    }
  }
  return $this
    ->sanitizeFile($this->file_path);
}