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
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2020-02-01 09:05:48 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2020-02-01 09:05:48 +0100
commit6854cb3f4d8219cf1829e32122eb2502a916eae9 (patch)
tree350feb504587d932e02837a1442b059759927646 /setup/upgrade/0.9.9/clean_unique.php
initial checkin
Diffstat (limited to 'setup/upgrade/0.9.9/clean_unique.php')
-rw-r--r--setup/upgrade/0.9.9/clean_unique.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/setup/upgrade/0.9.9/clean_unique.php b/setup/upgrade/0.9.9/clean_unique.php
new file mode 100644
index 0000000..652630b
--- /dev/null
+++ b/setup/upgrade/0.9.9/clean_unique.php
@@ -0,0 +1,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']));
+ }
+}
+?>