Skip to content

Commit

Permalink
Ticket 557: delete user in user_auth_providers
Browse files Browse the repository at this point in the history
Delete user in user_auth_providers if the user gets deleted.
  • Loading branch information
blackcoder87 committed Oct 25, 2018
1 parent 93eb662 commit 811ffb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions application/modules/user/controllers/admin/Index.php
Expand Up @@ -15,6 +15,7 @@
use Modules\User\Models\Group as GroupModel;
use Modules\User\Service\Password as PasswordService;
use Modules\Admin\Mappers\Emails as EmailsMapper;
use Modules\User\Mappers\AuthProvider as AuthProvider;
use \Ilch\Registry as Registry;
use Ilch\Validation;

Expand Down Expand Up @@ -372,6 +373,7 @@ public function deleteAction()
$authTokenMapper = new AuthTokenMapper();
$statisticMapper = new StatisticMapper();
$profileFieldsContentMapper = new ProfileFieldsContentMapper();
$authProviderMapper = new AuthProvider();

$userId = $this->getRequest()->getParam('id');

Expand Down Expand Up @@ -405,6 +407,7 @@ public function deleteAction()
}

$profileFieldsContentMapper->deleteProfileFieldContentByUserId($userId);
$authProviderMapper->deleteUser($userId);
if ($userMapper->delete($userId)) {
$authTokenMapper->deleteAllAuthTokenOfUser($userId);
$statisticMapper->deleteUserOnline($userId);
Expand Down
18 changes: 18 additions & 0 deletions application/modules/user/mappers/AuthProvider.php
Expand Up @@ -183,6 +183,24 @@ public function unlinkUser($provider, $user_id)
return $result;
}

/**
* Delete user by id.
* Call this function if the user for example gets deleted and therefore
* the links to the auth providers of that deleted user are of no use anymore.
*
* @param $user_id
* @return \Ilch\Database\Mysql\Result|int
*/
public function deleteUser($user_id)
{
$result = $this->db()->delete()
->from($this->default_table)
->where(['user_id' => $user_id])
->execute();

return $result;
}

public function authProvidersModuleExistsForProvider($provider, $module)
{
if (empty($module)) {
Expand Down

0 comments on commit 811ffb2

Please sign in to comment.