From 6854cb3f4d8219cf1829e32122eb2502a916eae9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 1 Feb 2020 09:05:48 +0100 Subject: initial checkin --- setup/upgrade/0.9.9/clean_unique.php | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 setup/upgrade/0.9.9/clean_unique.php (limited to 'setup/upgrade/0.9.9/clean_unique.php') 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 @@ +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'])); + } +} +?> -- cgit v1.2.3-70-g09d2