/[drupal]/contributions/modules/devel/devel_generate_batch.inc
ViewVC logotype

Contents of /contributions/modules/devel/devel_generate_batch.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Mon Aug 24 03:54:27 2009 UTC (3 months ago) by weitzman
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +4 -4 lines
File MIME type: text/x-php
drupal_function_exists() no longer exists.
1 <?php
2 // $Id: devel_generate_batch.inc,v 1.5 2008/11/07 20:36:42 weitzman Exp $
3
4 /**
5 * Devel Generate batch handling functions using the BatchAPI
6 */
7
8 /**
9 * Functions called from FAPI:
10 */
11
12 function devel_generate_batch_content($form_state) {
13 $operations = array();
14
15 // Setup the batch operations and save the variables.
16 $operations[] = array('devel_generate_batch_content_pre_node', array($form_state['values']));
17
18 // add the kill operation
19 if ($form_state['values']['kill_content']) {
20 $operations[] = array('devel_generate_batch_content_kill', array());
21 }
22
23 // add the operations to create the nodes
24 for ($num = 0; $num < $form_state['values']['num_nodes']; $num ++) {
25 $operations[] = array('devel_generate_batch_content_add_node', array());
26 }
27
28 // start the batch
29 $batch = array(
30 'title' => t('Generating Content'),
31 'operations' => $operations,
32 'finished' => 'devel_generate_batch_finished',
33 'file' => drupal_get_path('module', 'devel_generate') . '/devel_generate_batch.inc',
34 );
35 batch_set($batch);
36 }
37
38 /**
39 * Create Content Batch Functions:
40 */
41
42 function devel_generate_batch_content_kill(&$context) {
43 module_load_include('inc', 'devel_generate', 'devel_generate');
44 devel_generate_content_kill($context['results']);
45 }
46
47 function devel_generate_batch_content_pre_node($vars, &$context) {
48 $context['results'] = $vars;
49 $context['results']['num_nids'] = 0;
50 module_load_include('inc', 'devel_generate', 'devel_generate');
51 devel_generate_content_pre_node($context['results']);
52 }
53
54 function devel_generate_batch_content_add_node(&$context) {
55 module_load_include('inc', 'devel_generate', 'devel_generate');
56 devel_generate_content_add_node($context['results']);
57 $context['results']['num_nids'] ++;
58 }
59
60 function devel_generate_batch_finished($success, $results, $operations) {
61 if ($success) {
62 $message = t('Finished @num_nids nodes created successfully.', array('@num_nids' => $results['num_nids']));
63 }
64 else {
65 $message = t('Finished with an error.');
66 }
67 drupal_set_message($message);
68 }
69

  ViewVC Help
Powered by ViewVC 1.1.2