Notice

The forum is in read only mode.

Support Forum

Welcome! Support Forums have been reactivated
Welcome the Technical Support section. Help us in assisting you by providing us with a concise and descriptive elaboration of your issues. Be specific and if possible, provide us with a step-by-step instruction in replicating your problem.

User Groups Being Deslected/Disappearing

10 years 3 months ago
  • Joseph's Avatar
    Topic Author
  • Joseph
  • Offline
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 1
Licenses:
JomSocial Expired

J! user groups are being modified by Jomsocial, seemingly randomly. This has been addressed here: www.jomsocial.com/forum/groups/21513-use...ging-randomly#110459

I tried the fix, and it resulted in an error. I'm happy to modify any files necessary, I just need to know which ones to do.

FYI, even the main Joomla Super User was modified at one point, becoming a Registered only user. Yikes!

10 years 3 months ago
Licenses:

Hi Joseph,

please follow the instruction carefully.
1. edit [your joomla site location]/libraries/joomla/table/user.php at line 291 you can find the following function

public function store($updateNulls = false)
	{
		// Get the table key and key value.
		$k = $this->_tbl_key;
		$key = $this->$k;

		// TODO: This is a dumb way to handle the groups.
		// Store groups locally so as to not update directly.
		$groups = $this->groups;
		unset($this->groups);

		// Insert or update the object based on presence of a key value.
		if ($key)
		{
			// Already have a table key, update the row.
			$this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
		}
		else
		{
			// Don't have a table key, insert the row.
			$this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
		}

		// Reset groups to the local object.
		$this->groups = $groups;
		unset($groups);

		$query = $this->_db->getQuery(true);

		// Store the group data if the user data was saved.
		if (is_array($this->groups) && count($this->groups))
		{
			// Delete the old user group maps.
			$query->delete($this->_db->quoteName('#__user_usergroup_map'))
				->where($this->_db->quoteName('user_id') . ' = ' . (int) $this->id);
			$this->_db->setQuery($query);
			$this->_db->execute();

			// Set the new user group maps.
			$query->clear()
				->insert($this->_db->quoteName('#__user_usergroup_map'))
				->columns(array($this->_db->quoteName('user_id'), $this->_db->quoteName('group_id')));

			// Have to break this up into individual queries for cross-database support.
			foreach ($this->groups as $group)
			{
				$query->clear('values')
					->values($this->id . ', ' . $group);
				$this->_db->setQuery($query);
				$this->_db->execute();
			}
		}

		// If a user is blocked, delete the cookie login rows
		if ($this->block == (int) 1)
		{
			$query->clear()
				->delete($this->_db->quoteName('#__user_keys'))
				->where($this->_db->quoteName('user_id') . ' = ' . $this->_db->quote($this->username));
			$this->_db->setQuery($query);
			$this->_db->execute();
		}

		return true;
	}
changing it to
public function store($updateNulls = false)
{
	// Get the table key and key value.
	$k = $this->_tbl_key;
	$key = $this->$k;

	// TODO: This is a dumb way to handle the groups.
	// Store groups locally so as to not update directly.
	$groups = $this->groups;
	unset($this->groups);

	// Insert or update the object based on presence of a key value.
	if ($key)
	{
		// Already have a table key, update the row.
		$this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
	}
	else
	{
		// Don't have a table key, insert the row.
		$this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
	}

	// Reset groups to the local object.
	$this->groups = $groups;
	unset($groups);

	$query = $this->_db->getQuery(true);

	// Update the group data if the user data was saved.
	if (is_array($this->groups) && count($this->groups))
	{
        // Grab all usergroup entries for the user
        $query  -> clear()
                -> select('*')
                -> from($this->_db->quoteName('#__user_usergroup_map'))
                -> where($this->_db->quoteName('user_id') . ' = ' . (int) $this->id);

        $this->_db->setQUery($query);
        $result = $this->_db->loadObjectList();

        // Loop through them and check if database contains something $this->groups does not
        if(sizeof($result)) {

            foreach($result as $map) {

                if(array_key_exists($map->group_id, $this->groups)) {
                    // it already exists, no action required
                    unset($this->groups[$map->group_id]);
                } else {
                    // it should be removed
                    $query  -> clear()
                            -> delete($this->_db->quoteName('#__user_usergroup_map'))
                            -> where($this->_db->quoteName('user_id') . ' = ' . (int) $this->id)
                            -> where($this->_db->quoteName('group_id') . ' = ' . (int) $map->group_id);

                    $this->_db->setQuery($query);
                    $this->_db->execute();
                }
            }
        }

        // If there is anything left in this->groups it needs to be inserted
        if(sizeof($this->groups)) {

            // Set the new user group maps.
            $query->clear()
                ->insert($this->_db->quoteName('#__user_usergroup_map'))
                ->columns(array($this->_db->quoteName('user_id'), $this->_db->quoteName('group_id')));

            // Have to break this up into individual queries for cross-database support.
            foreach ($this->groups as $group) {
                $query->clear('values')
                    ->values($this->id . ', ' . $group);
                $this->_db->setQuery($query);
                $this->_db->execute();
            }
        }
	}

	return true;
}

if any administrator / super user already as registered, you must manually revert it back to administrator / super user from joomla users manager

Regards

Moderators: Piotr Garasiński
Powered by Kunena Forum

Join 180,000 websites creating Amazing communities

JomSocial is the most complete, easy-to-use addon that turns Joomla CMS into a
full -fledged, social networking site

TRY NOW BUY NOW