You are here

public function FeedsHTTPCache::saveFile in Feeds 7.2

Saves raw contents to a file in the cache directory.

Parameters

string $cid: The cache ID.

object $response: The HTTP Response object.

Return value

string|null The name of the file that was created or NULL if no file was created.

Throws

Exception In case the cache dir is not writable.

File

includes/FeedsHTTPCache.inc, line 102
Contains FeedsHTTPCache class.

Class

FeedsHTTPCache
Cache implementation for the Feeds HTTP cache.

Code

public function saveFile($cid, $response) {
  if (isset($response->data)) {
    $file_cache_dir = $this
      ->getCacheDir();
    if (!file_prepare_directory($file_cache_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {

      // Cache directory is not writeable.
      if (user_access('administer feeds')) {
        $message = t("The feeds cache directory (@dir) either cannot be created or is not writable. You can change the cache directory by setting the '@variable' variable.", array(
          '@dir' => $file_cache_dir,
          '@variable' => 'feeds_http_file_cache_dir',
        ));
      }
      else {
        $message = t('The feeds cache directory either cannot be created or is not writable. Please contact your site administrator.');
      }
      throw new Exception($message);
    }
    $filename = $this
      ->constructFilePath($cid);
    file_put_contents($filename, $response->data);
    return $filename;
  }
}