You are here

public function S3fsService::convertMetadata in S3 File System 8.3

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

Convert file metadata returned from S3 into a metadata cache array.

Parameters

string $uri: The uri of the resource.

array $s3_metadata: An array containing the collective metadata for the object in S3. The caller may send an empty array here to indicate that the returned metadata should represent a directory.

Return value

array A file metadata cache array.

Overrides S3fsServiceInterface::convertMetadata

2 calls to S3fsService::convertMetadata()
S3fsService::getObjectMetadata in src/S3fsService.php
Cache object meta data.
S3fsService::writeFolders in src/S3fsService.php
Write the folders list to the databsae.

File

src/S3fsService.php, line 602

Class

S3fsService
Defines a S3fsService service.

Namespace

Drupal\s3fs

Code

public function convertMetadata($uri, array $s3_metadata) {

  // Need to fill in a default value for everything, so that DB calls
  // won't complain about missing fields.
  $metadata = [
    'uri' => $uri,
    'filesize' => 0,
    'timestamp' => $this->time
      ->getRequestTime(),
    'dir' => 0,
    'version' => '',
  ];
  if (empty($s3_metadata)) {

    // The caller wants directory metadata.
    $metadata['dir'] = 1;
  }
  else {

    // The filesize value can come from either the Size or ContentLength
    // attribute, depending on which AWS API call built $s3_metadata.
    if (isset($s3_metadata['ContentLength'])) {
      $metadata['filesize'] = $s3_metadata['ContentLength'];
    }
    else {
      if (isset($s3_metadata['Size'])) {
        $metadata['filesize'] = $s3_metadata['Size'];
      }
    }
    if (isset($s3_metadata['LastModified'])) {
      $metadata['timestamp'] = date('U', strtotime($s3_metadata['LastModified']));
    }
    if (isset($s3_metadata['VersionId']) && $s3_metadata['VersionId'] != 'null') {
      $metadata['version'] = $s3_metadata['VersionId'];
    }
  }
  return $metadata;
}