Skip to content
Snippets Groups Projects
Commit 7eaf1907 authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Christian Kuhn
Browse files

[BUGFIX] Delete unavailable "recently switched to" users from UC

If a user who appears in the "Recently switched to" list became
unavailable for some reason, only the placeholder avatar was rendered,
giving a slight hint of life in the past.

Such users are now deleted from UC and do not appear in the list anymore.
Furthermore, the section label was slightly modified to be more
understandable.

For performance reasons, only one query is triggered now and sorting is
done based on the array of UIDs stored in UC.

Resolves: #82796
Related: #80581
Releases: master
Change-Id: Ieff8a779639f277de1c0cb7feaa0fe2b82bd97c5
Reviewed-on: https://review.typo3.org/54433


Reviewed-by: default avatarMathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: default avatarMathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarJoerg Boesche <typo3@joergboesche.de>
Tested-by: default avatarJoerg Boesche <typo3@joergboesche.de>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 0aa3123d
Branches
Tags
No related merge requests found
......@@ -17,6 +17,8 @@ namespace TYPO3\CMS\Backend\Backend\ToolbarItems;
use TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
......@@ -71,15 +73,37 @@ class UserToolbarItem implements ToolbarItemInterface
&& isset($backendUser->uc['recentSwitchedToUsers'])
&& is_array($backendUser->uc['recentSwitchedToUsers'])
) {
foreach ($backendUser->uc['recentSwitchedToUsers'] as $userUid) {
$backendUserRecord = BackendUtility::getRecord('be_users', $userUid);
$backendUserRecord['switchUserLink'] = BackendUtility::getModuleUrl(
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
$result = $queryBuilder
->select('uid', 'username', 'realName')
->from('be_users')
->where(
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($backendUser->uc['recentSwitchedToUsers'], Connection::PARAM_INT_ARRAY))
)->execute();
// Flip the array to have a "sorted" list of items
$mostRecentUsers = array_flip($backendUser->uc['recentSwitchedToUsers']);
while ($row = $result->fetch()) {
$row['switchUserLink'] = BackendUtility::getModuleUrl(
'system_BeuserTxBeuser',
[
'SwitchUser' => $backendUserRecord['uid']
]
[
'SwitchUser' => $row['uid']
]
);
$mostRecentUsers[] = $backendUserRecord;
$mostRecentUsers[$row['uid']] = $row;
}
// Remove any item that is not an array (means, the stored uid is not available anymore)
$mostRecentUsers = array_filter($mostRecentUsers, function ($record) {
return is_array($record);
});
$availableUsers = array_keys($mostRecentUsers);
if (!empty(array_diff($backendUser->uc['recentSwitchedToUsers'], $availableUsers))) {
$backendUser->uc['recentSwitchedToUsers'] = $availableUsers;
$backendUser->writeUC();
}
}
......
......@@ -20,7 +20,7 @@
Have a nice day.</source>
</trans-unit>
<trans-unit id="usermodule.su.list">
<source>Recently 'switched to' users</source>
<source>Recently switched to</source>
</trans-unit>
<trans-unit id="usermodule.su.tooltip">
<source>Switch to user %s</source>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment