/** * Anonymize user account by updating username to a random string * and setting other user object fields (besides id) to their default values. * User comments are preserved. Catalog accounts, due date reminders, * saved searches and lists are deleted. * * @return boolean True on success */ public function anonymizeAccount() { $conn = $this->getDatabaseConnection(); $res = $conn->query("START TRANSACTION"); try { // Delete catalog accounts $account = new User_account(); $account->user_id = $this->id; if ($account->find(false)) { while ($account->fetch()) { $account->delete(); } } // Delete due date reminders $reminder = new Due_date_reminder(); $reminder->user_id = $this->id; if ($reminder->find(false)) { while ($reminder->fetch()) { $reminder->delete(); } } // Delete lists (linked user_resource objects cascade) $list = new User_list(); $list->user_id = $this->id; if ($list->find(false)) { while ($list->fetch()) { $list->delete(); } } // Delete saved searches $search = new SearchEntry(); $search->user_id = $this->id; if ($search->find(false)) { while ($search->fetch()) { $search->delete(); } } // Anonymize user object $this->username = '******' . uniqid(); $this->password = ''; $this->firstname = ''; $this->lastname = ''; $this->email = ''; $this->cat_username = '******'; $this->cat_password = '******'; $this->college = ''; $this->major = ''; $this->home_library = ''; $this->language = ''; $this->due_date_notification = 0; $this->due_date_reminder = 0; $this->authMethod = 'null'; $this->update(); } catch (Exception $e) { $conn->query("ROLLBACK"); throw $e; return false; } $conn->query("COMMIT"); return true; }
/** * Delete an account * * @param int $id Account ID * * @return boolean Whether the account was deleted */ protected function deleteAccount($id) { global $user; $account = new User_account(); $account->id = $id; $account->user_id = $user->id; if ($account->find(true)) { $account->delete(); if ($user->cat_username == $account->cat_username) { // Active account deleted, select another or deactivate $account = new User_account(); $account->user_id = $user->id; if ($account->find(true)) { UserAccount::activateCatalogAccount($account->cat_username, $account->cat_password, $account->home_library); } else { UserAccount::activateCatalogAccount('', '', ''); } } return true; } return false; }