You are here

public function S3::ensure in Flysystem - S3 2.0.x

Same name and namespace in other branches
  1. 8 src/Flysystem/S3.php \Drupal\flysystem_s3\Flysystem\S3::ensure()

File

src/Flysystem/S3.php, line 208

Class

S3
Drupal plugin for the "S3" Flysystem adapter.

Namespace

Drupal\flysystem_s3\Flysystem

Code

public function ensure($force = FALSE) {
  try {
    $this
      ->getAdapter()
      ->listContents();
  } catch (S3Exception $e) {
    $message = $e
      ->getMessage();
    \Drupal::logger('flysystem_s3')
      ->error($message);
  }

  // @TODO: If the bucket exists, can we write to it? Find a way to test that.
  if (!$this->client
    ->doesBucketExist($this->bucket)) {
    return [
      [
        'severity' => RfcLogLevel::ERROR,
        'message' => 'Bucket %bucket does not exist.',
        'context' => [
          '%bucket' => $this->bucket,
        ],
      ],
    ];
  }
  return [];
}