Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/setup/upgrade/0.9.9/clean_unique.php
blob: 652630bb34bfdf26d69fa5661b2c4c04e78be0a7 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
   /**********************************************************\
   | This script removes duplicate db entries                 |
   \**********************************************************/

// Users

$users = $db->query('SELECT * FROM {users} ORDER BY user_id ASC');

while ($row = $db->fetchRow($users))
{
    if (!isset($deleted[$row['user_name']])) {
        $deleted[$row['user_name']] = $row['user_id'];
    }

    $db->query('DELETE FROM {users} WHERE user_name = ? AND user_id != ?',
                array($row['user_name'], $deleted[$row['user_name']]));
}


$users = $db->query('SELECT * FROM {registrations} ORDER BY reg_id ASC');

while ($row = $db->fetchRow($users))
{
    if (!isset($deleted[$row['user_name']])) {
        $deleted[$row['user_name']] = $row['reg_id'];
    }

    $db->query('DELETE FROM {registrations} WHERE user_name = ? AND reg_id != ?',
                array($row['user_name'], $deleted[$row['user_name']]));
}

// Users in groups

$sql = $db->query('SELECT * FROM {users_in_groups} ORDER BY record_id');
while ($row = $db->fetchRow($sql))
{
    $db->query('DELETE FROM {users_in_groups} WHERE user_id = ? AND group_id = ? AND record_id <> ?',
               array($row['user_id'], $row['group_id'], $row['record_id']));
}

// Group names

$sql = $db->query('SELECT * FROM {groups} ORDER BY group_id ASC');
while ($row = $db->fetchRow($sql))
{
    $col = 'belongs_to_project';
    if (!isset($row[$col])) {
        $col = 'project_id';
    }

    $db->query('DELETE FROM {groups} WHERE group_name = ? AND '.$col.' = ? AND group_id <> ?',
               array($row['group_name'], $row[$col], $row['group_id']));
}

// Out of range value adjusted for column..
$sql = $db->query('SELECT * FROM {tasks}');
while ($row = $db->fetchRow($sql))
{
    $db->query('UPDATE {tasks} SET date_closed = ?, last_edited_time = ? WHERE task_id = ?',
               array(intval($row['date_closed']), intval($row['last_edited_time']), $row['task_id']));
    if (isset($row['due_date'])) {
       $db->query('UPDATE {tasks} SET due_date = ? WHERE task_id = ?',
                   array(intval($row['due_date']), $row['task_id']));
    }
}
?>