コード例 #1
0
ファイル: User.php プロジェクト: bharatm/NDL-VuFind
 /**
  * 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;
 }