Piwik\Plugins\UsersManager\Model::deleteUserOnly PHP Method

deleteUserOnly() public method

public deleteUserOnly ( $userLogin )
    public function deleteUserOnly($userLogin)
    {
        $db = $this->getDb();
        $db->query("DELETE FROM " . $this->table . " WHERE login = ?", $userLogin);
        /**
         * Triggered after a user has been deleted.
         *
         * This event should be used to clean up any data that is related to the now deleted user.
         * The **Dashboard** plugin, for example, uses this event to remove the user's dashboards.
         *
         * @param string $userLogin The login handle of the deleted user.
         */
        Piwik::postEvent('UsersManager.deleteUser', array($userLogin));
    }

Usage Example

Example #1
0
 /**
  * Delete a user and all its access, given its login.
  *
  * @param string $userLogin the user login.
  *
  * @throws Exception if the user doesn't exist
  *
  * @return bool true on success
  */
 public function deleteUser($userLogin)
 {
     Piwik::checkUserHasSuperUserAccess();
     $this->checkUserIsNotAnonymous($userLogin);
     if (!$this->userExists($userLogin)) {
         throw new Exception(Piwik::translate("UsersManager_ExceptionDeleteDoesNotExist", $userLogin));
     }
     if ($this->isUserTheOnlyUserHavingSuperUserAccess($userLogin)) {
         $message = Piwik::translate("UsersManager_ExceptionDeleteOnlyUserWithSuperUserAccess", $userLogin) . " " . Piwik::translate("UsersManager_ExceptionYouMustGrantSuperUserAccessFirst");
         throw new Exception($message);
     }
     $this->model->deleteUserOnly($userLogin);
     $this->model->deleteUserAccess($userLogin);
     Cache::deleteTrackerCache();
 }