Update needed for onBeforeStoreUser event documentation

Joomla! Documentation Workgroup

Moderator: Documentation

Locked
User avatar
tomthornz
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Thu Feb 16, 2006 6:33 pm
Location: UK

Update needed for onBeforeStoreUser event documentation

Post by tomthornz » Wed Jan 14, 2009 9:58 am

I've recently come across an issue with the documentation for onBeforeStoreUser event.

It does not mention that the event is fired when a user is updated, only for new users added. The documentation for onAfterStoreUser mentions that it is fired for both new users and updates to users, so there is a little inconsistency which caused confusion.

After checking the code in *libraries/joomla/user/user.php I found that the event is definitely called on both new and updates:

Code: Select all

// Get the old user
$old = new JUser($this->id);

// Fire the onBeforeStoreUser event.
JPluginHelper::importPlugin( 'user' );
$dispatcher =& JDispatcher::getInstance();
$dispatcher->trigger( 'onBeforeStoreUser', array( $old->getProperties(), $isnew ) );

//Store the user data in the database
if (!$result = $table->store()) {
	$this->setError($table->getError());
}

// Set the id for the JUser object in case we created a new user.
if (empty($this->id)) {
	$this->id = $table->get( 'id' );
}

// Fire the onAftereStoreUser event
$dispatcher->trigger( 'onAfterStoreUser', array( $this->getProperties(), $isnew, $result, $this->getError() ) );
I'm not sure if this is the best place to post this info but I wasn't sure how else to let you guys know!
Please read forum rules regarding signatures: http://forum.joomla.org/viewtopic.php?t=65

User avatar
Pentacle
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 165
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: Update needed for onBeforeStoreUser event documentation

Post by Pentacle » Wed Jan 14, 2009 11:30 am

Why don't you go ahead and change it? Anyone can edit that page. Just get an ID at that site and correct it. :)
My Joomla! 1.5 extensions - http://ercan.us
Progress is made by lazy men looking for easier ways to do things.

User avatar
tomthornz
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Thu Feb 16, 2006 6:33 pm
Location: UK

Re: Update needed for onBeforeStoreUser event documentation

Post by tomthornz » Wed Jan 14, 2009 12:42 pm

Cool, update made, very easy to do too!
Please read forum rules regarding signatures: http://forum.joomla.org/viewtopic.php?t=65

billengle
Joomla! Intern
Joomla! Intern
Posts: 89
Joined: Thu Apr 30, 2009 6:21 pm
Contact:

Re: Update needed for onBeforeStoreUser event documentation

Post by billengle » Wed Jan 06, 2010 7:51 pm

Sorry the documentation change you made was wrong. I updated it. I am running 1.5.15. I was spinning my wheels for a while based on the documentation update until I looked at /libraries/joomla/user/user.php and then ultimately found this thread. There is no new user data being passed here, only old! The code you posted is the same as it currently is in 1.5.15.

Code: Select all

		// Get the old user
		$old = new JUser($this->id); <- the new user hasn't been created yet so this is NULL

		// Fire the onBeforeStoreUser event.
		JPluginHelper::importPlugin( 'user' );
		$dispatcher =& JDispatcher::getInstance();
		$dispatcher->trigger( 'onBeforeStoreUser', array( $old->getProperties(), $isnew ) );
See ...
http://groups.google.es/group/joomla-de ... 9062ed1c6a

Luckily there is a patch in that discussion that does what the documentation now says so I am not completely stuck.

http://joomlacode.org/gf/project/joomla ... m_id=17506

sunny12
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sat Oct 09, 2010 9:55 pm

Re: Update needed for onBeforeStoreUser event documentation

Post by sunny12 » Sat Oct 09, 2010 10:04 pm

billengle wrote:Sorry the documentation change you made was wrong. I updated it. I am running 1.5.15. I was spinning my wheels for a while based on the documentation update until I looked at /libraries/joomla/user/user.php and then ultimately found this thread. There is no new user data being passed here, only old! The code you posted is the same as it currently is in 1.5.15.

Code: Select all

		// Get the old user
		$old = new JUser($this->id); <- the new user hasn't been created yet so this is NULL

		// Fire the onBeforeStoreUser event.
		JPluginHelper::importPlugin( 'user' );
		$dispatcher =& JDispatcher::getInstance();
		$dispatcher->trigger( 'onBeforeStoreUser', array( $old->getProperties(), $isnew ) );
See ...
http://groups.google.es/group/joomla-de ... 9062ed1c6a

Luckily there is a patch in that discussion that does what the documentation now says so I am not completely stuck.

http://joomlacode.org/gf/project/joomla ... m_id=17506
Thanks for correction billengle. The patch really did the job. :)

[Mod Note: Links deleted. Please see Forum Rules.]
Last edited by Chris Davenport on Sat Oct 23, 2010 8:33 pm, edited 1 time in total.
Reason: Deleted spam links.

homemade
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Mon Jan 12, 2009 10:30 am

Re: Update needed for onBeforeStoreUser event documentation

Post by homemade » Sat Feb 12, 2011 2:24 pm

Will this patch ever become native. Because I would love the ability to manipulate new user's information. Like change the username to a standardize method.

I want emails to be the main ~primary key for logging in. If not, i will try to access the class individually via parent or something along those lines.

homemade
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Mon Jan 12, 2009 10:30 am

Re: Update needed for onBeforeStoreUser event documentation

Post by homemade » Sat Feb 12, 2011 2:41 pm

Actually no need for the patch. I thought about for about 15 minutes and came up with this.

Code: Select all

		$u = JFactory::getUser();
		$post = JRequest::get('post');
		$u->bind($post);

		$props = $u->getProperties();
something like this pretty much get new user credentials and you can manipulate it and add it to $user by doing a pass by reference assignment to onBeforeStoreUser( & user, isNew)
etc...etc...maybe

This is just in case some one needs this for the future to spark a thought process.

peace.


Locked

Return to “docs.joomla.org - Feedback/Information”