[TYPO3-mvc] update hidden / disabled records

Ulrich Fischer ulrich-fischer at gmx.net
Sun Dec 11 10:58:45 CET 2016


Hi all,

this thread is quite old. But here is a nice snippet.

Problem description:
If a fe_user is disabled, the incoming user argument will not be mapped as an 
user object, because the findByUid repository method excludes disabled records.

Solution:
The user argument in the request returns the uid of the user.
With this user.uid a custom findDisabledByUid method in the repository method 
will return the user object, which can be updated.

--- fluid template activate link ---
<f:link.action action="activate" arguments="{user: user}">Activate</f:link.action>

--- Controller function ---
public function activateAction() {
   // get user id from request
   if ($this->request->hasArgument('user')) {
     $userUid = $this->request->getArgument('supplier');
   }
   // get disabled user object
   $user= $this->userRepository->findDisabledByUid($userUid);
   $user->setDisable(false);
   $this->userRepository->update($supplier);
}

--- Repository ---
public function findDisabledByUid($uid) {
   $query = $this->createQuery();
   $query->getQuerySettings()
     ->setIgnoreEnableFields(true)
     ->setEnableFieldsToBeIgnored(array('disable'));
   $query->matching(
   $query->logicalAnd(
     $query->equals('uid', $uid),
     $query->equals('deleted', 0)
   ));
   return $query->execute()->getFirst();
}

Regards

Ulrich

www.sunfish.de


More information about the TYPO3-project-typo3v4mvc mailing list