From e51136b7524098d554114a971a2749b744455c2b Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 11 Feb 2011 12:46:37 -0200 Subject: Converting do 7.x API --- node_truncate.module | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'node_truncate.module') diff --git a/node_truncate.module b/node_truncate.module index a6fc829..a4f34fe 100644 --- a/node_truncate.module +++ b/node_truncate.module @@ -12,7 +12,7 @@ * Implementation of hook_menu(); */ function node_truncate_menu() { - $items['admin/content/node_truncate'] = array( + $items['admin/config/content/node_truncate'] = array( 'title' => 'Node Truncate', 'description' => 'Mass deletion page.', 'page callback' => 'node_truncate_page', @@ -27,15 +27,15 @@ function node_truncate_menu() { */ function node_truncate_page() { $output = t('Choose a content type to truncate.'); - $output .= drupal_get_form('node_truncate_form'); + $output .= drupal_render(drupal_get_form('node_truncate_form')); return $output; } /** * Mass deletion form. */ -function node_truncate_form(&$form_state) { - $node_types = node_get_types(); +function node_truncate_form($form, &$form_state) { + $node_types = node_type_get_types(); $node_codes = array(); foreach ($node_types as $item) { @@ -86,26 +86,27 @@ function node_truncate_form_submit($form, &$form_state) { ); batch_set($batch); - batch_process($redirect); + batch_process(); } /** * Mass deletion of content. */ function node_truncate($type, &$context) { - $type = 'WHERE type = "' . $type . '"'; + $where = '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)); + $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node} ' . $where, + array(':type' => $type))->fetchField(); } $limit = 5; - $result = db_query_range('SELECT nid FROM {node} ' . $type, $context['sandbox']['current_node'], 0, $limit); - while ($row = db_fetch_array($result)) { + $result = db_query_range('SELECT node.nid FROM {node} ' . $where, 0, $limit, array(':type' => $type)); + while ($row = $result->fetchAssoc()) { $node = node_delete($row['nid'], NULL, TRUE); $context['sandbox']['progress']++; $context['sandbox']['current_node'] = $node->nid; - $context['results'][] = $node->nid .' : '. check_plain($node->title); + $context['results'][] = $node->nid . ' : ' . check_plain($node->title); $context['message'] = check_plain($node->title); } if ($context['sandbox']['progress'] != $context['sandbox']['max']) { -- cgit v1.2.3