git_deploy.install in Git Deploy 7
Same filename and directory in other branches
Checks that site can get version information with Git.
File
git_deploy.installView source
<?php
/**
* @file
* Checks that site can get version information with Git.
*/
/**
* Throws glip library errors.
*/
function git_deploy_glip_bug($errno, $errstr, $errfile, $errline, $errcontext) {
// $m is set in an assert line, so if it is missing, assertions are disabled.
if (!isset($errcontext['m'])) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
}
/**
* Implements hook_requirements().
*/
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 ($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;
}
/**
* Save current location of glip library.
*/
function git_deploy_update_7000() {
if (!module_exists('libraries')) {
$glip_path = drupal_get_path('module', 'git_deploy') . '/glip';
if (file_exists("{$glip_path}/lib/glip.php")) {
variable_set('git_deploy_glip_path', $glip_path);
}
}
}
Functions
Name![]() |
Description |
---|---|
git_deploy_glip_bug | Throws glip library errors. |
git_deploy_requirements | Implements hook_requirements(). |
git_deploy_update_7000 | Save current location of glip library. |