Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function skeleton_menu() {
- $items['admin/skeleton/batch'] = array(
- 'title' => 'Skeleton Batch',
- 'page callback' => 'skeleton_batch_init',
- 'access arguments' => array('Administer content'),
- 'type' => MENU_NORMAL_ITEM,
- );
- return $items;
- }
- function skeleton_batch_init() {
- $batch = array(
- 'title' => t('Importing Content ...'),
- 'operations' => array(),
- 'init_message' => t('Commencing'),
- 'progress_message' => t('Processed @current out of @total.'),
- 'error_message' => t('An error occurred during processing'),
- 'finished' => 'skeleton_batch_finished',
- 'progressive' => FALSE
- );
- $nodes = array(
- 'one',
- 'two',
- 'three',
- 'four'
- );
- foreach ($nodes as $new_node) {
- $batch['operations'][] = array('skeleton_batch_worker', array($new_node));
- }
- batch_set($batch);
- batch_process('<front>');
- }
- function skeleton_batch_worker($new_node, &$context) {
- /*
- $node = new stdClass();
- $node->type = 'article';
- node_object_prepare($node);
- $node->title = $new_node;
- $node->language = LANGUAGE_NONE;
- $node->body[$node->language][0]['value'] = $new_node;
- $node->body[$node->language][0]['summary'] = $new_node;
- $node->status = 1;
- node_save($node);
- */
- $context['results']['processed']++;
- $context['message'] = $new_node;
- }
- function skeleton_batch_finished($success, $results, $operations) {
- if ($success) {
- $message = format_plural($results['processed'], 'One node processed.', '@count nodes processed.');
- }
- else {
- $message = 'some errors';
- }
- drupal_set_message($message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement