[BUGFIX] PHP 5.4 warning in CLI context in switch back user
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / Hook / SwitchBackUserHook.php
1 <?php
2 namespace TYPO3\CMS\Beuser\Hook;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Felix Kopp <felix-source@phorax.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Backend user switchback, for logoff_pre_processing hook within
29 * \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication class
30 *
31 * @author Kasper Skårhøj (kasperYYYY@typo3.com)
32 * @author Sebastian Kurfürst <sebastian@garbage-group.de>
33 * @author Felix Kopp <felix-source@phorax.com>
34 */
35 class SwitchBackUserHook {
36
37 /**
38 * Switch backend user session
39 *
40 * @param array $params
41 * @param \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication $that
42 * @see \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
43 */
44 public function switchBack($params, $that) {
45 // Is a backend session handled?
46 if (
47 $that->session_table !== 'be_sessions'
48 || !is_array($that->user)
49 || !$that->user['uid']
50 || !$that->user['ses_backuserid']
51 ) {
52 return;
53 }
54
55 // @TODO: Move update functionality to Tx_Beuser_Domain_Repository_BackendUserSessionRepository
56 $updateData = array(
57 'ses_userid' => $that->user['ses_backuserid'],
58 'ses_backuserid' => 0
59 );
60 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
61 'be_sessions',
62 'ses_id = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions') .
63 ' AND ses_name = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName(), 'be_sessions') .
64 ' AND ses_userid=' . intval($GLOBALS['BE_USER']->user['uid']), $updateData);
65
66 $redirectUrl = $GLOBALS['BACK_PATH'] . 'index.php' . ($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces'] ? '' : '?commandLI=1');
67 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($redirectUrl);
68 }
69
70 }
71
72
73 ?>