diff --git a/lib/Db/EventWrapperRequest.php b/lib/Db/EventWrapperRequest.php index 8fe9e38fc..48d6a5cc3 100644 --- a/lib/Db/EventWrapperRequest.php +++ b/lib/Db/EventWrapperRequest.php @@ -109,4 +109,22 @@ public function getByToken(string $token): array { return $this->getItemsFromRequest($qb); } + + /** + * delete completed entries older than a month + * + * @param bool $allOldEntries delete also not-completed entries + */ + public function deleteOldEntries(bool $allOldEntries = false): void { + $qb = $this->getEventWrapperDeleteSql(); + $qb->where( + $qb->exprLimitInt('status', EventWrapper::STATUS_OVER), + $qb->exprLt('creation', time() - 30 * 86400) + ); + if (!$allOldEntries) { + $qb->andWhere($qb->exprLimitInt('status', EventWrapper::STATUS_OVER)); + } + + $qb->executeStatement(); + } } diff --git a/lib/Service/MaintenanceService.php b/lib/Service/MaintenanceService.php index 30f4654fe..892633e66 100644 --- a/lib/Service/MaintenanceService.php +++ b/lib/Service/MaintenanceService.php @@ -15,6 +15,7 @@ use OC\User\NoUserException; use OCA\Circles\Db\AccountsRequest; use OCA\Circles\Db\CircleRequest; +use OCA\Circles\Db\EventWrapperRequest; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Db\ShareWrapperRequest; use OCA\Circles\Exceptions\InitiatorNotFoundException; @@ -29,6 +30,7 @@ use OCA\Circles\Tools\Traits\TNCLogger; use OCP\IGroupManager; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Output\OutputInterface; /** @@ -40,7 +42,6 @@ class MaintenanceService { use TNCLogger; public const TIMEOUT = 18000; - public static $DELAY = [ 1 => 60, // every minute @@ -50,94 +51,25 @@ class MaintenanceService { 5 => 432000 // evey week ]; + private OutputInterface $output; - /** @var IUserManager */ - private $userManager; - - /** @var IGroupManager */ - private $groupManager; - - /** @var AccountsRequest */ - private $accountRequest; - - /** @var CircleRequest */ - private $circleRequest; - - /** @var MemberRequest */ - private $memberRequest; - - /** @var ShareWrapperRequest */ - private $shareWrapperRequest; - - /** @var SyncService */ - private $syncService; - - /** @var FederatedUserService */ - private $federatedUserService; - - private ShareWrapperService $shareWrapperService; - - /** @var MembershipService */ - private $membershipService; - - /** @var EventWrapperService */ - private $eventWrapperService; - - /** @var CircleService */ - private $circleService; - - /** @var ConfigService */ - private $configService; - - - /** @var OutputInterface */ - private $output; - - - /** - * MaintenanceService constructor. - * - * @param IUserManager $userManager - * @param IGroupManager $groupManager - * @param CircleRequest $circleRequest - * @param MemberRequest $memberRequest - * @param ShareWrapperRequest $shareWrapperRequest - * @param SyncService $syncService - * @param FederatedUserService $federatedUserService - * @param ShareWrapperService $shareWrapperService - * @param MembershipService $membershipService - * @param EventWrapperService $eventWrapperService - * @param CircleService $circleService - * @param ConfigService $configService - */ public function __construct( - IUserManager $userManager, - IGroupManager $groupManager, - CircleRequest $circleRequest, - AccountsRequest $accountRequest, - MemberRequest $memberRequest, - ShareWrapperRequest $shareWrapperRequest, - SyncService $syncService, - FederatedUserService $federatedUserService, - ShareWrapperService $shareWrapperService, - MembershipService $membershipService, - EventWrapperService $eventWrapperService, - CircleService $circleService, - ConfigService $configService, + private IUserManager $userManager, + private IGroupManager $groupManager, + private CircleRequest $circleRequest, + private AccountsRequest $accountRequest, + private MemberRequest $memberRequest, + private ShareWrapperRequest $shareWrapperRequest, + private EventWrapperRequest $eventWrapperRequest, + private SyncService $syncService, + private FederatedUserService $federatedUserService, + private ShareWrapperService $shareWrapperService, + private MembershipService $membershipService, + private EventWrapperService $eventWrapperService, + private CircleService $circleService, + private ConfigService $configService, + private LoggerInterface $logger, ) { - $this->userManager = $userManager; - $this->groupManager = $groupManager; - $this->circleRequest = $circleRequest; - $this->accountRequest = $accountRequest; - $this->memberRequest = $memberRequest; - $this->shareWrapperRequest = $shareWrapperRequest; - $this->syncService = $syncService; - $this->federatedUserService = $federatedUserService; - $this->shareWrapperService = $shareWrapperService; - $this->eventWrapperService = $eventWrapperService; - $this->membershipService = $membershipService; - $this->circleService = $circleService; - $this->configService = $configService; } @@ -267,6 +199,13 @@ private function runMaintenance4(bool $forceRefresh = false): void { $this->syncService->sync(); } catch (Exception $e) { } + + try { + $this->output('Delete old and terminated FederatedEvents'); + $this->eventWrapperRequest->deleteOldEntries(false); + } catch (Exception $e) { + $this->logger->warning('issue while deleting old events', ['exception' => $e]); + } } /**