From 15e319a599664778428bbf0beeb85fd3e4e69254 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 19 Nov 2024 16:19:07 +0100 Subject: [PATCH] Migrate acp session log to grid view --- .../files/acp/templates/acpSessionLogList.tpl | 62 +------------ .../acp/page/ACPSessionLogListPage.class.php | 55 +++-------- .../session/log/ACPSessionLogList.class.php | 10 +- ...ACPSessionLogGridViewInitialized.class.php | 19 ++++ .../gridView/ACPSessionLogGridView.class.php | 92 +++++++++++++++++++ 5 files changed, 132 insertions(+), 106 deletions(-) create mode 100644 wcfsetup/install/files/lib/event/gridView/ACPSessionLogGridViewInitialized.class.php create mode 100644 wcfsetup/install/files/lib/system/gridView/ACPSessionLogGridView.class.php diff --git a/wcfsetup/install/files/acp/templates/acpSessionLogList.tpl b/wcfsetup/install/files/acp/templates/acpSessionLogList.tpl index e044749651..55e003f5dd 100644 --- a/wcfsetup/install/files/acp/templates/acpSessionLogList.tpl +++ b/wcfsetup/install/files/acp/templates/acpSessionLogList.tpl @@ -2,7 +2,7 @@
-

{lang}wcf.acp.sessionLog.list{/lang} {#$items}

+

{lang}wcf.acp.sessionLog.list{/lang} {#$gridView->countRows()}

{hascontent} @@ -14,62 +14,8 @@ {/hascontent}
-{hascontent} -
- {content}{pages print=true assign=pagesLinks controller="ACPSessionLogList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"}{/content} -
-{/hascontent} - -{if $objects|count} -
- - - - - - - - - - - - {event name='columnHeads'} - - - - - {foreach from=$objects item=sessionLog} - - - - - - - - - - {event name='columns'} - - {/foreach} - -
{lang}wcf.global.objectID{/lang}{lang}wcf.user.username{/lang}{lang}wcf.user.ipAddress{/lang}{lang}wcf.user.userAgent{/lang}{lang}wcf.acp.sessionLog.time{/lang}{lang}wcf.acp.sessionLog.lastActivityTime{/lang}{lang}wcf.acp.sessionLog.actions{/lang}
{@$sessionLog->sessionLogID}{$sessionLog->username}{$sessionLog->getIpAddress()}{if $sessionLog->hostname != $sessionLog->ipAddress}
{$sessionLog->hostname}{/if}
{$sessionLog->userAgent|truncate:75|tableWordwrap}{@$sessionLog->time|time}{@$sessionLog->lastActivityTime|time}{#$sessionLog->accesses}
-
- - -{/if} +
+ {unsafe:$gridView->render()} +
{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php b/wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php index f7f8b160a0..0053e4ea7f 100755 --- a/wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php @@ -2,19 +2,20 @@ namespace wcf\acp\page; -use wcf\data\acp\session\log\ACPSessionLogList; -use wcf\page\SortablePage; +use wcf\page\AbstractGridViewPage; +use wcf\system\gridView\AbstractGridView; +use wcf\system\gridView\ACPSessionLogGridView; /** - * Shows a list of log sessions. + * Shows a list of logged sessions. * - * @author Marcel Werk - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License + * @author Marcel Werk + * @copyright 2001-2024 WoltLab GmbH + * @license GNU Lesser General Public License * - * @property ACPSessionLogList $objectList + * @property ACPSessionLogGridView $gridView */ -class ACPSessionLogListPage extends SortablePage +class ACPSessionLogListPage extends AbstractGridViewPage { /** * @inheritDoc @@ -31,41 +32,9 @@ class ACPSessionLogListPage extends SortablePage */ public $neededPermissions = ['admin.management.canViewLog']; - /** - * @inheritDoc - */ - public $defaultSortField = 'lastActivityTime'; - - /** - * @inheritDoc - */ - public $defaultSortOrder = 'DESC'; - - /** - * @inheritDoc - */ - public $validSortFields = [ - 'sessionLogID', - 'username', - 'ipAddress', - 'userAgent', - 'time', - 'lastActivityTime', - 'accesses', - ]; - - /** - * @inheritDoc - */ - public $objectListClassName = ACPSessionLogList::class; - - /** - * @inheritDoc - */ - public function readObjects() + #[\Override] + protected function createGridViewController(): AbstractGridView { - $this->sqlOrderBy = (($this->sortField != 'accesses' && $this->sortField != 'username') ? 'acp_session_log.' : '') . $this->sortField . " " . $this->sortOrder; - - parent::readObjects(); + return new ACPSessionLogGridView(); } } diff --git a/wcfsetup/install/files/lib/data/acp/session/log/ACPSessionLogList.class.php b/wcfsetup/install/files/lib/data/acp/session/log/ACPSessionLogList.class.php index f440b012f4..32658ec85b 100644 --- a/wcfsetup/install/files/lib/data/acp/session/log/ACPSessionLogList.class.php +++ b/wcfsetup/install/files/lib/data/acp/session/log/ACPSessionLogList.class.php @@ -33,7 +33,11 @@ class ACPSessionLogList extends DatabaseObjectList $this->sqlSelects .= ','; } $this->sqlSelects .= " - user_table.username, + ( + SELECT username + FROM wcf1_user + WHERE userID = " . $this->getDatabaseTableAlias() . ".userID + ) AS username, 0 AS active, ( SELECT COUNT(*) @@ -41,10 +45,6 @@ class ACPSessionLogList extends DatabaseObjectList WHERE sessionLogID = " . $this->getDatabaseTableAlias() . ".sessionLogID ) AS accesses"; - $this->sqlJoins .= " - LEFT JOIN wcf1_user user_table - ON user_table.userID = " . $this->getDatabaseTableAlias() . ".userID"; - parent::readObjects(); } } diff --git a/wcfsetup/install/files/lib/event/gridView/ACPSessionLogGridViewInitialized.class.php b/wcfsetup/install/files/lib/event/gridView/ACPSessionLogGridViewInitialized.class.php new file mode 100644 index 0000000000..43f1430006 --- /dev/null +++ b/wcfsetup/install/files/lib/event/gridView/ACPSessionLogGridViewInitialized.class.php @@ -0,0 +1,19 @@ + + * @since 6.2 + */ +final class ACPSessionLogGridViewInitialized implements IPsr14Event +{ + public function __construct(public readonly ACPSessionLogGridView $gridView) {} +} diff --git a/wcfsetup/install/files/lib/system/gridView/ACPSessionLogGridView.class.php b/wcfsetup/install/files/lib/system/gridView/ACPSessionLogGridView.class.php new file mode 100644 index 0000000000..4faaf6de8e --- /dev/null +++ b/wcfsetup/install/files/lib/system/gridView/ACPSessionLogGridView.class.php @@ -0,0 +1,92 @@ + + * @since 6.2 + */ +final class ACPSessionLogGridView extends DatabaseObjectListGridView +{ + public function __construct() + { + $this->addColumns([ + GridViewColumn::for('sessionLogID') + ->label('wcf.global.objectID') + ->renderer(new NumberColumnRenderer()) + ->sortable(), + GridViewColumn::for('userID') + ->label('wcf.user.username') + ->sortable() + ->sortById('username') + ->renderer(new UserColumnRenderer()) + ->filter(new UserFilter()), + GridViewColumn::for('ipAddress') + ->label('wcf.user.ipAddress') + ->sortable() + ->renderer(new IpAddressColumnRenderer()) + ->filter(new IpAddressFilter()), + GridViewColumn::for('userAgent') + ->label('wcf.user.userAgent') + ->sortable() + ->renderer(new TruncatedTextColumnRenderer()) + ->filter(new TextFilter()), + GridViewColumn::for('time') + ->label('wcf.acp.sessionLog.time') + ->sortable() + ->renderer(new TimeColumnRenderer()) + ->filter(new TimeFilter()), + GridViewColumn::for('lastActivityTime') + ->label('wcf.acp.sessionLog.lastActivityTime') + ->sortable() + ->renderer(new TimeColumnRenderer()) + ->filter(new TimeFilter()), + GridViewColumn::for('accesses') + ->label('wcf.acp.sessionLog.actions') + ->sortable() + ->renderer(new NumberColumnRenderer()), + ]); + + $this->addRowLink(new GridViewRowLink(ACPSessionLogPage::class)); + $this->setSortField('lastActivityTime'); + $this->setSortOrder('DESC'); + } + + #[\Override] + public function isAccessible(): bool + { + return WCF::getSession()->getPermission('admin.management.canViewLog'); + } + + #[\Override] + protected function createObjectList(): DatabaseObjectList + { + return new ACPSessionLogList(); + } + + #[\Override] + protected function getInitializedEvent(): ?IPsr14Event + { + return new ACPSessionLogGridViewInitialized($this); + } +} -- 2.20.1