You are here

function acsf_sj_requirements in Acquia Cloud Site Factory Connector 8.2

Same name and namespace in other branches
  1. 8 acsf_sj/acsf_sj.install \acsf_sj_requirements()

Implements hook_requirements().

File

acsf_sj/acsf_sj.install, line 13
Provides requirements for installing the ACSF Scheduled Jobs module.

Code

function acsf_sj_requirements($phase) {
  $requirements = [];
  if ($phase == 'install' || $phase == 'runtime') {
    $binary_path = _acsf_sj_install_get_sjadd_path();
    if ($binary_path == NULL) {
      $requirements['acsf_sj_sjadd'] = [
        'title' => 'ACSF SJ binary',
        'severity' => REQUIREMENT_WARNING,
        'description' => 'The installation path for the ACSF SJ binary cannot be determined.',
      ];
    }
    elseif (!is_executable($binary_path)) {
      $requirements['acsf_sj_sjadd'] = [
        'title' => 'ACSF SJ binary validation',
        'severity' => REQUIREMENT_WARNING,
        'description' => "{$binary_path} is not executable.",
      ];
    }
    else {
      $process = new Process($binary_path);
      $success = FALSE;
      $message = '';
      try {
        $process
          ->run();
        $stdout = $process
          ->getOutput();
        $stderr = $process
          ->getErrorOutput();
        if (strpos($stderr, "Usage: {$binary_path}") !== FALSE) {
          $success = TRUE;
        }
        else {
          $message = 'exit code: ' . $process
            ->getExitCode() . "\nstdout: {$stdout}\nstderr: {$stderr}";
        }
      } catch (\Exception $e) {
        $message = $e
          ->getMessage();
        $success = FALSE;
      }
      if (!$success) {
        $requirements['acsf_sj_sjadd_execution'] = [
          'title' => 'ACSF SJ sjadd execution',
          'severity' => REQUIREMENT_WARNING,
          'description' => 'The binary "sjadd" cannot be executed: ' . $message,
        ];
      }
    }
  }
  return $requirements;
}