You are here

function _acquia_purge_get_diagnosis in Acquia Purge 6

Same name and namespace in other branches
  1. 7 acquia_purge.deprecated.inc \_acquia_purge_get_diagnosis()

Perform a series of self-tests against the site and our purging conditions.

@returns Array that complies to the format as seen in hook_requirements().

Parameters

int $verbosity: Optional, the level of diagnostics presented. Test results that match or are higher than the given level are returned.

5 calls to _acquia_purge_get_diagnosis()
acquia_purge_ajax_processor in ./acquia_purge.admin.inc
Menu callback; process a chunk of purge items via AJAX.
acquia_purge_expire_cache in ./acquia_purge.module
Implements hook_expire_cache().
acquia_purge_requirements in ./acquia_purge.install
Implements hook_requirements().
drush_acquia_purge_ap_diagnosis in ./acquia_purge.drush.inc
Perform a series of diagnostic self-tests.
_acquia_purge_queue_processpurge in ./acquia_purge.module
Queue manager: process a single path (on all domains and balancers).

File

./acquia_purge.module, line 344
Acquia Purge, Top-notch Varnish purging on Acquia Cloud!

Code

function _acquia_purge_get_diagnosis($verbosity = ACQUIA_PURGE_SEVLEVEL_INFO) {
  static $tests;

  // Initialize $tests and gather test results, cache everything statically.
  if (is_null($tests)) {
    $module_path = drupal_get_path('module', 'acquia_purge');
    $prefix = '_acquia_purge_get_diagnosis_';
    $tests = array();
    $t = get_t();

    // Require the file that contains our tests: acquia_purge.diagnostics.inc.
    require_once $module_path . '/acquia_purge.diagnostics.inc';

    // Similar to hooks, functions starting with "_acquia_purge_get_diagnosis_"
    // will be regarded as individual tests and called to gather results.
    $functions = get_defined_functions();
    foreach ($functions['user'] as $function) {
      if ($function === '_acquia_purge_get_diagnosis_logged') {
        continue;
      }
      elseif (strpos($function, $prefix) !== 0) {
        continue;
      }

      // Add the test and its resulting data to the tests array.
      $tst = str_replace($prefix, 'acquia_purge_', $function);
      $tests[$tst] = $function($t);

      // Overwrite or assure data integrity on most of the fields.
      $tests[$tst]['name'] = isset($tests[$tst]['title']) ? $tests[$tst]['title'] : $tst;
      $tests[$tst]['description'] = isset($tests[$tst]['description']) ? $tests[$tst]['description'] : NULL;
      $tests[$tst]['description_plain'] = strip_tags($tests[$tst]['description']);
      $tests[$tst]['severity'] = isset($tests[$tst]['severity']) ? $tests[$tst]['severity'] : ACQUIA_PURGE_SEVLEVEL_INFO;
      $tests[$tst]['value_plain'] = isset($tests[$tst]['value_plain']) ? $tests[$tst]['value_plain'] : $tests[$tst]['value'];
      $tests[$tst]['value_plain'] = $t('@title: @value', array(
        '@title' => $tests[$tst]['title'],
        '@value' => $tests[$tst]['value_plain'],
      ));
      $tests[$tst]['value'] = $t('<b>@title</b><br />@value', array(
        '@title' => $tests[$tst]['title'],
        '@value' => $tests[$tst]['value'],
      ));
      $tests[$tst]['title'] = $t('Acquia Purge');
    }
  }

  // Return test results that match or are higher than the verbosity level.
  $results = array();
  foreach ($tests as $name => $result) {
    if ($result['severity'] >= $verbosity) {
      $results[$name] = $result;
    }
  }
  return $results;
}