12474349cSGreg Roach<?php 22474349cSGreg Roach 32474349cSGreg Roach/** 42474349cSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 62474349cSGreg Roach * This program is free software: you can redistribute it and/or modify 72474349cSGreg Roach * it under the terms of the GNU General Public License as published by 82474349cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 92474349cSGreg Roach * (at your option) any later version. 102474349cSGreg Roach * This program is distributed in the hope that it will be useful, 112474349cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 122474349cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 132474349cSGreg Roach * GNU General Public License for more details. 142474349cSGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 162474349cSGreg Roach */ 172474349cSGreg Roach 182474349cSGreg Roachdeclare(strict_types=1); 192474349cSGreg Roach 202474349cSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 212474349cSGreg Roach 222474349cSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 232474349cSGreg Roachuse Fisharebest\Webtrees\I18N; 24d97083feSGreg Roachuse Fisharebest\Webtrees\Registry; 252474349cSGreg Roachuse Fisharebest\Webtrees\Services\UserService; 262474349cSGreg Roachuse Psr\Http\Message\ResponseInterface; 272474349cSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 282474349cSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 292474349cSGreg Roach 302474349cSGreg Roach/** 312474349cSGreg Roach * Delete old/inactive users. 322474349cSGreg Roach */ 332474349cSGreg Roachclass UsersCleanupPage implements RequestHandlerInterface 342474349cSGreg Roach{ 352474349cSGreg Roach use ViewResponseTrait; 362474349cSGreg Roach 37c4943cffSGreg Roach private UserService $user_service; 382474349cSGreg Roach 392474349cSGreg Roach /** 402474349cSGreg Roach * @param UserService $user_service 412474349cSGreg Roach */ 425f9bebcaSGreg Roach public function __construct(UserService $user_service) 435f9bebcaSGreg Roach { 442474349cSGreg Roach $this->user_service = $user_service; 452474349cSGreg Roach } 462474349cSGreg Roach 472474349cSGreg Roach /** 482474349cSGreg Roach * @param ServerRequestInterface $request 492474349cSGreg Roach * 502474349cSGreg Roach * @return ResponseInterface 512474349cSGreg Roach */ 522474349cSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 532474349cSGreg Roach { 54d97083feSGreg Roach $inactive_threshold = Registry::timestampFactory()->now()->subtractMonths(6)->timestamp(); 55d97083feSGreg Roach $unverified_threshold = Registry::timestampFactory()->now()->subtractDays(7)->timestamp(); 562474349cSGreg Roach 572474349cSGreg Roach $inactive_users = $this->user_service->all() 582474349cSGreg Roach ->filter($this->user_service->filterInactive($inactive_threshold)) 592474349cSGreg Roach ->sort($this->user_service->sortByLastLogin()); 602474349cSGreg Roach 612474349cSGreg Roach $unverified_users = $this->user_service->unverified() 622474349cSGreg Roach ->filter($this->user_service->filterInactive($unverified_threshold)) 632474349cSGreg Roach ->sort($this->user_service->sortByLastLogin()); 642474349cSGreg Roach 652474349cSGreg Roach $title = I18N::translate('Delete inactive users'); 662474349cSGreg Roach 672474349cSGreg Roach $this->layout = 'layouts/administration'; 682474349cSGreg Roach 692474349cSGreg Roach return $this->viewResponse('admin/users-cleanup', [ 702474349cSGreg Roach 'title' => $title, 712474349cSGreg Roach 'inactive_users' => $inactive_users, 722474349cSGreg Roach 'unverified_users' => $unverified_users, 732474349cSGreg Roach ]); 742474349cSGreg Roach } 752474349cSGreg Roach} 76