forked from os2loop/profile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.php
51 lines (44 loc) · 1.02 KB
/
cleanup.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
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env drush
<?php
/**
* @file Cleanup flagging.
*/
// Delete every flagged message.
db_delete('flagging')
->condition('entity_type', 'message')
->execute();
// Delete every flagged nodes.
db_delete('flagging')
->condition('entity_type', 'node')
->execute();
// Delete all messages.
db_delete('message')
->execute();
// Get post nodes.
$nodes = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'post')
->condition('status', 1)
->execute()
->fetchAllAssoc('nid');
// Get every user.
$users = db_select('users', 'u')
->fields('u', array('uid'))
->condition('status', 1)
->execute()
->fetchAllAssoc('uid');
// Insert flagging according to nodes and users.
foreach (array_keys($nodes) as $node) {
foreach (array_keys($users) as $user) {
db_insert('flagging')
->fields(array(
'fid' => 3,
'entity_type' => 'node',
'entity_id' => $node,
'uid' => $user,
'sid' => 0,
'timestamp' => REQUEST_TIME,
))
->execute();
}
}