#509392 by adrian: Add .info files for installation profiles.

merge-requests/26/head
Angie Byron 2009-07-15 02:08:41 +00:00
parent 3472adb2ca
commit b692036962
8 changed files with 188 additions and 169 deletions

View File

@ -422,24 +422,6 @@ function drupal_get_install_files($module_list = array()) {
return $installs;
}
/**
* Get a list of modules required by an installation profile.
*
* @param profile
* Name of profile.
* @param locale
* Name of locale used (if any).
* @return
* The list of modules to install.
*/
function drupal_get_profile_modules($profile, $locale = 'en') {
$profile_file = "./profiles/$profile/$profile.profile";
require_once($profile_file);
// Get a list of modules required by this profile.
$function = $profile . '_profile_modules';
return array_merge(drupal_required_modules(), $function(), ($locale != 'en' && !empty($locale) ? array('locale') : array()));
}
/**
* Verify an install profile for installation.
@ -460,8 +442,8 @@ function drupal_verify_profile($profile, $locale) {
if (!isset($profile) || !file_exists($profile_file)) {
install_no_profile_error();
}
$info = install_profile_info($profile);
$module_list = drupal_get_profile_modules($profile, $locale);
// Get a list of modules that exist in Drupal's assorted subdirectories.
$present_modules = array();
@ -470,7 +452,7 @@ function drupal_verify_profile($profile, $locale) {
}
// Verify that all of the profile's required modules are present.
$missing_modules = array_diff($module_list, $present_modules);
$missing_modules = array_diff($info['dependencies'], $present_modules);
$requirements = array();
@ -924,14 +906,10 @@ function drupal_check_profile($profile) {
install_no_profile_error();
}
require_once $profile_file;
// Get a list of modules required by this profile.
$function = $profile . '_profile_modules';
$module_list = array_unique(array_merge(drupal_required_modules(), $function()));
$info = install_profile_info($profile);
// Get a list of all .install files.
$installs = drupal_get_install_files($module_list);
$installs = drupal_get_install_files($info['dependencies']);
// Collect requirement testing results
$requirements = array();
@ -996,3 +974,26 @@ function drupal_check_module($module) {
}
return TRUE;
}
/**
* Retrieve info about an install profile from its .info file.
*/
function install_profile_info($profile, $locale = 'en') {
$cache =& drupal_static('install_profile_info', array(), TRUE);
// Set defaults for module info.
$defaults = array(
'dependencies' => array(),
'tasks' => array(),
'description' => '',
'version' => NULL,
'php' => DRUPAL_MINIMUM_PHP,
);
$info = drupal_parse_info_file(sprintf('profiles/%s/%s.info', $profile, $profile)) + $defaults;
$info['dependencies'] = array_unique(array_merge(
drupal_required_modules(),
$info['dependencies'],
($locale != 'en' && !empty($locale) ? array('locale') : array()))
);
return $info;
}

View File

@ -102,8 +102,6 @@ function install_main() {
install_no_profile_error();
}
// Load the profile.
require_once DRUPAL_ROOT . "/profiles/$profile/$profile.profile";
// Locale selection
if (!empty($_GET['locale'])) {
@ -113,6 +111,10 @@ function install_main() {
install_goto("install.php?profile=$profile&locale=$install_locale");
}
// Load the profile.
require_once DRUPAL_ROOT . "/profiles/$profile/$profile.profile";
$info = install_profile_info($profile, $install_locale);
// Tasks come after the database is set up
if (!$task) {
global $db_url;
@ -151,7 +153,7 @@ function install_main() {
// Save the list of other modules to install for the 'profile-install'
// task. variable_set() can be used now that system.module is installed
// and drupal is bootstrapped.
$modules = drupal_get_profile_modules($profile, $install_locale);
$modules = $info['dependencies'];
variable_set('install_profile_modules', array_diff($modules, array('system')));
}
@ -437,6 +439,7 @@ function install_select_profile() {
}
}
/**
* Form API array definition for the profile selection form.
*
@ -452,11 +455,7 @@ function install_select_profile_form(&$form_state, $profile_files) {
foreach ($profile_files as $profile) {
include_once DRUPAL_ROOT . '/' . $profile->filepath;
// Load profile details and store them for later retrieval.
$function = $profile->name . '_profile_details';
if (function_exists($function)) {
$details = $function();
}
$details = install_profile_info($profile->name);
$profiles[$profile->name] = $details;
// Determine the name of the profile; default to file name if defined name
@ -970,15 +969,11 @@ function install_task_list($active = NULL) {
unset($tasks['profile-select']);
$tasks['profile-install-batch'] = st('Install site');
}
// Add tasks defined by the profile.
if ($profile) {
$function = $profile . '_profile_task_list';
if (function_exists($function)) {
$result = $function();
if (is_array($result)) {
$tasks += $result;
}
$info = install_profile_info($profile);
if (array_key_exists('tasks', $info)) {
$tasks += $info['tasks'];
}
}

View File

@ -1033,10 +1033,13 @@ class DrupalWebTestCase extends DrupalTestCase {
$this->preloadRegistry();
// Include the default profile
require_once("./profiles/default/default.profile");
$profile_details = install_profile_info('default', 'en');
// Add the specified modules to the list of modules in the default profile.
// Install the modules specified by the default profile.
$core_modules = drupal_get_profile_modules('default', 'en');
drupal_install_modules($core_modules, TRUE);
drupal_install_modules($profile_details['dependencies'], TRUE);
node_type_clear();

View File

@ -1825,6 +1825,126 @@ function hook_registry_files_alter(&$files, $module_cache) {
}
}
/**
* Perform any final installation tasks for an installation profile.
*
* The installer goes through the profile-select -> locale-select
* -> requirements -> database -> profile-install-batch
* -> locale-initial-batch -> configure -> locale-remaining-batch
* -> finished -> done tasks, in this order, if you don't implement
* this function in your profile.
*
* If this function is implemented, you can have any number of
* custom tasks to perform after 'configure', implementing a state
* machine here to walk the user through those tasks. First time,
* this function gets called with $task set to 'profile', and you
* can advance to further tasks by setting $task to your tasks'
* identifiers, used as array keys in the tasks property of the
* profilename.info file.
*
* You must avoid the reserved tasks listed in install_reserved_tasks().
* If you implement your custom tasks, this function will get called in
* every HTTP request (for form processing, printing your information
* screens and so on) until you advance to the 'profile-finished' task,
* with which you hand control back to the installer. Each custom page
* you return needs to provide a way to continue, such as a form
* submission or a link. You should also set custom page titles.
*
* You should define the list of custom tasks you implement by
* specifying an array of tasks in your profilename.info file, as these
* show up in the list of tasks on the installer user interface.
*
* Example :
* task[custom_task] = My first custom task
* task[custom_task_2] = My second custom task
*
* Remember that the user will be able to reload the pages multiple
* times, so you might want to use variable_set() and variable_get()
* to remember your data and control further processing, if $task
* is insufficient. Should a profile want to display a form here,
* it can; the form should set '#redirect' to FALSE, and rely on
* an action in the submit handler, such as variable_set(), to
* detect submission and proceed to further tasks. See the configuration
* form handling code in install_tasks() for an example.
*
* Important: Any temporary variables should be removed using
* variable_del() before advancing to the 'profile-finished' phase.
*
* @param $task
* The current $task of the install system. When hook_profile_tasks()
* is first called, this is 'profile'.
* @param $url
* Complete URL to be used for a link or form action on a custom page,
* if providing any, to allow the user to proceed with the installation.
*
* @return
* An optional HTML string to display to the user. Only used if you
* modify the $task, otherwise discarded.
*/
function hook_profile_tasks(&$task, $url) {
// Enable some standard blocks.
$values = array(
array(
'module' => 'system',
'delta' => 'main',
'theme' => 'garland',
'status' => 1,
'weight' => 0,
'region' => 'content',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'user',
'delta' => 'login',
'theme' => 'garland',
'status' => 1,
'weight' => 0,
'region' => 'left',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'system',
'delta' => 'navigation',
'theme' => 'garland',
'status' => 1,
'weight' => 0,
'region' => 'left',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'system',
'delta' => 'management',
'theme' => 'garland',
'status' => 1,
'weight' => 1,
'region' => 'left',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'system',
'delta' => 'help',
'theme' => 'garland',
'status' => 1,
'weight' => 0,
'region' => 'help',
'pages' => '',
'cache' => -1,
),
);
$query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
foreach ($values as $record) {
$query->values($record);
}
$query->execute();
}
/**
* @} End of "addtogroup hooks".
*/

View File

@ -0,0 +1,16 @@
; $Id$
name = Drupal
description = Create a Drupal site with the most commonly used features pre-installed.
version = VERSION
core = 7.x
dependencies[] = block
dependencies[] = color
dependencies[] = comment
dependencies[] = help
dependencies[] = image
dependencies[] = menu
dependencies[] = path
dependencies[] = taxonomy
dependencies[] = dblog
dependencies[] = search
dependencies[] = toolbar

View File

@ -2,95 +2,9 @@
// $Id$
/**
* Return an array of the modules to be enabled when this profile is installed.
*
* @return
* An array of modules to enable.
*/
function default_profile_modules() {
return array('block', 'color', 'comment', 'help', 'image', 'menu', 'path', 'taxonomy', 'dblog', 'search', 'toolbar');
}
/**
* Return a description of the profile for the initial installation screen.
*
* @return
* An array with keys 'name' and 'description' describing this profile,
* and optional 'language' to override the language selection for
* language-specific profiles.
*/
function default_profile_details() {
return array(
'name' => 'Drupal',
'description' => 'Create a Drupal site with the most commonly used features pre-installed.'
);
}
/**
* Return a list of tasks that this profile supports.
*
* @return
* A keyed array of tasks the profile will perform during
* the final stage. The keys of the array will be used internally,
* while the values will be displayed to the user in the installer
* task list.
*/
function default_profile_task_list() {
}
/**
* Perform any final installation tasks for this profile.
*
* The installer goes through the profile-select -> locale-select
* -> requirements -> database -> profile-install-batch
* -> locale-initial-batch -> configure -> locale-remaining-batch
* -> finished -> done tasks, in this order, if you don't implement
* this function in your profile.
*
* If this function is implemented, you can have any number of
* custom tasks to perform after 'configure', implementing a state
* machine here to walk the user through those tasks. First time,
* this function gets called with $task set to 'profile', and you
* can advance to further tasks by setting $task to your tasks'
* identifiers, used as array keys in the hook_profile_task_list()
* above. You must avoid the reserved tasks listed in
* install_reserved_tasks(). If you implement your custom tasks,
* this function will get called in every HTTP request (for form
* processing, printing your information screens and so on) until
* you advance to the 'profile-finished' task, with which you
* hand control back to the installer. Each custom page you
* return needs to provide a way to continue, such as a form
* submission or a link. You should also set custom page titles.
*
* You should define the list of custom tasks you implement by
* returning an array of them in hook_profile_task_list(), as these
* show up in the list of tasks on the installer user interface.
*
* Remember that the user will be able to reload the pages multiple
* times, so you might want to use variable_set() and variable_get()
* to remember your data and control further processing, if $task
* is insufficient. Should a profile want to display a form here,
* it can; the form should set '#redirect' to FALSE, and rely on
* an action in the submit handler, such as variable_set(), to
* detect submission and proceed to further tasks. See the configuration
* form handling code in install_tasks() for an example.
*
* Important: Any temporary variables should be removed using
* variable_del() before advancing to the 'profile-finished' phase.
*
* @param $task
* The current $task of the install system. When hook_profile_tasks()
* is first called, this is 'profile'.
* @param $url
* Complete URL to be used for a link or form action on a custom page,
* if providing any, to allow the user to proceed with the installation.
*
* @return
* An optional HTML string to display to the user. Only used if you
* modify the $task, otherwise discarded.
* Implement hook_profile_tasks().
*/
function default_profile_tasks(&$task, $url) {
// Enable some standard blocks.
$values = array(
array(

View File

@ -0,0 +1,7 @@
; $Id$
name = Drupal (minimal)
description = Create a Drupal site with only required modules enabled.
version = VERSION
core = 7.x
dependencies[] = block
dependencies[] = dblog

View File

@ -2,44 +2,7 @@
// $Id$
/**
* Return an array of the modules to be enabled when this profile is installed.
*
* @return
* An array of modules to enable.
*/
function expert_profile_modules() {
return array('block', 'dblog');
}
/**
* Return a description of the profile for the initial installation screen.
*
* @return
* An array with keys 'name' and 'description' describing this profile,
* and optional 'language' to override the language selection for
* language-specific profiles.
*/
function expert_profile_details() {
return array(
'name' => 'Drupal (minimal)',
'description' => 'Create a Drupal site with only required modules enabled.'
);
}
/**
* Return a list of tasks that this profile supports.
*
* @return
* A keyed array of tasks the profile will perform during
* the final stage. The keys of the array will be used internally,
* while the values will be displayed to the user in the installer
* task list.
*/
function expert_profile_task_list() {
}
/**
* Perform any final installation tasks for this profile.
* Implement hook_profile_tasks().
*/
function expert_profile_tasks(&$task, $url) {