diff options
Diffstat (limited to 'node_truncate.module')
-rw-r--r-- | node_truncate.module | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/node_truncate.module b/node_truncate.module index a4f34fe..6ea0b85 100644 --- a/node_truncate.module +++ b/node_truncate.module @@ -95,13 +95,24 @@ function node_truncate_form_submit($form, &$form_state) { function node_truncate($type, &$context) { $where = 'WHERE type = :type'; if (empty($context['sandbox'])) { + $query = db_select('node', 'n'); + $query + ->condition('n.type', $type, '=') + ->addExpression('COUNT(DISTINCT(nid))'); + $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; - $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node} ' . $where, - array(':type' => $type))->fetchField(); + $context['sandbox']['max'] = $query->execute()->fetchField(); } - $limit = 5; - $result = db_query_range('SELECT node.nid FROM {node} ' . $where, 0, $limit, array(':type' => $type)); + + $limit = 5; + $query = db_select('node', 'n'); + $query + ->condition('n.type', $type, '=') + ->fields('n', array('nid')) + ->range(0, $limit); + $result = $query->execute(); + while ($row = $result->fetchAssoc()) { $node = node_delete($row['nid'], NULL, TRUE); $context['sandbox']['progress']++; |