You are here

function s3fs_requirements in S3 File System 8.2

Same name and namespace in other branches
  1. 8.3 s3fs.install \s3fs_requirements()
  2. 7.3 s3fs.install \s3fs_requirements()
  3. 7 s3fs.install \s3fs_requirements()
  4. 7.2 s3fs.install \s3fs_requirements()
  5. 4.0.x s3fs.install \s3fs_requirements()

Implements hook_requirements().

File

./s3fs.install, line 14
Install, update and uninstall functions for the S3 File System module.

Code

function s3fs_requirements($phase) {
  $requirements = [];
  if ($phase == 'install') {
    if (!class_exists('\\Aws\\S3\\S3Client')) {
      $requirements['aws_library'] = [
        'description' => t('S3fs require AWS library.'),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }
  if ($phase == 'runtime') {
    $s3fs_config = \Drupal::config('s3fs.settings');
    $access_key = $s3fs_config
      ->get('access_key');
    $secret_key = $s3fs_config
      ->get('secret_key');
    if (!($access_key && $secret_key)) {
      $requirements['s3fs'] = [
        'title' => t('S3 File System'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('S3 File System access key or secret key is not set and it is required for some functionalities to work. Please set it up at the <a href=":settings">S3 File System module settings page</a>.', [
          ':settings' => Url::fromRoute('s3fs.admin_settings')
            ->toString(),
        ]),
      ];
    }
    if (ini_get('allow_url_fopen')) {
      $requirements['s3fs_allow_url_fopen'] = [
        'severity' => REQUIREMENT_OK,
        'title' => t('allow_url_fopen'),
        'value' => t('Enabled'),
      ];
    }
    else {
      $requirements['s3fs_allow_url_fopen'] = [
        'severity' => REQUIREMENT_ERROR,
        'title' => t('allow_url_fopen'),
        'value' => t('Disabled'),
        'description' => t('The S3 File System module requires that the allow_url_fopen setting be turned on in php.ini.'),
      ];
    }
    if (PHP_INT_SIZE === 8) {
      $requirements['s3fs_int64'] = [
        'title' => t('PHP architecture'),
        'value' => t('64-bit'),
        'severity' => REQUIREMENT_OK,
      ];
    }
    else {
      $requirements['s3fs_int64'] = [
        'title' => t('PHP architecture'),
        'value' => t('32-bit'),
        'description' => t('A 64-bit PHP installation is required in order to support files larger than 2GB.'),
        'severity' => REQUIREMENT_WARNING,
      ];
    }
  }
  return $requirements;
}