/**
  * Method to save the JUser object to the database
  *
  * @param   boolean  $updateOnly  Save the object only if not a new user
  *                                Currently only used in the user reset password method.
  *
  * @return  boolean  True on success
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 public function save($updateOnly = false)
 {
     // Create the user table object
     $table = $this->getTable();
     $this->params = (string) $this->_params;
     $table->bind($this->getProperties());
     // Allow an exception to be thrown.
     try {
         // Check and store the object.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // If user is made a Super Admin group and user is NOT a Super Admin
         // @todo ACL - this needs to be acl checked
         $my = Factory::getUser();
         // Are we creating a new user
         $isNew = empty($this->id);
         // If we aren't allowed to create new users return
         if ($isNew && $updateOnly) {
             return true;
         }
         // Get the old user
         $oldUser = new User($this->id);
         // Access Checks
         // The only mandatory check is that only Super Admins can operate on other Super Admin accounts.
         // To add additional business rules, use a user plugin and throw an Exception with onUserBeforeSave.
         // Check if I am a Super Admin
         $iAmSuperAdmin = $my->authorise('core.admin');
         // We are only worried about edits to this account if I am not a Super Admin.
         if ($iAmSuperAdmin != true) {
             if ($isNew) {
                 // Check if the new user is being put into a Super Admin group.
                 foreach ($this->groups as $groupId) {
                     if (Access::checkGroup($groupId, 'core.admin')) {
                         throw new RuntimeException('User not Super Administrator');
                     }
                 }
             } else {
                 // I am not a Super Admin, and this one is, so fail.
                 if (Access::check($this->id, 'core.admin')) {
                     throw new RuntimeException('User not Super Administrator');
                 }
                 if ($this->groups != null) {
                     // I am not a Super Admin and I'm trying to make one.
                     foreach ($this->groups as $groupId) {
                         if (Access::checkGroup($groupId, 'core.admin')) {
                             throw new RuntimeException('User not Super Administrator');
                         }
                     }
                 }
             }
         }
         // Fire the onUserBeforeSave event.
         PluginHelper::importPlugin('user');
         $dispatcher = Dispatcher::getInstance();
         $result = $dispatcher->trigger('onUserBeforeSave', array($oldUser->getProperties(), $isNew, $this->getProperties()));
         if (in_array(false, $result, true)) {
             // Plugin will have to raise its own error or throw an exception.
             return false;
         }
         // Store the user data in the database
         $result = $table->store();
         // Set the id for the JUser object in case we created a new user.
         if (empty($this->id)) {
             $this->id = $table->get('id');
         }
         if ($my->id == $table->id) {
             $registry = new Registry();
             $registry->loadString($table->params);
             $my->setParameters($registry);
         }
         // Fire the onUserAfterSave event
         $dispatcher->trigger('onUserAfterSave', array($this->getProperties(), $isNew, $result, $this->getError()));
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     return $result;
 }