-
Notifications
You must be signed in to change notification settings - Fork 0
/
denuke_drupal_helpers.php
40 lines (35 loc) · 1.23 KB
/
denuke_drupal_helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// get top-level terms for a given vocabulary ID
// $terms[] looks like '3' => 'Horror'
// $terms_reverted[] looks like 'Horror' => 3
function load_drupal_tax($vocabulary_id, &$terms, &$terms_reverted) {
$items = taxonomy_get_tree($vocabulary_id);
foreach ($items as $item) {
if ($item->parents[0] != 0) {
// skip non-top level items
continue;
}
$terms[$item->tid] = $item->name;
$terms_reverted[$item->name] = $item->tid;
}
}
// returns an array of malformed nodes
function check_nodes() {
$bad_nodes = array();
$result = db_query('SELECT * FROM {node} WHERE vid = 0');
while ($entry = $result->fetch_assoc()) {
$bad_nodes[] = $entry['nid'];
}
return $bad_nodes;
}
// malformed node cannot be deleted by standard way
// that's the reason why we need this - clean up after failures
// parameter shall be an array
function erase_nodes($nodes) {
if (!is_array($nodes) ) return;
if (!count($nodes) ) return;
db_query("DELETE FROM {node} WHERE nid IN (" . implode(',', $nodes) . ")");
db_query("DELETE FROM {node_revisions} WHERE nid IN (" . implode(',', $nodes) . ")");
db_query("DELETE FROM {comments} WHERE nid IN (" . implode(',', $nodes) . ")");
}
?>