Permalink
Browse files

Merge pull request #1085 from AmyStephen/user

User Package: ->error, Exceptions, JError
  • Loading branch information...
2 parents 4be2323 + 5c1e740 commit 6977881ebf06c2fb4f13ab6dc93148926f7170a4 @chdemko chdemko committed Mar 31, 2012
Showing with 14 additions and 37 deletions.
  1. +9 −29 libraries/joomla/user/helper.php
  2. +5 −8 libraries/joomla/user/user.php
@@ -27,9 +27,10 @@
* @param integer $userId The id of the user.
* @param integer $groupId The id of the group.
*
- * @return mixed Boolean true on success, Exception on error.
+ * @return mixed Boolean true on success
*
* @since 11.1
+ * @throws RuntimeException
*/
public static function addUserToGroup($userId, $groupId)
{
@@ -48,26 +49,17 @@ public static function addUserToGroup($userId, $groupId)
$db->setQuery($query);
$title = $db->loadResult();
- // Check for a database error.
- if ($db->getErrorNum())
- {
- return new Exception($db->getErrorMsg());
- }
-
// If the group does not exist, return an exception.
if (!$title)
{
- return new Exception(JText::_('JLIB_USER_EXCEPTION_ACCESS_USERGROUP_INVALID'));
+ throw new RuntimeException('Access Usergroup Invalid');
}
// Add the group data to the user object.
$user->groups[$title] = $groupId;
// Store the user object.
- if (!$user->save())
- {
- return new Exception($user->getError());
- }
+ $user->save();
}
// Set the group data for any preloaded user objects.
@@ -89,7 +81,7 @@ public static function addUserToGroup($userId, $groupId)
*
* @param integer $userId The id of the user.
*
- * @return mixed Array on success, JException on error.
+ * @return mixed Array on success
*
* @since 11.1
*/
@@ -107,7 +99,7 @@ public static function getUserGroups($userId)
* @param integer $userId The id of the user.
* @param integer $groupId The id of the group.
*
- * @return mixed Boolean true on success, JException on error.
+ * @return mixed Boolean true on success
*
* @since 11.1
*/
@@ -124,10 +116,7 @@ public static function removeUserFromGroup($userId, $groupId)
unset($user->groups[$key]);
// Store the user object.
- if (!$user->save())
- {
- return new JException($user->getError());
- }
+ $user->save();
}
// Set the group data for any preloaded user objects.
@@ -150,7 +139,7 @@ public static function removeUserFromGroup($userId, $groupId)
* @param integer $userId The id of the user.
* @param array $groups An array of group ids to put the user in.
*
- * @return mixed Boolean true on success, Exception on error.
+ * @return mixed Boolean true on success
*
* @since 11.1
*/
@@ -172,23 +161,14 @@ public static function setUserGroups($userId, $groups)
$db->setQuery($query);
$results = $db->loadObjectList();
- // Check for a database error.
- if ($db->getErrorNum())
- {
- return new Exception($db->getErrorMsg());
- }
-
// Set the titles for the user groups.
for ($i = 0, $n = count($results); $i < $n; $i++)
{
$user->groups[$results[$i]->id] = $results[$i]->title;
}
// Store the user object.
- if (!$user->save())
- {
- return new Exception($user->getError());
- }
+ $user->save();
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
@@ -625,7 +625,7 @@ public function bind(&$array)
* @return boolean True on success
*
* @since 11.1
- * @throws exception
+ * @throws RuntimeException
*/
public function save($updateOnly = false)
{
@@ -680,7 +680,7 @@ public function save($updateOnly = false)
{
if (JAccess::checkGroup($groupId, 'core.admin'))
{
- throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
+ throw new RuntimeException('User not Super Administrator');
}
}
}
@@ -689,7 +689,7 @@ public function save($updateOnly = false)
// I am not a Super Admin, and this one is, so fail.
if (JAccess::check($this->id, 'core.admin'))
{
- throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
+ throw new RuntimeException('User not Super Administrator');
}
if ($this->groups != null)
@@ -699,7 +699,7 @@ public function save($updateOnly = false)
{
if (JAccess::checkGroup($groupId, 'core.admin'))
{
- throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
+ throw new RuntimeException('User not Super Administrator');
}
}
}
@@ -718,10 +718,7 @@ public function save($updateOnly = false)
}
// Store the user data in the database
- if (!($result = $table->store()))
- {
- throw new Exception($table->getError());
- }
+ $result = $table->store();
// Set the id for the JUser object in case we created a new user.
if (empty($this->id))

0 comments on commit 6977881

Please sign in to comment.