Skip to content

Commit bd1696b

Browse files
committed
MC-30109: Deleting an empty user model caused deleting admin role
1 parent 3009388 commit bd1696b

File tree

1 file changed

+7
-5
lines changed
  • app/code/Magento/User/Model/ResourceModel

1 file changed

+7
-5
lines changed

app/code/Magento/User/Model/ResourceModel/User.php

100644100755
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,13 @@ public function delete(\Magento\Framework\Model\AbstractModel $user)
259259
$uid = $user->getId();
260260
$connection->beginTransaction();
261261
try {
262-
$connection->delete($this->getMainTable(), ['user_id = ?' => $uid]);
263-
$connection->delete(
264-
$this->getTable('authorization_role'),
265-
['user_id = ?' => $uid, 'user_type = ?' => UserContextInterface::USER_TYPE_ADMIN]
266-
);
262+
if ($uid) {
263+
$connection->delete($this->getMainTable(), ['user_id = ?' => $uid]);
264+
$connection->delete(
265+
$this->getTable('authorization_role'),
266+
['user_id = ?' => $uid, 'user_type = ?' => UserContextInterface::USER_TYPE_ADMIN]
267+
);
268+
}
267269
} catch (\Magento\Framework\Exception\LocalizedException $e) {
268270
$connection->rollBack();
269271
return false;

0 commit comments

Comments
 (0)