You are here

flysystem.install in Flysystem 7

Install, update, enable hooks for flysystem.module.

File

flysystem.install
View source
<?php

/**
 * @file
 * Install, update, enable hooks for flysystem.module.
 */

/**
 * Implements hook_requirements().
 */
function flysystem_requirements($phase) {
  $requirements = array();
  if ($phase !== 'runtime') {
    return $requirements;
  }
  if (!flysystem_dependencies_check()) {
    $requirements['flysystem_dependencies'] = array(
      'title' => t('Flysystem'),
      'description' => t('The Flysystem dependencies are not installed correctly.'),
      'severity' => REQUIREMENT_ERROR,
    );

    // Things will most likely be broken, so don't continue.
    return $requirements;
  }
  foreach (flysystem_factory()
    ->ensure() as $scheme => $errors) {
    foreach ($errors as $error) {
      $requirements['flysystem:' . $scheme] = array(
        'title' => t('Flysystem: @scheme', array(
          '@scheme' => $scheme,
        )),
        'description' => t($error['message'], $error['context']),
        'severity' => _flysystem_convert_watchdog_to_requirements($error['severity']),
      );
    }
  }
  return $requirements;
}

/**
 * Converts from watchdog to hook_requirements values.
 *
 * @param int $severity
 *   The severity according to watchdog().
 *
 * @return int
 *   An appropriate value for hook_requirements.
 */
function _flysystem_convert_watchdog_to_requirements($severity) {
  if ($level <= WATCHDOG_ERROR) {
    return REQUIREMENT_ERROR;
  }
  if ($level == WATCHDOG_WARNING) {
    return REQUIREMENT_WARNING;
  }
  if ($level == WATCHDOG_NOTICE || $level == WATCHDOG_INFO) {
    return REQUIREMENT_INFO;
  }
  return REQUIREMENT_OK;
}

Functions

Namesort descending Description
flysystem_requirements Implements hook_requirements().
_flysystem_convert_watchdog_to_requirements Converts from watchdog to hook_requirements values.