first commit
[step2_drupal.git] / devel / devel_generate_batch.inc
blobfba72cae49e715db335d2c5372661b1e1f318fe7
1 <?php
2 // $Id: devel_generate_batch.inc,v 1.1.2.5 2009/02/02 21:00:52 drewish Exp $
4 /**
5  * Devel Generate batch handling functions using the BatchAPI
6  * included by devel_generate.module
7  */
9 /**
10  * Functions called from FAPI:
11  */
13 function devel_batch_generate_content($form_state) {
14   $operations = array();
16   // Setup the batch operations and save the variables.
17   $operations[] = array('devel_generate_batch_content_pre_node', array($form_state['values']));
19   // add the kill operation
20   if ($form_state['values']['kill_content']) {
21     $operations[] = array('devel_generate_batch_content_kill', array());
22   }
24   // add the operations to create the nodes
25   for ($num = 0; $num < $form_state['values']['num_nodes']; $num ++) {
26     $operations[] = array('devel_generate_batch_content_add_node', array());
27   }
29   // start the batch
30   $batch = array(
31     'title' => t('Generating Content'),
32     'operations' => $operations,
33     'finished' => 'devel_generate_batch_finished',
34     'file' => drupal_get_path('module', 'devel_generate') . '/devel_generate_batch.inc',
35   );
36   batch_set($batch);
39 /**
40  * Create Content Batch Functions:
41  */
43 function devel_generate_batch_content_kill(&$context) {
44   require_once('devel_generate.inc');
45   devel_generate_content_kill($context['results']);
48 function devel_generate_batch_content_pre_node($vars, &$context) {
49   $context['results'] = $vars;
50   $context['results']['num_nids'] = 0;
51   require_once('devel_generate.inc');
52   devel_generate_content_pre_node($context['results']);
55 function devel_generate_batch_content_add_node(&$context) {
56   require_once('devel_generate.inc');
57   devel_generate_content_add_node($context['results']);
58   $context['results']['num_nids'] ++;
61 function devel_generate_batch_finished($success, $results, $operations) {
62   if ($success) {
63     $message = t('Finished @num_nids nodes created successfully.', array('@num_nids' => $results['num_nids']));
64   }
65   else {
66     $message = t('Finished with an error.');
67   }
68   drupal_set_message($message);