You are here

public function S3fsService::writeTemporaryMetadata in S3 File System 8.3

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

Writes metadata to the temp table in the database.

Parameters

array $file_metadata_list: An array passed by reference, which contains the current page of file metadata. This function empties out $file_metadata_list at the end.

array $folders: An associative array keyed by folder name, which is populated with the ancestor folders of each file in $file_metadata_list.

Overrides S3fsServiceInterface::writeTemporaryMetadata

1 call to S3fsService::writeTemporaryMetadata()
S3fsService::refreshCache in src/S3fsService.php
Refreshes the metadata cache.

File

src/S3fsService.php, line 643

Class

S3fsService
Defines a S3fsService service.

Namespace

Drupal\s3fs

Code

public function writeTemporaryMetadata(array &$file_metadata_list, array &$folders) {
  if ($file_metadata_list) {
    $insert_query = \Drupal::database()
      ->insert('s3fs_file_temp')
      ->fields([
      'uri',
      'filesize',
      'timestamp',
      'dir',
      'version',
    ]);
    foreach ($file_metadata_list as $metadata) {

      // Write the file metadata to the DB.
      $insert_query
        ->values($metadata);

      // Add the ancestor folders of this file to the $folders array.
      $uri = \Drupal::service('file_system')
        ->dirname($metadata['uri']);
      $root = StreamWrapperManager::getScheme($uri) . '://';

      // Loop through each ancestor folder until we get to the root uri.
      // Risk exists that dirname() returns a malformed uri if a
      // StreamWrapper is disabled causing a loop. Use isValidUri to avoid.
      while ($uri != $root && \Drupal::service('stream_wrapper_manager')
        ->isValidUri($uri)) {
        $folders[$uri] = TRUE;
        $uri = \Drupal::service('file_system')
          ->dirname($uri);
      }
    }
    $insert_query
      ->execute();
  }

  // Empty out the file array, so it can be re-filled by the next request.
  $file_metadata_list = [];
}