Skip to content

Commit

Permalink
Deprecate add() in favor of saveRelations()
Browse files Browse the repository at this point in the history
  • Loading branch information
elidrissidev committed Jan 24, 2023
1 parent 6634a23 commit bf591d6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 36 deletions.
36 changes: 2 additions & 34 deletions app/code/core/Mage/Admin/Model/Resource/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,45 +306,13 @@ public function getRoles(Mage_Core_Model_Abstract $user)
/**
* Save user roles
*
* @deprecated Use {@see _saveRelations} instead.
* @param Mage_Core_Model_Abstract|Mage_Admin_Model_User $user
* @return $this
*/
public function add(Mage_Core_Model_Abstract $user)
{
$dbh = $this->_getWriteAdapter();
$aRoles = $this->hasAssigned2Role($user);
if (count($aRoles)) {
foreach ($aRoles as $idx => $data) {
$dbh->delete(
$this->getTable('admin/role'),
['role_id = ?' => $data['role_id']]
);
}
}

if ($user->getId() > 0) {
$role = Mage::getModel('admin/role')->load($user->getRoleId());
} else {
$role = new Varien_Object(['tree_level' => 0]);
}

$data = new Varien_Object([
'parent_id' => $user->getRoleId(),
'tree_level' => $role->getTreeLevel() + 1,
'sort_order' => 0,
'role_type' => Mage_Admin_Model_Acl::ROLE_TYPE_USER,
'user_id' => $user->getUserId(),
'role_name' => $user->getFirstname()
]);

$insertData = $this->_prepareDataForTable($data, $this->getTable('admin/role'));
$dbh->insert($this->getTable('admin/role'), $insertData);

if ($user->getId() > 0) {
// reload acl on next user http request
$this->saveReloadAclFlag($user, 1);
}

$this->_saveRelations($user);
return $this;
}

Expand Down
3 changes: 2 additions & 1 deletion app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,12 @@ public function roleUserExists()
/**
* Assign user to role
*
* @deprecated Use {@see saveRelations} instead.
* @return $this
*/
public function add()
{
$this->_getResource()->add($this);
$this->saveRelations();
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected function _addUserToRole($userId, $roleId)
if ($user->roleUserExists() === true) {
return false;
} else {
$user->add();
$user->saveRelations();
return true;
}
}
Expand Down

0 comments on commit bf591d6

Please sign in to comment.