function patterns_execute_pattern_batch in Patterns 6
Same name and namespace in other branches
- 6.2 patterns.module \patterns_execute_pattern_batch()
- 7.2 includes/core/batch.inc \patterns_execute_pattern_batch()
- 7 includes/core/batch.inc \patterns_execute_pattern_batch()
File
- ./
patterns.module, line 1376 - Enables extremely simple adding/removing features to your site with minimal to no configuration
Code
function patterns_execute_pattern_batch($pattern, $params = array()) {
set_time_limit(0);
if (!is_object($pattern)) {
$pattern = patterns_get_pattern($pattern);
if (!$pattern) {
return FALSE;
}
}
$pattern->subpatterns_run_mode = $params['run-subpatterns'];
$pattern_details = patterns_get_pattern_details($pattern, TRUE);
$modules = $pattern_details['modules'];
$actions = $pattern_details['actions'];
$actions_map = array(
'patterns' => $pattern_details['info'],
'map' => $pattern_details['actions_map'],
);
$info = reset($pattern_details['info']);
// If there are no actions or modules, most likely the pattern
// was not created correctly.
if (empty($actions) && empty($modules)) {
drupal_set_message(t('Could not recognize pattern %title, aborting.', array(
'%title' => $info['title'],
)), 'error');
return FALSE;
}
$result = patterns_install_modules($modules);
if (!$result['success']) {
drupal_set_message($result['error_message'], 'error');
return FALSE;
}
$result = patterns_prepare_actions($actions, $actions_map);
if (!$result['success']) {
drupal_set_message($result['error_message'], 'error');
return FALSE;
}
$batch = array(
'title' => t('Processing pattern %pattern', array(
'%pattern' => $info['title'],
)),
// 'init_message' => t('Running action @current out of @total', array('@current' => 1, '@total' => count($actions))),
'progress_message' => t('Running action @current out of @total'),
'operations' => array(),
'finished' => 'patterns_batch_finish',
);
for ($i = 0; $i < count($actions); $i++) {
$batch['operations'][] = array(
'patterns_batch_actions',
array(
$actions[$i],
$i,
$actions_map,
),
);
}
$_SESSION['patterns_batch_info'] = $pattern_details['info'];
batch_set($batch);
return TRUE;
}