[TYPO3-mvc] Problem while adding Usergroups to an (extended) FrontendUser

Nils Blattner nb at cabag.ch
Tue Feb 9 18:24:41 CET 2010


Am 29.01.10 16:08, schrieb Nils Blattner:
> Hi there
>
> Basic scenario is this:
>
> I have my own user class extend Tx_Extbase_Domain_Model_FrontendUser.
> I add Usergroups with the inherited addUsergroup().
> They are actually in there (checked with print_r()).
> BUT, they don't get saved to the db.
> I copied the typoscript settings for the mapping done with the
> FrontendUser but it still doesnt save the groups.
>
> I'm trying not to work with commaseparated lists, but im kind of forced
> to do it here.
>
> So if anyone can tell me if this is a fundamental flaw with extbase or
> i'm missing some setting, i'd be very thankful.
>
> Regards, Nils

I was asked how I solved this issue, so I'll post it here:

I know this is not extbase at all, but I ended up injecting the 
usergroups manually with exec_UPDATEquery() like so:

/**
  * Injects the default user group to the user (directly in the db)
  *
  * @param Tx_CabagSteps_Domain_Model_User $user The user to inject to.
  * @return void
  */
protected function 
injectDefaultUserGroup(Tx_CabagSteps_Domain_Model_User $user = null) {
	if ($user == null) return;
	$query = 'UPDATE `fe_users` SET `usergroup` = \'' . 
$this->defaultUserGroup . '\' WHERE `uid` = \'' . $user->getUid() . '\';';
	return $GLOBALS['TYPO3_DB']->sql_query($query);
}

$this->defaultUserGroup beeing a string with commaseparated uids of 
usergroups (how its stored).

Since my user objects were freshly created I had to do the following ...

In the userRepository I added the following method:


	
/**
  * Persists all unsaved elements.
  *
  * @return void
  */
public function persistAll() {
	$this->persistenceManager->persistAll();
}



Now in your action (or wherever you have to inject the groups)
Note that the persistAll() makes the persistence manager insert the new 
objects AND update their uids to correspond to the db.
The check for null is not really necessary, but I had to be on the safe 
side... :)

	// hack to inject the default usergroup with standard UPDATE query
	$this->userRepository->persistAll();
	foreach ($t_users as $user) {
		if ($user != null) {
			$this->injectDefaultUserGroup($user);
			
		}
	}



The basic reason behind my doing it this way is simple:
No time to go digging endlessly, so I just did it quick and dirty.

Im sure theres an extbase way, however this works and thats what counts 
at the end of the day.


More information about the TYPO3-project-typo3v4mvc mailing list