You are here

function optimizedb_requirements in OptimizeDB 8

Same name and namespace in other branches
  1. 6 optimizedb.install \optimizedb_requirements()
  2. 7 optimizedb.install \optimizedb_requirements()

Implements hook_requirements().

File

./optimizedb.install, line 37
Installation file for Database Optimization.

Code

function optimizedb_requirements($phase) {
  $requirements = [];
  $config = \Drupal::configFactory()
    ->getEditable('optimizedb.settings');
  if ($phase == 'runtime') {

    // Check, if necessary optimization.
    $notify_optimize = $config
      ->get('notify_optimize');
    if ($notify_optimize) {

      // The last time optimization in Unix format.
      $last_optimization = $config
        ->get('last_optimization');

      // If optimization is not carried out earlier
      // must display an appropriate message.
      if ((bool) $last_optimization !== FALSE) {
        $time_optimization = t('Last run: @date ago.', [
          '@date' => _optimizedb_date($last_optimization),
        ]);
      }
      else {
        $time_optimization = t('Optimization yet was not run.');
      }
      $requirements['optimizedb'] = [
        'title' => t('Database Optimization'),
        'description' => t('You must perform <a href="@optimize_link">database optimization</a>. <a href="@hide_link">Hide notification</a>', [
          '@optimize_link' => Url::fromRoute('optimizedb.admin_page')
            ->toString(),
          '@hide_link' => Url::fromRoute('optimizedb.hide')
            ->toString(),
        ]),
        'severity' => REQUIREMENT_ERROR,
        'value' => $time_optimization,
      ];
    }
  }
  if ($phase == 'install') {
    $db_drivers_list = optimizedb_available_db_drivers();
    $db_driver = \Drupal::database()
      ->driver();
    if (!in_array($db_driver, $db_drivers_list)) {
      $requirements['optimizedb'] = [
        'title' => t('Database Optimization'),
        'description' => t('The module Optimizedb does not work with db driver "@name".', [
          '@name' => $db_driver,
        ]),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }
  return $requirements;
}