Commit 9f2b6a5d authored by helmo's avatar helmo

Issue #2650290: Search for packages in D8 profiles under subdirs. (Merge...

Issue #2650290: Search for packages in D8 profiles under subdirs. (Merge branch 'dev/2650290' into 7.x-3.x)
parents d597cfe0 323d4826
...@@ -193,3 +193,80 @@ function _provision_drupal_system_map() { ...@@ -193,3 +193,80 @@ function _provision_drupal_system_map() {
drush_log(dt("Found !count themes", array('!count' => sizeof($packages['themes'])))); drush_log(dt("Found !count themes", array('!count' => sizeof($packages['themes']))));
return $packages; return $packages;
} }
/**
* Find available profiles on this platform.
*/
function _provision_find_profiles() {
$profiles = array();
include_once('includes/install.inc');
$profiles_subdirs[] = "./profiles";
foreach($profiles_subdirs as $profiles_subdir) {
if (!$dir = opendir($profiles_subdir)) {
drush_log(dt("Cannot find profiles directory"), 'error');
return FALSE;
}
while (FALSE !== ($name = readdir($dir))) {
$languages = array();
if (($name == '..') || ($name == '.') || (!is_dir("$profiles_subdir/$name"))) {
continue;
}
$profile = new stdClass();
$profile->name = $name;
$profile->info = array();
$info_file = "$profiles_subdir/$name/$name.info";
if (file_exists($info_file)) {
$profile->info = provision_parse_info_file($info_file);
// Skip hidden profiles
if (isset($profile->info['hidden']) && $profile->info['hidden'] == 1) {
continue;
}
}
$profile->filename = $info_file;
// Include code from the profile.
if (file_exists($profile_file = "$profiles_subdir/$name/$name.profile")) {
require_once($profile_file);
}
$func = $profile->name . "_profile_details";
if (function_exists($func)) {
$profile->info = array_merge($profile->info, $func());
}
$profile_path = $profiles_subdir . '/' . $name;
$profile->info['languages'] = _provision_find_profile_languages($profile_path);
$profiles[$name] = $profile;
drush_log(dt('Found install profile %name', array('%name' => $name)));
}
}
return $profiles;
}
/**
* Retrieve a list of paths to search in a certain scope
*/
function _provision_drupal_search_paths($scope, $key = '', $type = 'modules') {
$searchpaths = array();
$drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
switch ($scope) {
case 'base' :
$searchpaths[] = sprintf("%s/%s", $drupal_root, $type);
$searchpaths[] = sprintf("%s/sites/all/%s", $drupal_root, $type);
break;
default :
if ($key) {
$searchpaths[] = sprintf("%s/%s/%s/%s", $drupal_root, $scope, $key, $type);
}
break;
}
return $searchpaths;
}
...@@ -204,3 +204,86 @@ function _provision_drupal_system_map() { ...@@ -204,3 +204,86 @@ function _provision_drupal_system_map() {
drush_log(dt("Found !count themes", array('!count' => sizeof($packages['themes'])))); drush_log(dt("Found !count themes", array('!count' => sizeof($packages['themes']))));
return $packages; return $packages;
} }
/**
* Find available profiles on this platform.
*/
function _provision_find_profiles() {
$profiles = array();
include_once('includes/install.inc');
$profiles_subdirs[] = "./profiles";
foreach($profiles_subdirs as $profiles_subdir) {
if (!$dir = opendir($profiles_subdir)) {
drush_log(dt("Cannot find profiles directory"), 'error');
return FALSE;
}
while (FALSE !== ($name = readdir($dir))) {
$languages = array();
if (($name == '..') || ($name == '.') || (!is_dir("$profiles_subdir/$name"))) {
continue;
}
$profile = new stdClass();
$profile->name = $name;
$profile->info = array();
$info_file = "$profiles_subdir/$name/$name.info";
if (file_exists($info_file)) {
$profile->info = provision_parse_info_file($info_file);
// Skip hidden profiles
if (isset($profile->info['hidden']) && $profile->info['hidden'] == 1) {
continue;
}
}
$profile->filename = $info_file;
// Include code from the profile.
if (file_exists($profile_file = "$profiles_subdir/$name/$name.profile")) {
require_once($profile_file);
}
$func = $profile->name . "_profile_details";
if (function_exists($func)) {
$profile->info = array_merge($profile->info, $func());
}
$profile_path = $profiles_subdir . '/' . $name;
$profile->info['languages'] = _provision_find_profile_languages($profile_path);
// Drupal 7 renamed the default install profile to 'standard'
// Aegir now allows projects to specify an "old short name" to provide an upgrade path when projects get renamed.
if ($profile->name == 'standard') {
$profile->info['old_short_name'] = 'default';
}
$profiles[$name] = $profile;
drush_log(dt('Found install profile %name', array('%name' => $name)));
}
}
return $profiles;
}
/**
* Retrieve a list of paths to search in a certain scope
*/
function _provision_drupal_search_paths($scope, $key = '', $type = 'modules') {
$searchpaths = array();
$drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
switch ($scope) {
case 'base' :
$searchpaths[] = sprintf("%s/%s", $drupal_root, $type);
$searchpaths[] = sprintf("%s/sites/all/%s", $drupal_root, $type);
break;
default :
if ($key) {
$searchpaths[] = sprintf("%s/%s/%s/%s", $drupal_root, $scope, $key, $type);
}
break;
}
return $searchpaths;
}
...@@ -113,3 +113,64 @@ function _provision_system_query($type) { ...@@ -113,3 +113,64 @@ function _provision_system_query($type) {
return $packages; return $packages;
} }
/**
* Find available profiles on this platform.
*/
function _provision_find_profiles() {
$profile_dirs = array('./core/profiles', './profiles');
$profiles = array();
foreach($profile_dirs as $profile_dir) {
if (!is_dir($profile_dir)) {
drush_log(dt("Cannot find profiles directory %dir", array('%dir' => $profile_dir)), 'error');
return FALSE;
}
$info_files = drush_scan_directory($profile_dir, "/\.info.yml$/");
foreach ($info_files as $path => $info_file) {
$path = realpath($path);
$info = Symfony\Component\Yaml\Yaml::parse($path);
if ($info['type'] == 'profile' && (!isset($info['hidden']) || !$info['hidden'])) {
$profile = new stdClass();
$profile->name = $info['name'];
$profile->info = $info;
$profile->filename = $path;
$profile->path = dirname($path);
$profile->info['languages'] = _provision_find_profile_languages($profile->path);
$profiles[basename($profile->path)] = $profile;
drush_log(dt('Found install profile %name', array('%name' => $name)));
}
}
}
return $profiles;
}
/**
* Retrieve a list of paths to search in a certain scope
*/
function _provision_drupal_search_paths($scope, $key = '', $type = 'modules') {
$searchpaths = array();
$drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
switch ($scope) {
case 'base':
$searchpaths[] = sprintf("%s/%s", $drupal_root, $type);
$searchpaths[] = sprintf("%s/core/%s", $drupal_root, $type);
$searchpaths[] = sprintf("%s/sites/all/%s", $drupal_root, $type);
break;
case 'profiles':
foreach (_provision_find_profiles() as $profile) {
$searchpaths[] = $profile->path;
}
break;
default:
if ($key) {
$searchpaths[] = sprintf("%s/%s/%s/%s", $drupal_root, $scope, $key, $type);
}
break;
}
return $searchpaths;
}
...@@ -372,105 +372,6 @@ function _provision_drupal_rebuild_caches() { ...@@ -372,105 +372,6 @@ function _provision_drupal_rebuild_caches() {
} }
} }
/**
* Find available profiles on this platform.
*/
function _provision_find_profiles() {
$profiles = array();
if (drush_drupal_major_version() >= 8) {
include_once('core/includes/install.inc');
$profiles_subdirs[] = "./core/profiles";
$profiles_subdirs[] = "./profiles";
}
else {
include_once('includes/install.inc');
$profiles_subdirs[] = "./profiles";
}
foreach($profiles_subdirs as $profiles_subdir) {
if (!$dir = opendir($profiles_subdir)) {
drush_log(dt("Cannot find profiles directory"), 'error');
return FALSE;
}
while (FALSE !== ($name = readdir($dir))) {
$languages = array();
if (($name == '..') || ($name == '.') || (!is_dir("$profiles_subdir/$name"))) {
continue;
}
$profile = new stdClass();
$profile->name = $name;
$profile->info = array();
if (drush_drupal_major_version() >= 8) {
$yaml_file = "$profiles_subdir/$name/$name.info.yml";
if(!file_exists($yaml_file)) {
drush_log(dt("@name.info.yml not found.", array("@name" => $name)), 'notice');
unset($files[$name]);
continue;
}
$profile->info = Symfony\Component\Yaml\Yaml::parse($yaml_file);
// Skip hidden profiles.
if (isset($profile->info['hidden']) && $profile->info['hidden'] == 1) {
continue;
}
if (!empty($profile->info['name'])) {
$profile->name = $profile->info['name'];
}
$profile->filename = $yaml_file;
}
else {
$info_file = "$profiles_subdir/$name/$name.info";
if (file_exists($info_file)) {
$profile->info = provision_parse_info_file($info_file);
// Skip hidden profiles
if (isset($profile->info['hidden']) && $profile->info['hidden'] == 1) {
continue;
}
}
$profile->filename = $info_file;
}
// Include code from the profile.
if (file_exists($profile_file = "$profiles_subdir/$name/$name.profile")) {
require_once($profile_file);
}
$func = $profile->name . "_profile_details";
if (function_exists($func)) {
$profile->info = array_merge($profile->info, $func());
}
$languages['en'] = 1;
// Find languages available
$files = array_keys(drush_scan_directory($profiles_subdir . '/' . $name . '/translations', '/\.po$/', array('.', '..', 'CVS'), 0, FALSE, 'filepath'));
$files = array_merge($files, array_keys(drush_scan_directory($profiles_subdir . '/' . $name , '/\.po$/', array('.', '..', 'CVS'), 0, FALSE, 'filepath')));
if (is_array($files)) {
foreach ($files as $file) {
if (preg_match('!(/|\.)([^\./]+)\.po$!', $file, $langcode)) {
$languages[$langcode[2]] = 1; // use the language name as an index to weed out duplicates
}
}
}
$profile->info['languages'] = array_keys($languages);
// Drupal 7 renamed the default install profile to 'standard'
// Aegir now allows projects to specify an "old short name" to provide an upgrade path when projects get renamed.
if ($profile->name == 'standard') {
$profile->info['old_short_name'] = 'default';
}
$profiles[$name] = $profile;
drush_log(dt('Found install profile %name', array('%name' => $name)));
}
}
return $profiles;
}
function provision_drupal_find_sites() { function provision_drupal_find_sites() {
$sites = array(); $sites = array();
if ($dir = opendir("./sites")) { if ($dir = opendir("./sites")) {
...@@ -640,28 +541,6 @@ function provision_drupal_system_map() { ...@@ -640,28 +541,6 @@ function provision_drupal_system_map() {
return _provision_drupal_system_map(); return _provision_drupal_system_map();
} }
/**
* Retrieve a list of paths to search in a certain scope
*/
function _provision_drupal_search_paths($scope, $key = '', $type = 'modules') {
$searchpaths = array();
$drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
switch ($scope) {
case 'base' :
$searchpaths[] = sprintf("%s/%s", $drupal_root, $type);
$searchpaths[] = sprintf("%s/core/%s", $drupal_root, $type);
$searchpaths[] = sprintf("%s/sites/all/%s", $drupal_root, $type);
break;
default :
if ($key) {
$searchpaths[] = sprintf("%s/%s/%s/%s", $drupal_root, $scope, $key, $type);
}
break;
}
return $searchpaths;
}
/** /**
* Find modules in a certain scope. * Find modules in a certain scope.
* *
...@@ -847,3 +726,25 @@ function _provision_client_delete_symlink() { ...@@ -847,3 +726,25 @@ function _provision_client_delete_symlink() {
->fail('Failed to delete symlink @path: @reason'); ->fail('Failed to delete symlink @path: @reason');
} }
} }
/**
* Find available languages for a profile.
*/
function _provision_find_profile_languages($profile_path) {
$languages = array();
// English is default.
$languages['en'] = 1;
// Find languages available.
$files = array_keys(drush_scan_directory($profile_path . '/translations', '/\.po$/', array('.', '..', 'CVS'), 0, FALSE, 'filepath'));
$files = array_merge($files, array_keys(drush_scan_directory($profile_path, '/\.po$/', array('.', '..', 'CVS'), 0, FALSE, 'filepath')));
if (is_array($files)) {
foreach ($files as $file) {
if (preg_match('!(/|\.)([^\./]+)\.po$!', $file, $langcode)) {
$languages[$langcode[2]] = 1; // use the language name as an index to weed out duplicates
}
}
}
return array_keys($languages);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment