function patterns_start_engine in Patterns 7
Same name and namespace in other branches
- 7.2 patterns.module \patterns_start_engine()
The beginning of the whole Patterns logic. Starts the execution in 'batch' mode (default) or 'php' mode, which makes things easier for debugging.
Parameters
stdClass $pattern Pattern object as loaded by patterns_get_pattern().:
array $params Parameters for executing the pattern. Array format is as follows::
- pid => Pid of the pattern as it is in the database.
- run-subpatterns => ['first-update', always', 'update', 'first', 'never']
If coming from form_confirm some other parameters are addes, such as:
- confirm [1]
- submit [Confirm]
- form_build_id
- form_token
- form_id
- op [Confirm]
string $mode The running mode, one of {'batch', 'php'}.:
Return value
The result of the appropriate patterns_execute_pattern_$mode function.
See also
patterns_execute_pattern_batch()
patterns_execute_pattern_php()
4 calls to patterns_start_engine()
- drush_patterns_run_pattern in ./
patterns.drush.inc - patterns_enable_pattern_submit in ./
patterns.module - Form submission handler for patterns_enable_pattern().
- patterns_execute_config in includes/
unused.inc - Executes default configuration for module during the module installation.
- patterns_quickrun_submit in includes/
forms/ quickrun.inc - Form submission handler for patterns_quickrun().
File
- ./
patterns.module, line 692
Code
function patterns_start_engine($pattern, $params = array(), $mode = 'batch') {
module_load_include('inc', 'patterns', 'includes/core/common');
module_load_include('inc', 'patterns', 'includes/core/modules');
module_load_include('inc', 'patterns', 'includes/core/token');
module_load_include('inc', 'patterns', 'includes/core/' . $mode);
if (empty($pattern)) {
drupal_set_message(t('The pattern seems empty...I cannot run it!'));
return FALSE;
}
/////////////////////////////////////////
// Get Patterns details
$patterns_details = patterns_parser_get_pattern_details($pattern);
if ($patterns_details === FALSE) {
drupal_set_message(t('Errors where found in the pattern. Aborting.'), 'error');
return FALSE;
}
// TODO: handle multiple patterns correctly
// Let us assume we have only one pattern in the returned array of details
$pid = key($patterns_details);
$pattern_details = current($patterns_details);
$info = $pattern_details['info'];
// Array of infos of multiple patterns (we have only one for now).
$infos = array(
$pid => $info,
);
$modules = $pattern_details['modules'];
// Install modules, if necessary.
$installed_modules = patterns_install_modules($modules);
if (!$installed_modules['success']) {
drupal_set_message($installed_modules['error_message'], 'error');
return FALSE;
}
$sections = $pattern_details['sections'];
// Building execution parameters
if (!isset($params['quickrun']) || !$params['quickrun']) {
if (!is_object($pattern)) {
$pattern = patterns_get_pattern($pattern);
if (!$pattern) {
return FALSE;
}
}
}
// This is needed for the Patterns installation profile.
if (isset($params['run-subpatterns'])) {
$pattern->subpatterns_run_mode = $params['run-subpatterns'];
}
// Ste: Actions_map seems to be used with includes. Probably we do not need it now.
//$actions_map = array('patterns' => $pattern_details['info'], 'map' => $pattern_details['actions_map']);
// TODO: Patterns details was returning this in case of recursive includes.
// $result['actions_map'][] = array(
// 'pid' => $pattern->pid,
// 'index' => $key,
// );
$actions_map = array(
'patterns' => $infos,
'map' => NULL,
);
// Fix this.
////////////////////////////////////////
drupal_set_time_limit(0);
$fun = 'patterns_execute_pattern_' . $mode;
// Execute the Pattern using the selected mode.
$fun($pattern, $params, $patterns_details, $actions_map);
// Disable the modules enabled just for executing the pattern
if (!empty($installed_modules['installed'])) {
patterns_disable_modules($installed_modules['installed']);
}
return TRUE;
}