You are here

function optimizedb_requirements in OptimizeDB 6

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

Implements hook_requirements().

File

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

Code

function optimizedb_requirements($phase) {
  global $db_type;
  $requirements = array();

  // Ensure translations don't break during installation.
  $t = get_t();
  if ($phase == 'runtime') {

    // Check, if necessary optimization.
    $notify_optimize = variable_get('optimizedb_notify_optimize', FALSE);
    if ($notify_optimize) {

      // The last time optimization in Unix format.
      $last_optimization = variable_get('optimizedb_last_optimization', 0);

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