Piwik\Plugins\UsersManager\API::deleteUser PHP Метод

deleteUser() публичный Метод

Delete a user and all its access, given its login.
public deleteUser ( string $userLogin ) : boolean
$userLogin string the user login.
Результат boolean 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();
    }

Usage Example

Пример #1
0
 /**
  * normal case, user deleted
  */
 public function testDeleteUser()
 {
     $this->addSites(3);
     //add user and set some rights
     $this->api->addUser("geggeqgeqag", "geqgeagae", "*****@*****.**", "alias");
     $this->api->setUserAccess("geggeqgeqag", "view", array(1, 2));
     $this->api->setUserAccess("geggeqgeqag", "admin", array(1, 3));
     // check rights are set
     $this->assertNotEquals(array(), $this->api->getSitesAccessFromUser("geggeqgeqag"));
     // delete the user
     $this->api->deleteUser("geggeqgeqag");
     // try to get it, it should raise an exception
     try {
         $this->api->getUser("geggeqgeqag");
         $this->fail("Exception not raised.");
     } catch (Exception $expected) {
         $this->assertRegExp("(UsersManager_ExceptionUserDoesNotExist)", $expected->getMessage());
     }
     // add the same user
     $this->api->addUser("geggeqgeqag", "geqgeagae", "*****@*****.**", "alias");
     //checks access have been deleted
     //to do so we recreate the same user login and check if the rights are still there
     $this->assertEquals(array(), $this->api->getSitesAccessFromUser("geggeqgeqag"));
 }