aboutsummaryrefslogtreecommitdiff
path: root/node_truncate.module
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2011-02-11 13:27:47 -0200
committerSilvio <silvio@devlet.com.br>2011-02-11 13:27:47 -0200
commit2b1131c4b85cbb4fdd6cc767932d752c210d3e0e (patch)
tree80ae725e8c4ed2459e429d02613ed5443404b3e9 /node_truncate.module
parente51136b7524098d554114a971a2749b744455c2b (diff)
downloadnode_truncate-2b1131c4b85cbb4fdd6cc767932d752c210d3e0e.tar.gz
node_truncate-2b1131c4b85cbb4fdd6cc767932d752c210d3e0e.tar.bz2
Using dynamic queries
Diffstat (limited to 'node_truncate.module')
-rw-r--r--node_truncate.module19
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']++;