Exemple #1
0
 /**
  * Test delete user home directory
  */
 public function testDeleteUserHomeDirectory()
 {
     // test user data
     $data = ['nick_name' => Rand::getString(32), 'email' => Rand::getString(32), 'api_key' => Rand::getString(32), 'role' => AclModelBase::DEFAULT_ROLE_MEMBER, 'language' => null];
     // create a test user
     $query = $this->userModel->insert()->into('user_list')->values($data);
     $statement = $this->userModel->prepareStatementForSqlObject($query);
     $statement->execute();
     $testUserId = $this->userModel->getAdapter()->getDriver()->getLastGeneratedValue();
     // create a test user's home directory
     $homeUserDirectory = FileManagerBaseModel::getUserBaseFilesDir($testUserId) . '/' . FileManagerBaseModel::getHomeDirectoryName();
     FileSystemUtility::createDir($homeUserDirectory);
     // fire the delete user event
     UserEvent::fireUserDeleteEvent($testUserId, $data);
     // delete the created user
     $query = $this->userModel->delete()->from('user_list')->where(['user_id' => $testUserId]);
     $statement = $this->userModel->prepareStatementForSqlObject($query);
     $statement->execute();
     // home directory must be deleted
     $this->assertFalse(file_exists($homeUserDirectory));
 }
Exemple #2
0
 /**
  * Delete an user
  *
  * @param array $userInfo
  * @param boolean $sendMessage
  * @throws User/Exception/UserException
  * @return boolean|string
  */
 public function deleteUser(array $userInfo, $sendMessage = true)
 {
     // fire the delete user event
     UserEvent::fireUserDeleteEvent($userInfo['user_id'], $sendMessage ? $userInfo : []);
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $delete = $this->delete()->from('user_list')->where(['user_id' => $userInfo['user_id']])->where([new NotInPredicate('user_id', [self::DEFAULT_USER_ID])]);
         $statement = $this->prepareStatementForSqlObject($delete);
         $result = $statement->execute();
         // delete an avatar
         if ($userInfo['avatar']) {
             if (true !== ($avatarDeleteResult = $this->deleteUserAvatar($userInfo['avatar']))) {
                 throw new UserException('Avatar deleting failed');
             }
         }
         // clear caches
         $this->removeUserCache($userInfo['user_id']);
         $this->clearActiveUsersCache();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return $result->count() ? true : false;
 }