[TYPO3-mvc] update hidden / disabled records

Daniel Schöne daniel at schoene.it
Mon Apr 2 15:25:25 CEST 2012


Hi Tim,

I think the property mapper does map the hidden user. In a recent project I changed the behavior using a overridden findObjectByUid method:

/**
 * Custom Property Mapper wich works with disabled proerties (e.g. hidden / deleted).
 *
 */
class Tx_XYZ_Property_Mapper extends Tx_Extbase_Property_Mapper {

	/**
	 * Finds an object from the repository by searching for its technical UID.
	 * NOTICE: Instead of the original method this one does NOT respect enable fields
	 *
	 * @param string $dataType the data type to fetch
	 * @param int $uid The object's uid
	 * @return object Either the object matching the uid or, if none or more than one object was found, NULL
	 */
	// TODO This is duplicated code; see Argument class
	protected function findObjectByUid($dataType, $uid) {
		$query = $this->queryFactory->create($dataType);
		$query->getQuerySettings()->setRespectSysLanguage(FALSE);
		$query->getQuerySettings()->setRespectStoragePage(FALSE);
		$query->getQuerySettings()->setRespectEnableFields(FALSE);
		return $query->matching(
			$query->equals('uid', intval($uid)))
			->execute()
			->getFirst();
	}
}


TypoScript setup:

config.tx_extbase {
  objects.Tx_Extbase_Property_Mapper.className = Tx_XYZ_Property_Mapper
}


worked fine w/ 4.5LTS (but obviously has side effects)

Daniel


On Apr 2, 2012, at 2:56 PM, typo3 at litedesigns.nl wrote:

> Hi Frank,
> 
> Thanks for your suggestion, but this does not seem to work (i have set
> setRespectEnableFields(FALSE) in my createQuery() of my
> CompanyRepository). Was this not the correct way to use
> setRespectEnableFields?
> 
> A little more detailed info about my model:
> 
> Company
> - fieldA
> - fieldB
> - ...
> - activationHash
> - frontendUser => this is the 1:1 relation to fe_users table.
> 
> After i created the Company and FrontendUser i send the visitor an email
> with a link (with the activationHash) to activate the Company and
> FrontendUser.
> 
> In my Controller i have this function to activate the account:
> 
> public function activateAccountAction($activationHash)
> {
> 	// the findByActivationHash() uses setRespectEnableFields(FALSE) to find
> the hidden company
> 	$company =
> $this->companyRepository->findByActivationHash(trim($activationHash));
> 
> 	if ($company instanceof Tx_MyExt_Domain_Model_Company)
> 	{
> 		// unhide the company
> 		$company->setHidden(0); // so far so good, this works!
> 
> 		// get frontend user from company
> 		$frontendUser = $company->getFrontendUser(); // frontendUser is never
> returned
> 
> 		if ($frontendUser instanceof Tx_Extbase_Domain_Model_FrontendUser)
> 		{
> 			$frontendUser->setDisable(0);
> 		}
> 	}
> }
> 
> Since i don't have my own repository for the FrontendUsers, i try to fetch
> the FrontendUser by:
> $frontendUser = $company->getFrontendUser();
> This works fine though if the FrontendUser is not hidden!
> 
> But Extbase immediately tries to convert this to an Object instead of
> returning the FrontendUser.uid (as expected), but the FrontendUser object
> is never created since it has disable=1 set...
> 
> And because i can't get the FrontendUser.uid, i can't write my own
> function in my CompanyRepository to find the Company with an findByUid()
> and set setRespectEnableFields(FALSE) in this function.
> 
> That's why i proposed the solution to add a redundant field named
> 'fe_user_id' to my Company model, which is of type 'int' and not of type
> 'Tx_Extbase_Domain_Model_FrontendUser'.
> 
> With this redundant field i could write my own
> CompanyRepository->findFeUsersByUidEvenIfHidden($uid) function. But as in
> my original question, i'm not sure if this is the best / easiest approach.
> 
> It is a known problem: http://forge.typo3.org/issues/8483#note-4 (comment
> by Alexander Stehlik)
> 
> Any ideas are appreciated.
> 
> Kind regards,
> Tim
> 
> 
>> Hi,
>> 
>> you can try
>>  ' $query->getQuerySettings()->setRespectEnableFields(FALSE);'
>> In your repository, this should disable the enable-field query.
>> 
>> Best regards,
>> Frank
>> 
>> -----Ursprüngliche Nachricht-----
>> Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org
>> [mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von
>> typo3 at litedesigns.nl
>> Gesendet: Montag, 2. April 2012 13:18
>> An: typo3-project-typo3v4mvc at lists.typo3.org
>> Betreff: [TYPO3-mvc] update hidden / disabled records
>> 
>> Hi List,
>> 
>> I have a question about updating hidden records (based on http://forge:
>> http://forge.typo3.org/issues/8483) and i'm looking for an (temporary)
>> workaround.
>> 
>> I have a Company with a 1:1 relation to a FrontendUser. Visitors can
>> create
>> their own account, this is a single form with both Company and
>> FrontendUser
>> fields. But i want to send the visitor an activation email with a link to
>> activate their account.
>> 
>> Therefor i set the FrontendUser to 'disable=1' (fe_users table) upon
>> creating the Company and FrontendUser. This way they can't login yet
>> before
>> they have activated their account via the activation email.
>> 
>> But how can i retrieve my FrontendUser in my Controller when the
>> FrontendUser is still disabled?
>> 
>> $company->getFrontendUser() does not return anything because of the
>> 'enableFields' in the persistence layers of extbase.
>> 
>> Should i add an extra field in my Company model, something like
>> fe_user_id?
>> This then should be an integer, opposed to company.fe_user which is a
>> foreign key relation to the fe_users table. Because fe_user_id is an
>> integer, i can retrieve the id of the fe_user with
>> $company->getFeUserId() and then in my repository i can set
>> $querySettings->setRespectEnableFields(FALSE); to retrieve my FrontendUser
>> object. And if i change the disable to 0 (false), will it be saved or will
>> Extbase not update the FrontendUser because it is disabled?
>> 
>> Is this the easiest solution or does anyone have another approach?
>> 
>> Kind regards,
>> Tim
>> 
>> 
>> 
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>> 
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>> 
> 
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
> 

-- 
Daniel Schöne


tel.: (0351) 25 38 138
mobil: (0178) 14 81 505
email: daniel at schoene.it
web: http://schoene.it

USt-IdNr.: DE 264 29 88 81



More information about the TYPO3-project-typo3v4mvc mailing list