You are here

function _s3fs_write_metadata in S3 File System 7

Same name and namespace in other branches
  1. 7.3 s3fs.module \_s3fs_write_metadata()
  2. 7.2 s3fs.module \_s3fs_write_metadata()

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.

1 call to _s3fs_write_metadata()
_s3fs_refresh_cache in ./s3fs.module
Refreshes the metadata cache.

File

./s3fs.module, line 460
Sets up the S3fsStreamWrapper class to be used as a Drupal file system.

Code

function _s3fs_write_metadata(&$file_metadata_list, &$folders) {
  if ($file_metadata_list) {
    $insert_query = db_insert('s3fs_file_temp')
      ->fields(array(
      'uri',
      'filesize',
      'timestamp',
      'dir',
      'mode',
      'uid',
      '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 = dirname($metadata['uri']);

      // Loop through each ancestor folder until we get to 's3://'.
      while (strlen($uri) > 5) {
        $folders[$uri] = TRUE;
        $uri = dirname($uri);
      }
    }
    $insert_query
      ->execute();
  }

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