From 0ab063b89c69227012492fcc88173a42cdcfd083 Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 8 Oct 2010 16:20:00 -0300 Subject: Using node_truncate as a dependency --- node_import_truncate.info | 3 ++- node_import_truncate.module | 43 ++----------------------------------------- 2 files changed, 4 insertions(+), 42 deletions(-) diff --git a/node_import_truncate.info b/node_import_truncate.info index fa3dc9e..28b2a08 100644 --- a/node_import_truncate.info +++ b/node_import_truncate.info @@ -3,5 +3,6 @@ name = Node Import Truncate description = Allow to truncate a content type before importing data. package = Development core = 6.x +version = "6.x-0.2" dependencies[] = node_import -version = "6.x-0.1" +dependencies[] = node_truncate diff --git a/node_import_truncate.module b/node_import_truncate.module index 9a88fb1..ac75a71 100644 --- a/node_import_truncate.module +++ b/node_import_truncate.module @@ -83,9 +83,9 @@ function node_import_truncate_form_submit($form, &$form_state) { $batch = array( 'title' => t('Deleting old data.'), 'operations' => array( - array('node_import_truncate', array($type)), + array('node_truncate', array($type)), ), - 'finished' => 'node_import_truncate_callback', + 'finished' => 'node_truncate_callback', ); batch_set($batch); @@ -108,42 +108,3 @@ function node_import_truncate_node_import_task($task, $op) { drupal_goto('admin/content/node_import/truncate/' . $task['taskid']); } } - -/** - * Mass deletion of content. - */ -function node_import_truncate($type, &$context) { - $type = 'WHERE type = "' . $type . '"'; - if (empty($context['sandbox'])) { - $context['sandbox']['progress'] = 0; - $context['sandbox']['current_node'] = 0; - $context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT nid) FROM {node} ' . $type)); - } - $limit = 5; - $result = db_query_range('SELECT nid FROM {node} ' . $type, $context['sandbox']['current_node'], 0, $limit); - while ($row = db_fetch_array($result)) { - $node = node_delete($row['nid'], NULL, TRUE); - $context['sandbox']['progress']++; - $context['sandbox']['current_node'] = $node->nid; - $context['results'][] = $node->nid .' : '. $node->title; - $context['message'] = $node->title; - } - if ($context['sandbox']['progress'] != $context['sandbox']['max']) { - $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; - } -} - -/** - * Callback for node_import_truncate(); - */ -function node_import_truncate_callback($success, $results, $operations) { - if ($success) { - if ($results > 0) { - $message = format_plural(count($results), t('One old post processed.'), t('@count old posts processed.')); - } - } - else { - $message = t('Finished with an error.'); - } - drupal_set_message($message); -} -- cgit v1.2.3