You are here

function cdn_requirements in CDN 5

Same name and namespace in other branches
  1. 6.2 cdn.install \cdn_requirements()
  2. 6 cdn.module \cdn_requirements()
  3. 7.2 cdn.install \cdn_requirements()

Implementation of hook_requirements().

File

./cdn.module, line 49

Code

function cdn_requirements($phase) {
  $requirements = array();
  $t = get_t();
  switch ($phase) {
    case 'install':
    case 'runtime':
      $path = drupal_get_path('module', 'cdn') . '/cdn_cron.php';
      $cdn_cron_last = variable_get('cdn_cron_last', NULL);
      $cdn_cron_method = variable_get('cdn_cron_method', 'cdn');
      $requirements['cdn_cron']['title'] = $t('CDN synchronization');
      if (ini_get('safe_mode')) {
        $requirements['cdn_cron'] += array(
          'description' => $t('Safe mode is enabled on this server, which prevents the CDN
            synchronization cron from extending the time limit. This may cause
            the synchronization to not complete successfully.'),
          'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
          'value' => $t('Disable safe mode'),
        );
      }
      elseif ($cdn_cron_method == 'cdn' && !file_exists('cdn_cron.php') || file_exists($path) && file_exists('cdn_cron.php') && md5_file($path) != md5_file('cdn_cron.php')) {
        $requirements['cdn_cron'] += array(
          'description' => $t("In order for the CDN integration module to work correctly, it has\n             to be able to synchronize. This can be done automatically through\n             cron, but you will have to copy the file %file to the same\n             directory as Drupal's cron.php.", array(
            '%file' => $path,
          )),
          'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
          'value' => $t('Copy cdn_cron.php'),
        );
      }
      elseif ($cdn_cron_method == 'cdn' && !file_exists($path)) {
        $requirements['cdn_cron'] += array(
          'description' => $t("You probably <em>moved</em> rather than <em>copied</em> the\n            <em>cdn_cron.php</em> file from %file to the same directory as\n            Drupal's cron.php. You should leave a copy of this file in the CDN\n            integration module directory so that you will not lose this file\n            when you upgrade to another revision of Drupal.", array(
            '%file' => $path,
          )),
          'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
          'value' => $t('Copy cdn_corn.php back'),
        );
      }
      elseif (is_numeric($cdn_cron_last)) {
        $requirements['cdn_cron']['value'] = $t('Last run !time ago', array(
          '!time' => format_interval(time() - $cdn_cron_last),
        ));
        $requirements['cdn_cron']['description'] = variable_get('cdn_cron_last_stats', '<em>' . $t('No statistics available.') . '</em>');
      }
      else {
        $requirements['cdn_cron'] += array(
          'description' => $t('CDN synchronization cron job has not run -- it appears it has not
             been setup on your system. Please check the help pages for
             <a href="@url">configuring cron jobs</a>.', array(
            '@url' => 'http://drupal.org/cron',
          )),
          'severity' => REQUIREMENT_ERROR,
          'value' => $t('Never run'),
        );
      }
  }
  return $requirements;
}