Projet

Général

Profil

Révision 6d8023f2

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/taxonomy_menu/taxonomy_menu.batch.inc
6 6
 */
7 7

  
8 8
/**
9
 * The $batch can include the following values. Only 'operations'
10
 * and 'finished' are required, all others will be set to default values.
11
 *
12
 * @param operations
13
 *   An array of callbacks and arguments for the callbacks.
14
 *   There can be one callback called one time, one callback
15
 *   called repeatedly with different arguments, different
16
 *   callbacks with the same arguments, one callback with no
17
 *   arguments, etc.
18
 *
19
 * @param finished
20
 *   A callback to be used when the batch finishes.
21
 *
22
 * @param title
23
 *   A title to be displayed to the end user when the batch starts.
24
 *
25
 * @param init_message
26
 *   An initial message to be displayed to the end user when the batch starts.
27
 *
28
 * @param progress_message
29
 *   A progress message for the end user. Placeholders are available.
30
 *   Placeholders note the progression by operation, i.e. if there are
31
 *   2 operations, the message will look like:
32
 *    'Processed 1 out of 2.'
33
 *    'Processed 2 out of 2.'
34
 *   Placeholders include:
35
 *     @current, @remaining, @total and @percentage
36
 *
37
 * @param error_message
38
 *   The error message that will be displayed to the end user if the batch
39
 *   fails.
9
 *Starts a batch operation.
40 10
 *
11
 * @param int $vid
12
 *   Vocabulary ID.
41 13
 */
42 14
function _taxonomy_menu_insert_link_items_batch($vid) {
43
  $terms = taxonomy_get_tree($vid, 0, NULL, TRUE);
15
  $depth = variable_get(_taxonomy_menu_build_variable('max_depth', $vid), 0);
16
  if ($depth == 0) {
17
    $depth = NULL;
18
  }
19
  $terms = taxonomy_get_tree($vid, 0, $depth, TRUE);
44 20
  $menu_name = variable_get(_taxonomy_menu_build_variable('vocab_menu', $vid), FALSE);
45 21

  
46 22
  $batch = array(
23
    // An array of callbacks and arguments for the callbacks.
47 24
    'operations' => array(
48 25
      array('_taxonomy_menu_insert_link_items_process', array($terms, $menu_name)),
49 26
    ),
27
    // A callback to be used when the batch finishes.
50 28
    'finished' => '_taxonomy_menu_insert_link_items_success',
29
    // A title to be displayed to the end user when the batch starts.
51 30
    'title' => t('Rebuilding Taxonomy Menu'),
31
    // An initial message to be displayed to the end user when the batch starts.
52 32
    'init_message' => t('The menu items have been deleted, and are about to be regenerated.'),
33
    // A progress message for the end user. Placeholders are available.
34
    // Placeholders include: @current, @remaining, @total and @percentage
53 35
    'progress_message' => t('Import progress: Completed @current of @total stages.'),
54
    'redirect' => 'admin/structure/taxonomy',
36
    // The message that will be displayed to the end user if the batch fails.
55 37
    'error_message' => t('The Taxonomy Menu rebuild process encountered an error.'),
38
    'redirect' => 'admin/structure/taxonomy',
56 39
  );
57 40
  batch_set($batch);
58 41
  batch_process();
59 42
}
60 43

  
61

  
62
/*
63
 * Insert 10 menu link items
44
/**
45
 * Batch operation callback function: inserts 10 menu link items.
46
 *
47
 * @param array $terms
48
 *   Taxonomy terms as from taxonomy_get_tree().
49
 * @param string $menu_name
50
 *   Setting for the menu item name assigned to the vocabulary.
51
 * @param array $context
52
 *   Batch context array.
53
 *
54
 * @see _taxonomy_menu_insert_link_items_batch().
64 55
 */
65 56
function _taxonomy_menu_insert_link_items_process($terms, $menu_name, &$context) {
66 57
  _taxonomy_menu_batch_init_context($context, $start, $end, 10);
......
79 70

  
80 71

  
81 72

  
82
/*
83
 * Set a message stating the menu has been updated
73
/**
74
 * Batch finished callback: sets a message stating the menu has been updated.
75
 *
76
 * @see _taxonomy_menu_insert_link_items_batch().
84 77
 */
85 78
function _taxonomy_menu_insert_link_items_success() {
86 79
  // TODO state menu name here.
87 80
  drupal_set_message(t('The Taxonomy Menu has been updated.'));
88 81
}
89 82

  
90
/*
91
 * Initialise the batch context
92
 * @param array $context Batch context array.
93
 * @param int $start The item to start on in this pass
94
 * @param int $end The end item of this pass
95
 * @param int $items The number of items to process in this pass
83
/**
84
 * Initialise the batch context.
85
 *
86
 * @param array $context
87
 *   Batch context array.
88
 * @param int $start
89
 *   The item to start on in this pass.
90
 * @param int $end
91
 *   The end item of this pass.
92
 * @param int $items
93
 *   The number of items to process in this pass.
96 94
 */
97 95
function _taxonomy_menu_batch_init_context(&$context, &$start, &$end, $items) {
98 96
  // Initialize sandbox the first time through.
......
104 102
  $end = $start + $items;
105 103
}
106 104

  
107

  
108
/*
105
/**
109 106
 * Update the batch context
110 107
 *
111
 * @param array $context Batch context array.
112
 * @param int $end The end point of the most recent pass
113
 * @param int $total The total number of items to process in this batch
114
 * @param str $msg Message for the progress bar
108
 * @param array $context
109
 *   Batch context array.
110
 * @param int $end
111
 *   The end point of the most recent pass.
112
 * @param int $total
113
 *   The total number of items to process in this batch.
114
 * @param str $msg
115
 *   Message for the progress bar.
116
 * @see _taxonomy_menu_insert_link_items_process().
115 117
 */
116 118
function _taxonomy_menu_batch_update_context(&$context, $end, $total, $msg) {
117
  //Update context array
118 119
  if ($end > $total) {
119 120
    $context['finished'] = 1;
120 121
    return;

Formats disponibles : Unified diff