You are here

function git_deploy_requirements in Git Deploy 6

Same name and namespace in other branches
  1. 8.2 git_deploy.install \git_deploy_requirements()
  2. 6.2 git_deploy.install \git_deploy_requirements()
  3. 7.2 git_deploy.install \git_deploy_requirements()
  4. 7 git_deploy.install \git_deploy_requirements()

Implements hook_requirements().

File

./git_deploy.install, line 21
Checks that site can get version information with Git.

Code

function git_deploy_requirements($phase) {
  $requirements = array();

  // Check for glip library.
  if (module_exists('libraries')) {
    $glip_path = libraries_get_path('glip') . '/lib/glip.php';
  }
  else {
    $glip_path = variable_get('git_deploy_glip_path', 'sites/all/libraries/glip') . '/lib/glip.php';
  }
  $file_exists = file_exists($glip_path);
  switch ($phase) {
    case 'runtime':
      if (module_exists('update') && !module_exists('mydropwizard')) {
        $requirements['git_deploy_update'] = array(
          'title' => t('Unsupported <em>Update status</em> module is installed.'),
          'value' => t('Conflict'),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('Drupal 6 has reached its community End-of-Life (EOL) date and is now in a Long-Term Support (LTS) phase, where support is provided by a <a href="http://drupal.org/project/d6lts">small group of vendors</a>. To get accurate update status information, enable the <a href="https://www.drupal.org/project/mydropwizard">myDropWizard</a> module.'),
        );
      }
      if ($file_exists) {

        // Check for glip library assertion bug.
        try {
          set_error_handler('git_deploy_glip_bug');
          require_once $glip_path;
          $author = new GitCommitStamp();

          // This should be parsed without errors if PHP assertions are enabled.
          $author
            ->unserialize('name <mail> 0 +0000');
        } catch (ErrorException $e) {
          $requirements['git_deploy_assert'] = array(
            'title' => t('Assertions'),
            'value' => t('Disabled'),
            'description' => t('The glip library required by this version of Git Deploy uses PHP assertions for checking commit dates.'),
            'severity' => REQUIREMENT_WARNING,
          );

          // Try to find the reason for the error.
          if (version_compare(PHP_VERSION, '7', '<') && !ini_get('assert.active')) {
            $directive = '<a href="https://php.net/manual/en/info.configuration.php#ini.assert.active">assert.active</a>';
          }
          elseif (ini_get('zend.assertions') != 1) {
            $directive = '<a href="https://php.net/manual/en/ini.core.php#ini.zend.assertions">zend.assertions</a>';
          }

          // If we know the reason for the error, tell the user how to fix it.
          if (isset($directive)) {
            $requirements['git_deploy_assert']['description'] .= ' ' . t('Set !directive to 1 and reload PHP.', array(
              '!directive' => $directive,
            ));
          }
        } finally {
          restore_error_handler();
        }
      }
    case 'install':
      $requirements['git_deploy_glip'] = array(
        'title' => t('glip library'),
        'value' => $file_exists ? t('glip library exists.') : t('Git Deploy requires the glip library to function properly. The simplest way to install glip is by using using the Drush command <code>drush git-deploy-download</code>. Alternatively it can be acquired by methods found in <a href="!readme">README.txt</a>.', array(
          '!readme' => url(drupal_get_path('module', 'git_deploy') . '/README.txt'),
        )),
        'description' => $file_exists ? '' : t('The glip library must be present to use Git Deploy.'),
        'severity' => $file_exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
      );
      break;
  }
  return $requirements;
}