You are here

public function S3fsService::getExistingFolders in S3 File System 8.3

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

Get existing folders stored in the cached meta data.

Overrides S3fsServiceInterface::getExistingFolders

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

File

src/S3fsService.php, line 537

Class

S3fsService
Defines a S3fsService service.

Namespace

Drupal\s3fs

Code

public function getExistingFolders() {

  // The $folders array is an associative array keyed by folder paths, which
  // is constructed as each filename is written to the DB. After all the files
  // are written, the folder paths are converted to metadata and written.
  $folders = [];

  // Start by gathering all the existing folders. If we didn't do this, empty
  // folders would be lost, because they'd have no files from which to rebuild
  // themselves.
  $existing_folders = \Drupal::database()
    ->select('s3fs_file', 's')
    ->fields('s', [
    'uri',
  ])
    ->condition('dir', 1, '=');
  foreach ($existing_folders
    ->execute()
    ->fetchCol(0) as $folder_uri) {
    $folders[rtrim($folder_uri, '/')] = TRUE;
  }
  return $folders;
}