ProjectInfoTrait.php in Automatic Updates 7
File
ProjectInfoTrait.php
View source
<?php
trait ProjectInfoTrait {
protected static function getInfos() {
$infos = [];
$extensions = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\\.info$/', 'modules', $key = 'name', $min_depth = 1);
$extensions = array_merge($extensions, drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\\.info$/', 'themes', $key = 'name', $min_depth = 1));
foreach ($extensions as $extension) {
if (file_exists($info_file = dirname($extension->uri) . '/' . $extension->name . '.info')) {
$infos[$extension->name] = drupal_parse_info_file($info_file);
$info =& $infos[$extension->name];
$info['packaged'] = isset($info['project']) ? $info['project'] : FALSE;
$info['install path'] = dirname($extension->uri);
$info['project'] = self::getProjectName($extension->name, $info);
$info['version'] = self::getExtensionVersion($info);
}
}
$system = isset($infos['system']) ? $infos['system'] : NULL;
$infos = array_filter($infos, static function (array $info, $project_name) {
return $info && $info['project'] === $project_name;
}, ARRAY_FILTER_USE_BOTH);
if ($system) {
$infos['drupal'] = $system;
}
return $infos;
}
protected static function getProjectName($extension_name, array $info) {
$project_name = $extension_name;
if (isset($info['project'])) {
$project_name = $info['project'];
}
if (strpos($info['install path'], 'modules') === 0) {
$project_name = 'drupal';
}
if (strpos($info['install path'], 'themes') === 0) {
$project_name = 'drupal';
}
return $project_name;
}
protected static function getExtensionVersion(array $info) {
$extension_name = $info['project'];
if (isset($info['version']) && strpos($info['version'], '-dev') === FALSE) {
return $info['version'];
}
watchdog('automatic_updates', 'Version cannot be located for @extension', [
'@extension' => $extension_name,
], WATCHDOG_ERROR);
return NULL;
}
}