diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-21 07:50:08 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-21 07:50:08 +0000 |
commit | 716293e0fbf1155b8e78c4bd2762c98275b8e6cb (patch) | |
tree | a8dd7691cd035f407268e41969ffbb033871bc36 /includes | |
parent | d151ea91004abd0c771dfeea380ff4fef0fbf248 (diff) | |
download | brdo-716293e0fbf1155b8e78c4bd2762c98275b8e6cb.tar.gz brdo-716293e0fbf1155b8e78c4bd2762c98275b8e6cb.tar.bz2 |
#509398 by adrian: Turned install profiles into modules with full access to the Drupal API. Almost all WTFs/minute now removed from install profiles. Woohoo! :D
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 40 | ||||
-rw-r--r-- | includes/install.inc | 23 | ||||
-rw-r--r-- | includes/module.inc | 5 | ||||
-rw-r--r-- | includes/update.inc | 70 |
4 files changed, 117 insertions, 21 deletions
diff --git a/includes/common.inc b/includes/common.inc index 4e701de9e..910f4028a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -120,6 +120,32 @@ function drupal_get_region_content($region = NULL, $delimiter = ' ') { } /** + * Get the name of the currently active install profile. + * + * When this function is called during Drupal's initial installation process, + * the name of the profile that's about to be installed is stored in the global + * installation state. At all other times, the standard Drupal systems variable + * table contains the name of the current profile, and we can call variable_get() + * to determine what one is active. + * + * @return $profile + * The name of the install profile. + */ +function drupal_get_profile() { + global $install_state; + + if (isset($install_state['parameters']['profile'])) { + $profile = $install_state['parameters']['profile']; + } + else { + $profile = variable_get('install_profile', 'default'); + } + + return $profile; +} + + +/** * Set the breadcrumb trail for the current page. * * @param $breadcrumb @@ -3724,20 +3750,10 @@ function drupal_cron_cleanup() { * An array of file objects of the specified type. */ function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1) { - global $install_state; $config = conf_path(); - // When this function is called during Drupal's initial installation process, - // the name of the profile that's about to be installed is stored in the global - // installation state. At all other times, the standard Drupal systems variable - // table contains the name of the current profile, and we can call variable_get() - // to determine what one is active. - if (isset($install_state['parameters']['profile'])) { - $profile = $install_state['parameters']['profile']; - } - else { - $profile = variable_get('install_profile', 'default'); - } + $profile = drupal_get_profile(); + $searchdir = array($directory); $files = array(); diff --git a/includes/install.inc b/includes/install.inc index 5626196b0..60164b118 100644 --- a/includes/install.inc +++ b/includes/install.inc @@ -166,16 +166,12 @@ function drupal_set_installed_schema_version($module, $version) { */ function drupal_install_profile_name() { global $install_state; - $profile = $install_state['parameters']['profile']; - static $name = NULL; - if (!isset($name)) { - // Load profile details. - $function = $profile . '_profile_details'; - if (function_exists($function)) { - $details = $function(); - } - $name = isset($details['name']) ? $details['name'] : 'Drupal'; + if (isset($install_state['profile_info']['name'])) { + $name = $install_state['profile_info']['name']; + } + else { + $name = 'Drupal'; } return $name; @@ -522,6 +518,10 @@ function drupal_verify_profile($install_state) { $present_modules[] = $present_module->name; } + // The install profile is also a module, which needs to be installed after all the other dependencies + // have been installed. + $present_modules[] = drupal_get_profile(); + // Verify that all of the profile's required modules are present. $missing_modules = array_diff($info['dependencies'], $present_modules); @@ -1087,6 +1087,11 @@ function install_profile_info($profile, $locale = 'en') { $info['dependencies'], ($locale != 'en' && !empty($locale) ? array('locale') : array())) ); + + // drupal_required_modules() includes the current profile as a dependency. + // Since a module can't depend on itself we remove that element of the array. + array_shift($info['dependencies']); + $cache[$profile] = $info; } return $cache[$profile]; diff --git a/includes/module.inc b/includes/module.inc index e741e310f..0c3f9202d 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -502,11 +502,16 @@ function module_invoke_all() { function drupal_required_modules() { $files = drupal_system_listing('/\.info$/', 'modules', 'name', 0); $required = array(); + + // An install profile is required and one must always be loaded. + $required[] = drupal_get_profile(); + foreach ($files as $name => $file) { $info = drupal_parse_info_file($file->uri); if (!empty($info) && !empty($info['required']) && $info['required']) { $required[] = $name; } } + return $required; } diff --git a/includes/update.inc b/includes/update.inc index e27dd42d1..efe0d8535 100644 --- a/includes/update.inc +++ b/includes/update.inc @@ -255,10 +255,80 @@ function update_fix_d7_requirements() { } } + update_fix_d7_install_profile(); + return $ret; } /** + * Register the currently installed profile in the system table. + * + * Install profiles are now treated as modules by Drupal, and have an upgrade path + * based on their schema version in the system table. + * + * The install profile will be set to schema_version 0, as it has already been + * installed. Any other hook_update_N functions provided by the install profile + * will be run by update.php. + */ +function update_fix_d7_install_profile() { + $profile = drupal_get_profile(); + + + $results = db_select('system', 's') + ->fields('s', array('name', 'schema_version')) + ->condition('name', $profile) + ->condition('type', 'module') + ->execute() + ->fetchAll(); + + if (empty($results)) { + $filename = 'profiles/' . $profile . '/' . $profile . '.profile'; + + // Read profile info file + $info = drupal_parse_info_file(dirname($filename) . '/' . $profile . '.info'); + + // Merge in defaults. + $info = $info + array( + 'dependencies' => array(), + 'dependents' => array(), + 'description' => '', + 'package' => 'Other', + 'version' => NULL, + 'php' => DRUPAL_MINIMUM_PHP, + 'files' => array(), + ); + + // The install profile is always required. + $file->info['required'] = TRUE; + + $values = array( + 'filename' => $filename, + 'name' => $profile, + 'info' => serialize($info), + 'schema_version' => 0, + 'type' => 'module', + 'status' => 1, + 'owner' => '', + ); + + // Install profile hooks are always executed last by the module system + $values['weight'] = 1000; + + // Initializing the system table entry for the install profile + db_insert('system') + ->fields(array_keys($values)) + ->values($values) + ->execute(); + + // Reset the cached schema version. + drupal_get_installed_schema_version($profile, TRUE); + + // Load the updates again to make sure the install profile updates are loaded + drupal_load_updates(); + } +} + +/** * Parse database connection URLs (in the old, pre-Drupal 7 format) and * return them as an array of database connection information. */ |