{"action":"created","issue":{"url":"https://api.github.com/repos/kimai/kimai/issues/501","labels_url":"https://api.github.com/repos/kimai/kimai/issues/501/labels{/name}","comments_url":"https://api.github.com/repos/kimai/kimai/issues/501/comments","events_url":"https://api.github.com/repos/kimai/kimai/issues/501/events","html_url":"https://github.com/kimai/kimai/issues/501","id":92049532,"number":501,"title":"Incomplete delete - users","user":{"login":"cloudeasy","id":5797415,"avatar_url":"https://avatars.githubusercontent.com/u/5797415?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudeasy","html_url":"https://github.com/cloudeasy","followers_url":"https://api.github.com/users/cloudeasy/followers","following_url":"https://api.github.com/users/cloudeasy/following{/other_user}","gists_url":"https://api.github.com/users/cloudeasy/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudeasy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudeasy/subscriptions","organizations_url":"https://api.github.com/users/cloudeasy/orgs","repos_url":"https://api.github.com/users/cloudeasy/repos","events_url":"https://api.github.com/users/cloudeasy/events{/privacy}","received_events_url":"https://api.github.com/users/cloudeasy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-30T10:03:43Z","updated_at":"2015-07-04T14:50:20Z","closed_at":null,"body":"Hello again,\r\n\r\nI'm looking at the admin->membership roles, and I see a users count of 20 on the admin role... but there are only 5 users...\r\n\r\nSo, Mysql->user_delete() does not include the following related tables\r\n  groups_users\r\n  preferences\r\n  rates\r\n  timesheet\r\nI will leave timesheet alone because of possible negative consequences, but the other tables should be cleaned of the deleted user, otherwise we are leaving dead data.\r\n\r\nSo here's my version of function user_delete():\r\nfile: libraries/Kimai/Database/Mysql.php\r\n```php\r\n    public function user_delete($userID, $moveToTrash = false)\r\n    {\r\n        $userID = MySQL::SQLValue($userID, MySQL::SQLVALUE_NUMBER);\r\n        if ($moveToTrash) {\r\n            $values['trash']  = 1;\r\n            $filter['userID'] = $userID;\r\n            $table            = $this->kga['server_prefix'] . \"users\";\r\n\r\n            $query = MySQL::BuildSQLUpdate($table, $values, $filter);\r\n\r\n            return $this->conn->Query($query);\r\n        }\r\n\r\n        $query  = \"DELETE FROM \" . $this->kga['server_prefix'] . \"groups_users WHERE userID = \" . $userID;\r\n        $result = $this->conn->Query($query);\r\n\r\n        if ($result === false) {\r\n            $this->logLastError('groups_user_delete');\r\n\r\n            return false;\r\n        }\r\n\r\n        $query  = \"DELETE FROM \" . $this->kga['server_prefix'] . \"preferences WHERE userID = \" . $userID;\r\n        $result = $this->conn->Query($query);\r\n\r\n        if ($result === false) {\r\n            $this->logLastError('preferences_delete');\r\n\r\n            return false;\r\n        }\r\n\r\n        $query  = \"DELETE FROM \" . $this->kga['server_prefix'] . \"rates WHERE userID = \" . $userID;\r\n        $result = $this->conn->Query($query);\r\n\r\n        if ($result === false) {\r\n            $this->logLastError('rates_delete');\r\n\r\n            return false;\r\n        }\r\n\r\n        $query  = \"DELETE FROM \" . $this->kga['server_prefix'] . \"users WHERE userID = \" . $userID;\r\n        $result = $this->conn->Query($query);\r\n\r\n        if ($result === false) {\r\n            $this->logLastError('user_delete');\r\n\r\n            return false;\r\n        }\r\n\r\n        return true;\r\n    }\r\n```\r\nIdeally, it's probable that a check should be done on the other table, that depends on the user entry, before performing a delete (that's probably why the trash was put there in the first place).\r\n\r\ncorrect me if you see fit. :)\r\n\r\nAnyway, that's it for now.\r\n\r\nc."},"comment":{"url":"https://api.github.com/repos/kimai/kimai/issues/comments/118517795","html_url":"https://github.com/kimai/kimai/issues/501#issuecomment-118517795","issue_url":"https://api.github.com/repos/kimai/kimai/issues/501","id":118517795,"user":{"login":"simonschaufi","id":941794,"avatar_url":"https://avatars.githubusercontent.com/u/941794?v=3","gravatar_id":"","url":"https://api.github.com/users/simonschaufi","html_url":"https://github.com/simonschaufi","followers_url":"https://api.github.com/users/simonschaufi/followers","following_url":"https://api.github.com/users/simonschaufi/following{/other_user}","gists_url":"https://api.github.com/users/simonschaufi/gists{/gist_id}","starred_url":"https://api.github.com/users/simonschaufi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonschaufi/subscriptions","organizations_url":"https://api.github.com/users/simonschaufi/orgs","repos_url":"https://api.github.com/users/simonschaufi/repos","events_url":"https://api.github.com/users/simonschaufi/events{/privacy}","received_events_url":"https://api.github.com/users/simonschaufi/received_events","type":"User","site_admin":false},"created_at":"2015-07-04T14:50:20Z","updated_at":"2015-07-04T14:50:20Z","body":"thank you for your contribution but you don't consider the $moveToTrash parameter which is important. could you create a pull request? that would be great!"}}