function git_deploy_system_info_alter in Git Deploy 8.2
Same name and namespace in other branches
- 6.2 git_deploy.module \git_deploy_system_info_alter()
- 6 git_deploy.module \git_deploy_system_info_alter()
- 7.2 git_deploy.module \git_deploy_system_info_alter()
- 7 git_deploy.module \git_deploy_system_info_alter()
Implements hook_system_info_alter().
File
- ./
git_deploy.module, line 20 - Adds project, version and date information to projects checked out with Git.
Code
function git_deploy_system_info_alter(array &$info, Extension $file, $type) {
// Use drupal_static() so we can free up memory from static variables later.
$projects =& drupal_static(__FUNCTION__ . ':projects', []);
$available =& drupal_static(__FUNCTION__ . ':available');
$update =& drupal_static(__FUNCTION__ . ':update', []);
// Core has hard-coded version numbers, so we need to verify them. Otherwise,
// a valid version number indicates that this project was not installed with
// Git.
if (empty($info['hidden']) && (empty($info['version']) || ($file->origin == 'core' ? strstr($info['version'], '-dev') == '-dev' : $info['version'] == \Drupal::VERSION || !preg_match('/^\\d\\..+\\..+/', $info['version'])))) {
// Work around bug that causes Git to fail for users without home directory.
$home = getenv('HOME') === FALSE ? 'HOME=' . DRUPAL_ROOT . ' ' : '';
// Verify that we are in a Git repository. For core, also verify that this
// is really a Drupal repository.
$directory = exec($home . 'git -C ' . escapeshellarg($file
->getPath()) . ' rev-parse --show-toplevel 2> ' . GIT_DEPLOY_ERROR_DUMP);
if (!empty($directory) && ($file->origin != 'core' || in_array($directory, [
DRUPAL_ROOT,
DRUPAL_ROOT . '/core',
]))) {
// Only check Git once per repository.
if (!isset($projects[$directory])) {
$projects[$directory] = [];
// Make sure Git operates in the right directory.
$git = $home . 'git -C ' . escapeshellarg($directory);
// Ensure file is in repository.
if (exec("{$git} ls-files " . escapeshellarg(str_replace("{$directory}/", '', realpath($file
->getPathname()))) . ' 2> ' . GIT_DEPLOY_ERROR_DUMP)) {
// Get upstream info.
$upstream = _git_deploy_get_upstream($git, $file->origin == 'core' ? [
'8.*',
'9.*',
] : [
'*.*',
]);
if ($file->origin == 'core') {
$project_name = 'drupal';
}
elseif (isset($upstream['remote'])) {
// Find the project name based on fetch URL.
$fetch_url = exec("{$git} config --get " . escapeshellarg("remote.{$upstream['remote']}.url") . ' 2> ' . GIT_DEPLOY_ERROR_DUMP);
if (!empty($fetch_url)) {
$project_name = basename($fetch_url, '.git');
$projects[$directory]['project'] = $project_name;
}
}
// Set project datestamp.
if (isset($upstream['datestamp'])) {
$projects[$directory]['datestamp'] = $upstream['datestamp'];
// The '_info_file_ctime' should always get the latest value.
if (empty($info['_info_file_ctime'])) {
$projects[$directory]['_info_file_ctime'] = $upstream['datestamp'];
}
else {
$projects[$directory]['_info_file_ctime'] = max($info['_info_file_ctime'], $upstream['datestamp']);
}
}
// Set version from tag.
if (isset($upstream['tag'])) {
$projects[$directory]['version'] = $upstream['tag'];
}
elseif (isset($upstream['branch'])) {
if ($upstream['branch'] != 'master') {
$projects[$directory]['version'] = "{$upstream['branch']}-dev";
}
if (\Drupal::moduleHandler()
->moduleExists('update') && ($upstream['synced'] || $upstream['branch'] == 'master')) {
if (!isset($available)) {
// We only get this from the cache because an update status
// query is supposed to done only after processing all enabled
// modules and themes.
$available = \Drupal::keyValueExpirable('update_available_releases')
->getAll();
}
if (!empty($available[$project_name]['releases'])) {
if ($upstream['branch'] == 'master') {
// If there's available update_status data, we can use the
// version string the release node pointing to HEAD really
// has.
foreach ($available[$project_name]['releases'] as $release) {
if (isset($release['tag']) && $release['tag'] == 'HEAD') {
$projects[$directory]['version'] = $release['version'];
break;
}
}
}
if ($upstream['synced']) {
// This project's datestamp needs to be synced with upstream
// release.
$version = $projects[$directory]['version'];
if (!isset($available[$project_name]['releases'][$version]) || $projects[$directory]['_info_file_ctime'] > $available[$project_name]['last_fetch']) {
// We need to update available release data for this
// project.
$update[] = $project_name;
}
else {
_git_deploy_datestamp_sync($projects[$directory], $available[$project_name]['releases'][$version]);
}
}
}
}
}
}
}
$info = $projects[$directory] + $info;
}
}
}