1.20.x install.core.inc | install_run_task($task, &$install_state) |
Runs an individual installation task.
Parameters
$task: An array of information about the task to be run as returned by hook_install_tasks().
$install_state: An array of information about the current installation state. This is passed in by reference so that it can be modified by the task.
Return value
string|NULL: The output of the task function, if there is any.
Throws
Exception
File
- includes/
install.core.inc, line 380 - API functions for installing Backdrop.
Code
function install_run_task($task, &$install_state) {
$function = $task['function'];
if ($task['type'] == 'form') {
require_once BACKDROP_ROOT . '/core/includes/form.inc';
if ($install_state['interactive']) {
// For interactive forms, build the form and ensure that it will not
// redirect, since the installer handles its own redirection only after
// marking the form submission task complete.
$form_state = array(
// We need to pass $install_state by reference in order for forms to
// modify it, since the form API will use it in call_user_func_array(),
// which requires that referenced variables be passed explicitly.
'build_info' => array('args' => array(&$install_state)),
'no_redirect' => TRUE,
// Form build IDs are used to load prebuilt forms from tempstore.
// However, during install these tables don't exist yet. Prevent
// setting/checking the database with no_cache property.
'no_cache' => TRUE,
);
$form = backdrop_build_form($function, $form_state);
// If a successful form submission did not occur, the form needs to be
// rendered, which means the task is not complete yet.
if (empty($form_state['executed'])) {
$install_state['task_not_complete'] = TRUE;
return backdrop_render($form);
}
// Otherwise, return nothing so the next task will run in the same
// request.
return NULL;
}
else {
// For non-interactive forms, submit the form programmatically with the
// values taken from the installation state. Throw an exception if any
// errors were encountered.
$form_state = array(
'values' => !empty($install_state['forms'][$function]) ? $install_state['forms'][$function] : array(),
// We need to pass $install_state by reference in order for forms to
// modify it, since the form API will use it in call_user_func_array(),
// which requires that referenced variables be passed explicitly.
'build_info' => array('args' => array(&$install_state)),
);
backdrop_form_submit($function, $form_state);
$errors = form_get_errors();
if (!empty($errors)) {
throw new Exception(implode("\n", $errors));
}
}
}
elseif ($task['type'] == 'batch') {
// Start a new batch based on the task function, if one is not running
// already.
$current_batch = state_get('install_current_batch');
if (!$install_state['interactive'] || !$current_batch) {
$batch = $function($install_state);
if (empty($batch)) {
// If the task did some processing and decided no batch was necessary,
// there is nothing more to do here.
return NULL;
}
batch_set($batch);
// For interactive batches, we need to store the fact that this batch
// task is currently running. Otherwise, we need to make sure the batch
// will complete in one page request.
if ($install_state['interactive']) {
state_set('install_current_batch', $function);
}
else {
$batch = &batch_get();
$batch['progressive'] = FALSE;
}
// Process the batch. For progressive batches, this will redirect.
// Otherwise, the batch will complete.
batch_process(install_redirect_url($install_state), install_full_redirect_url($install_state));
}
// If we are in the middle of processing this batch, keep sending back
// any output from the batch process, until the task is complete.
elseif ($current_batch == $function) {
include_once BACKDROP_ROOT . '/core/includes/batch.inc';
$output = _batch_page();
// The task is complete when we try to access the batch page and receive
// FALSE in return, since this means we are at a URL where we are no
// longer requesting a batch ID.
if ($output === FALSE) {
// Return nothing so the next task will run in the same request.
state_del('install_current_batch');
return NULL;
}
else {
// We need to force the page request to end if the task is not
// complete, since the batch API sometimes prints JSON output
// rather than returning a themed page.
$install_state['task_not_complete'] = $install_state['stop_page_request'] = TRUE;
return $output;
}
}
}
else {
// For normal tasks, just return the function result, whatever it is.
return $function($install_state);
}
}