From b46237f453be6d28149f14240bd56adfef4b5f55 Mon Sep 17 00:00:00 2001 From: Adrian Rossouw Date: Sat, 28 Mar 2009 17:35:46 +0000 Subject: [PATCH] #368294 - replacement package checking functions. --- platform/drupal_5_packages.inc | 59 +++++++++ platform/drupal_packages.inc | 110 ++++++++++++++++ platform/install.provision.inc | 1 + platform/provision_drupal.drush.inc | 195 +++++++++++++++------------- platform/verify.provision.inc | 16 +-- 5 files changed, 280 insertions(+), 101 deletions(-) create mode 100644 platform/drupal_5_packages.inc create mode 100644 platform/drupal_packages.inc diff --git a/platform/drupal_5_packages.inc b/platform/drupal_5_packages.inc new file mode 100644 index 00000000..32f11dbe --- /dev/null +++ b/platform/drupal_5_packages.inc @@ -0,0 +1,59 @@ + $file) { + $files[$name] = $file; + } + foreach ($templates as $filename => $file) { + // The directory in which the template is stored is the name of the theme. + $name = basename(dirname($filename)); + $file->template = TRUE; + $file->engine = 'phptemplate'; + $files[$name] = $file; + } + foreach ($files as $name => $theme) { + // Now that we have the themes, let's get the sub styles. + foreach (drush_scan_directory(dirname($theme->filename), 'style.css$') as $style) { + $style->style = TRUE; + $style->template = isset($theme->template) ? $theme->template : FALSE; + $style->name = basename(dirname($style->filename)); + $style->owner = $theme->filename; + if (array_key_exists($style->name, $files)) { + continue; + } + $files[$style->name] = $style; + } + } + + foreach ($files as $name => $file) { + // Now we get the information about the themes and styles from cvs_deploy + _provision_cvs_deploy($files[$name]); + } + + return $files; +} diff --git a/platform/drupal_packages.inc b/platform/drupal_packages.inc new file mode 100644 index 00000000..f7f8a76a --- /dev/null +++ b/platform/drupal_packages.inc @@ -0,0 +1,110 @@ + $file) { + $files[$name]->info = _provision_drupal_parse_info_file($file->filename); + if (!empty($files[$name]->info['name'])) { + $files[$name]->name = $files[$name]->info['name']; + } + if (empty($files[$name]->info['engine'])) { + $filename = dirname($files[$name]->filename) .'/'. $files[$name]->name .'.theme'; + if (file_exists($filename)) { + $files[$name]->owner = $filename; + $files[$name]->prefix = $name; + } + } + else { + $engine = $files[$name]->info['engine']; + if (isset($engines[$engine])) { + $files[$name]->owner = $engines[$engine]->filename; + $files[$name]->prefix = $engines[$engine]->name; + $files[$name]->template = TRUE; + } + } + _provision_cvs_deploy($files[$name]); + } + return $files; +} + +/** + * This code is based on the Drupal 6 and Drupal 7 drupal_parse_info_file + */ +function _provision_drupal_parse_info_file($filename) { + $info = array(); + + if (!file_exists($filename)) { + return $info; + } + + $data = file_get_contents($filename); + if (preg_match_all(' + @^\s* # Start at the beginning of a line, ignoring leading whitespace + ((?: + [^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets, + \[[^\[\]]*\] # unless they are balanced and not nested + )+?) + \s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space) + (?: + ("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes + (\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes + ([^\r\n]*?) # Non-quoted string + )\s*$ # Stop at the next end of a line, ignoring trailing whitespace + @msx', $data, $matches, PREG_SET_ORDER)) { + foreach ($matches as $match) { + // Fetch the key and value string + $i = 0; + foreach (array('key', 'value1', 'value2', 'value3') as $var) { + $$var = isset($match[++$i]) ? $match[$i] : ''; + } + $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3; + + // Parse array syntax + $keys = preg_split('/\]?\[/', rtrim($key, ']')); + $last = array_pop($keys); + $parent = &$info; + + // Create nested arrays + foreach ($keys as $key) { + if ($key == '') { + $key = count($parent); + } + if (!isset($parent[$key]) || !is_array($parent[$key])) { + $parent[$key] = array(); + } + $parent = &$parent[$key]; + } + + // Handle PHP constants + if (defined($value)) { + $value = constant($value); + } + + // Insert actual value + if ($last == '') { + $last = count($parent); + } + $parent[$last] = $value; + } + } + + return $info; +} + diff --git a/platform/install.provision.inc b/platform/install.provision.inc index 3d4fcbfb..a58bdca0 100644 --- a/platform/install.provision.inc +++ b/platform/install.provision.inc @@ -61,5 +61,6 @@ function provision_drupal_provision_post_install($url) { _provision_drupal_maintain_aliases($url); provision_path("chmod", "./sites/$url/settings.php", 0440, dt("Secured settings.php with safe permissions")); _provision_drupal_rebuild_caches($url); + drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site'); } diff --git a/platform/provision_drupal.drush.inc b/platform/provision_drupal.drush.inc index fd2fef23..c0b29028 100644 --- a/platform/provision_drupal.drush.inc +++ b/platform/provision_drupal.drush.inc @@ -269,6 +269,7 @@ function _provision_find_profiles() { $profile->name = $name; $profile->filename = $file; + _provision_cvs_deploy($profile); require_once($profile->filename); $func = $profile->name . "_profile_details"; if (function_exists($func)) { @@ -288,7 +289,7 @@ function _provision_find_profiles() { } $profile->info['languages'] = array_keys($languages); $return[$name] = $profile; - drush_log(dt('found install profile %name', array('%name' => $name))); + drush_log(dt('Found install profile %name', array('%name' => $name))); } return $return; @@ -380,27 +381,115 @@ function provision_drupal_install_log($ret) { require_once('cvs_deploy.inc'); function provision_find_packages() { - $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT'); - $searchpaths[] = sprintf("%s/modules", $drupal_root); - $searchpaths[] = sprintf("%s/sites/all/modules", $drupal_root); - $packages['core']['modules'] = provision_parse_packages($searchpaths); - $profiles = drush_get_option('profiles', array()); + // Load the version specific include files. + provision_platform_include(dirname(__FILE__), 'packages'); + + $packages['base'] = _provision_find_packages('base'); + + // Create a package for the Drupal release + $packages['base']['platforms'] = _provision_find_platforms(); + + // Find install profiles. + $profiles = _provision_find_profiles(); + drush_set_option('profiles', array_keys((array) $profiles), 'drupal'); + $packages['base']['profiles'] = _scrub_object($profiles); + + // Iterate through the install profiles, finding the profile specific packages foreach ($profiles as $profile => $info) { - $searchpaths = array(); - $searchpaths[] = sprintf("%s/profiles/%s/modules", $drupal_root, $profile); - $packages['profiles'][$profile]['modules'] = provision_parse_packages($searchpaths); + $packages['profiles'][$profile] = _provision_find_packages('profiles', $profile); + } + + // Iterate through the sites, finding site specific packages + foreach (drush_get_option('sites', array()) as $site) { + $packages['sites'][$site] = _provision_find_packages('sites', $site); } - $sites = drush_get_option('sites', array()); - foreach ($sites as $site) { - $searchpaths = array(); - $searchpaths[] = sprintf("%s/sites/%s/modules", $drupal_root, $site); - $packages['sites'][$site]['modules'] = provision_parse_packages($searchpaths); + return $packages; +} + +function _provision_find_platforms() { + return array( + 'drupal' => array( + 'short_name' => 'drupal', 'version' => drush_drupal_version(), + 'description' => dt("This platform is running @short_name @version", array('@short_name' => 'Drupal', '@version' => VERSION)))); +} + +/** + * A small helper function to reduce code duplication + */ +function _provision_find_packages($scope, $key = '') { + $scope_text = ($key) ? "$scope/$key" : $scope; + foreach (array('modules', 'themes') as $type) { + $func = "_provision_drupal_find_$type"; + $result = $func($scope, $key); + if (sizeof($result)) { + $packages[$type] = $result; + drush_log(dt("Found !count !type in !scope", + array('!count' => sizeof($result), + '!scope' => $scope_text, '!type' => $type))); + } } return $packages; } +/** + * Map the system table to a packages multi-dimensional array component + */ +function provision_drupal_system_map() { + $profile = drush_get_option('profile'); + $profiles = _provision_find_profiles(); + + $packages['platforms'] = _provision_find_platforms(); + $packages['profiles'][$profile] = $profiles[$profile]; + $packages['profiles'][$profile]->status = 1; + + $result = db_query("SELECT * FROM {system} WHERE type='module'"); + while ($module = db_fetch_object($result)) { + _provision_cvs_deploy($module); + $module->filename = realpath($module->filename); + $packages['modules'][$module->name] = $module; + } + + drush_log(dt("Found !count modules", array('!count' => sizeof($packages['modules'])))); + + $result = db_query("SELECT * FROM {system} WHERE type='theme'"); + while ($theme = db_fetch_object($result)) { + _provision_cvs_deploy($theme); + $theme->filename = realpath($theme->filename); + $packages['themes'][$theme->name] = $theme; + } + drush_log(dt("Found !count themes", array('!count' => sizeof($packages['themes'])))); + return $packages; +} + +/** + * 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; +} -function provision_parse_packages($paths, $type = 'module') { +/** + * Find modules in a certain scope. + * + * This function is general enough that it works for all supported + * versions of Drupal. + */ +function _provision_drupal_find_modules($scope, $key = '') { + $paths = _provision_drupal_search_paths($scope, $key, 'modules'); $files = array(); foreach ($paths as $path) { $files = array_merge($files, drush_scan_directory($path, ".module$", array('.', '..', 'CVS', '.svn'), 0, true, 'name')); @@ -427,11 +516,10 @@ function provision_parse_packages($paths, $type = 'module') { return $files; } - function provision_parse_info_file($filename) { $info = array(); - $defaults = array( + $defaults = array( 'dependencies' => array(), 'description' => '', 'version' => NULL, @@ -439,81 +527,10 @@ function provision_parse_info_file($filename) { ); if (file_exists($filename)) { - - switch (drush_drupal_major_version()) { - case 5 : - $info = parse_ini_file($filename); - break; - default : - $info = _provision_drupal_parse_info_file($filename); - break; - } + $info = _provision_drupal_parse_info_file($filename); } // Merge in defaults and return return $info + $defaults; } -/** - * This code is based on the Drupal 6 and Drupal 7 drupal_parse_info_file - */ -function _provision_drupal_parse_info_file($filename) { - $info = array(); - - if (!file_exists($filename)) { - return $info; - } - - $data = file_get_contents($filename); - if (preg_match_all(' - @^\s* # Start at the beginning of a line, ignoring leading whitespace - ((?: - [^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets, - \[[^\[\]]*\] # unless they are balanced and not nested - )+?) - \s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space) - (?: - ("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes - (\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes - ([^\r\n]*?) # Non-quoted string - )\s*$ # Stop at the next end of a line, ignoring trailing whitespace - @msx', $data, $matches, PREG_SET_ORDER)) { - foreach ($matches as $match) { - // Fetch the key and value string - $i = 0; - foreach (array('key', 'value1', 'value2', 'value3') as $var) { - $$var = isset($match[++$i]) ? $match[$i] : ''; - } - $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3; - - // Parse array syntax - $keys = preg_split('/\]?\[/', rtrim($key, ']')); - $last = array_pop($keys); - $parent = &$info; - - // Create nested arrays - foreach ($keys as $key) { - if ($key == '') { - $key = count($parent); - } - if (!isset($parent[$key]) || !is_array($parent[$key])) { - $parent[$key] = array(); - } - $parent = &$parent[$key]; - } - - // Handle PHP constants - if (defined($value)) { - $value = constant($value); - } - - // Insert actual value - if ($last == '') { - $last = count($parent); - } - $parent[$last] = $value; - } - } - - return $info; -} diff --git a/platform/verify.provision.inc b/platform/verify.provision.inc index 12d501fc..531e376c 100644 --- a/platform/verify.provision.inc +++ b/platform/verify.provision.inc @@ -26,27 +26,19 @@ function provision_drupal_provision_verify($url = null) { dt("Drupal sites directory is not writable by the provisioning script"), PROVISION_SITES_DIR_NOT_WRITABLE); drush_set_option('sites', array_keys((array) provision_drupal_find_sites()), 'drupal'); - drush_set_option('platform', array('short_name' => 'drupal', 'version' => drush_drupal_version())); - drush_log(dt("This platform is running @short_name @version", - array('@short_name' => 'drupal', '@version' => VERSION))); - drush_set_option('profiles', _scrub_object(_provision_find_profiles()), 'drupal'); + drush_log(dt("This platform is running @short_name @version", array('@short_name' => 'drupal', '@version' => VERSION))); drush_set_option('packages', _scrub_object(provision_find_packages()), 'drupal'); - - } else { + drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site'); + // This is the actual drupal provisioning requirements. _provision_drupal_create_directories($url); _provision_drupal_maintain_aliases($url); // Requires at least the database settings to complete. _provision_drupal_create_settings_file($url); - - provision_platform_include(dirname(__FILE__), 'verify'); } - #if (is_array($data['modules'])) { - // get the correct version names for everything. - #$data['modules'] = _provision_drupal_get_cvs_versions($data['modules']); - #} + } -- GitLab