You are here

protected function S3fsStream::writeCache in S3 File System 8.3

Same name and namespace in other branches
  1. 4.0.x src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::writeCache()

Write an object's (and its ancestor folders') metadata to the cache.

Parameters

array $metadata: An associative array of file metadata in this format: 'uri' => The full URI of the file, including the scheme. 'filesize' => The size of the file, in bytes. 'timestamp' => The file's create/update timestamp. 'dir' => A boolean indicating whether the object is a directory.

Throws

\Drupal\s3fs\S3fsException Exceptions which occur in the database call will percolate.

3 calls to S3fsStream::writeCache()
S3fsStream::mkdir in src/StreamWrapper/S3fsStream.php
Support for mkdir().
S3fsStream::rename in src/StreamWrapper/S3fsStream.php
Support for rename().
S3fsStream::writeUriToCache in src/StreamWrapper/S3fsStream.php
Write the file at the given URI into the metadata cache.

File

src/StreamWrapper/S3fsStream.php, line 1346

Class

S3fsStream
Defines a Drupal s3 (s3://) stream wrapper class.

Namespace

Drupal\s3fs\StreamWrapper

Code

protected function writeCache(array $metadata) {
  $metadata['uri'] = $this->streamWrapperManager
    ->normalizeUri($metadata['uri']);

  // Should never happen as we attempt to capture this earlier.
  if (mb_strlen($metadata['uri']) > S3fsServiceInterface::MAX_URI_LENGTH) {
    return;
  }
  \Drupal::database()
    ->merge('s3fs_file')
    ->key([
    'uri' => $metadata['uri'],
  ])
    ->fields($metadata)
    ->execute();

  // Clear this URI from the Drupal cache, to ensure the next read isn't
  // from a stale cache entry.
  $cid = S3FS_CACHE_PREFIX . $metadata['uri'];
  $cache = \Drupal::cache(S3FS_CACHE_BIN);
  $cache
    ->delete($cid);
  $dirname = \Drupal::service('file_system')
    ->dirname($metadata['uri']);

  // If this file isn't in the root directory, also write this file's
  // ancestor folders to the cache.
  if ($this->streamWrapperManager::getTarget($dirname) != '') {
    $this
      ->mkdir($dirname, NULL, STREAM_MKDIR_RECURSIVE);
  }
}