TYPO3 CMS  TYPO3_8-7
BackendUserSessionRepository.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
28 {
34  public function findAllActive()
35  {
36  $sessionBackend = $this->getSessionBackend();
37  $allSessions = $sessionBackend->getAll();
38 
39  // Map array to correct keys
40  $allSessions = array_map(
41  function ($session) {
42  return [
43  'id' => $session['ses_id'],
44  'ip' => $session['ses_iplock'],
45  'timestamp' => $session['ses_tstamp'],
46  'ses_userid' => $session['ses_userid']
47  ];
48  },
49  $allSessions
50  );
51 
52  // Sort by timestamp
53  usort($allSessions, function ($session1, $session2) {
54  return $session1['timestamp'] <=> $session2['timestamp'];
55  });
56 
57  return $allSessions;
58  }
59 
66  public function findByBackendUser(BackendUser $backendUser)
67  {
68  $allActive = $this->findAllActive();
69 
70  return array_filter(
71  $allActive,
72  function ($session) use ($backendUser) {
73  return (int)$session['ses_userid'] === $backendUser->getUid();
74  }
75  );
76  }
77 
83  public function switchBackToOriginalUser(AbstractUserAuthentication $authentication)
84  {
85  $sessionBackend = $this->getSessionBackend();
86  $sessionId = $this->getBackendSessionId();
87  $sessionBackend->update(
88  $sessionId,
89  [
90  'ses_userid' => $authentication->user['ses_backuserid'],
91  'ses_backuserid' => 0
92  ]
93  );
94  }
95 
99  protected function getBackendSessionId(): string
100  {
101  return $GLOBALS['BE_USER']->id;
102  }
103 
108  {
109  return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
110  }
111 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']