devel_generate_batch.inc in Devel 6
File
devel_generate_batch.inc
View source
<?php
function devel_batch_generate_content($form_state) {
$operations = array();
$operations[] = array(
'devel_generate_batch_content_pre_node',
array(
$form_state['values'],
),
);
if ($form_state['values']['kill_content']) {
$operations[] = array(
'devel_generate_batch_content_kill',
array(),
);
}
for ($num = 0; $num < $form_state['values']['num_nodes']; $num++) {
$operations[] = array(
'devel_generate_batch_content_add_node',
array(),
);
}
$batch = array(
'title' => t('Generating Content'),
'operations' => $operations,
'finished' => 'devel_generate_batch_finished',
'file' => drupal_get_path('module', 'devel_generate') . '/devel_generate_batch.inc',
);
batch_set($batch);
}
function devel_generate_batch_content_kill(&$context) {
require_once 'devel_generate.inc';
devel_generate_content_kill($context['results']);
}
function devel_generate_batch_content_pre_node($vars, &$context) {
$context['results'] = $vars;
$context['results']['num_nids'] = 0;
require_once 'devel_generate.inc';
devel_generate_content_pre_node($context['results']);
}
function devel_generate_batch_content_add_node(&$context) {
require_once 'devel_generate.inc';
devel_generate_content_add_node($context['results']);
$context['results']['num_nids']++;
}
function devel_generate_batch_finished($success, $results, $operations) {
if ($success) {
$message = t('Finished @num_nids nodes created successfully.', array(
'@num_nids' => $results['num_nids'],
));
}
else {
$message = t('Finished with an error.');
}
drupal_set_message($message);
}