Skip to content

Commit 36186da

Browse files
authored
ENGCOM-5664: Resolve undefine variable in _createUserRole function #24182
2 parents e56640c + d4013e1 commit 36186da

File tree

1 file changed

+21
-24
lines changed
  • app/code/Magento/User/Model/ResourceModel

1 file changed

+21
-24
lines changed

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

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\User\Model\ResourceModel;
810

911
use Magento\Authorization\Model\Acl\Role\Group as RoleGroup;
@@ -208,27 +210,23 @@ protected function _createUserRole($parentId, ModelUser $user)
208210
if ($parentId > 0) {
209211
/** @var \Magento\Authorization\Model\Role $parentRole */
210212
$parentRole = $this->_roleFactory->create()->load($parentId);
211-
} else {
212-
$role = new \Magento\Framework\DataObject();
213-
$role->setTreeLevel(0);
214-
}
215-
216-
if ($parentRole->getId()) {
217-
$data = new \Magento\Framework\DataObject(
218-
[
219-
'parent_id' => $parentRole->getId(),
220-
'tree_level' => $parentRole->getTreeLevel() + 1,
221-
'sort_order' => 0,
222-
'role_type' => RoleUser::ROLE_TYPE,
223-
'user_id' => $user->getId(),
224-
'user_type' => UserContextInterface::USER_TYPE_ADMIN,
225-
'role_name' => $user->getFirstName(),
226-
]
227-
);
228-
229-
$insertData = $this->_prepareDataForTable($data, $this->getTable('authorization_role'));
230-
$this->getConnection()->insert($this->getTable('authorization_role'), $insertData);
231-
$this->aclDataCache->clean();
213+
if ($parentRole->getId()) {
214+
$data = new \Magento\Framework\DataObject(
215+
[
216+
'parent_id' => $parentRole->getId(),
217+
'tree_level' => $parentRole->getTreeLevel() + 1,
218+
'sort_order' => 0,
219+
'role_type' => RoleUser::ROLE_TYPE,
220+
'user_id' => $user->getId(),
221+
'user_type' => UserContextInterface::USER_TYPE_ADMIN,
222+
'role_name' => $user->getFirstName(),
223+
]
224+
);
225+
226+
$insertData = $this->_prepareDataForTable($data, $this->getTable('authorization_role'));
227+
$this->getConnection()->insert($this->getTable('authorization_role'), $insertData);
228+
$this->aclDataCache->clean();
229+
}
232230
}
233231
}
234232

@@ -267,8 +265,6 @@ public function delete(\Magento\Framework\Model\AbstractModel $user)
267265
['user_id = ?' => $uid, 'user_type = ?' => UserContextInterface::USER_TYPE_ADMIN]
268266
);
269267
} catch (\Magento\Framework\Exception\LocalizedException $e) {
270-
throw $e;
271-
} catch (\Exception $e) {
272268
$connection->rollBack();
273269
return false;
274270
}
@@ -476,7 +472,7 @@ public function updateRoleUsersAcl(\Magento\Authorization\Model\Role $role)
476472
$users = $role->getRoleUsers();
477473
$rowsCount = 0;
478474

479-
if (sizeof($users) > 0) {
475+
if (count($users) > 0) {
480476
$bind = ['reload_acl_flag' => 1];
481477
$where = ['user_id IN(?)' => $users];
482478
$rowsCount = $connection->update($this->getTable('admin_user'), $bind, $where);
@@ -618,6 +614,7 @@ public function trackPassword($user, $passwordHash, $lifetime = 0)
618614

619615
/**
620616
* Get latest password for specified user id
617+
*
621618
* Possible false positive when password was changed several times with different lifetime configuration
622619
*
623620
* @param int $userId

0 commit comments

Comments
 (0)