diff --git a/lib/Command/CirclesMaintenance.php b/lib/Command/CirclesMaintenance.php index dcca64dab..3ad21a197 100644 --- a/lib/Command/CirclesMaintenance.php +++ b/lib/Command/CirclesMaintenance.php @@ -91,7 +91,8 @@ protected function configure() { ->addOption( 'uninstall', '', InputOption::VALUE_NONE, 'Uninstall the apps and everything related to the app from the database' - ); + ) + ->addOption('force-refresh', '', InputOption::VALUE_NONE, 'enforce some refresh'); } @@ -154,9 +155,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->outputService->setOccOutput($output); $this->maintenanceService->setOccOutput($output); + for ($i = 1; $i <= $level; $i++) { try { - $this->maintenanceService->runMaintenance($i); + $this->maintenanceService->runMaintenance($i, $input->getOption('force-refresh')); } catch (MaintenanceException $e) { } } diff --git a/lib/Service/MaintenanceService.php b/lib/Service/MaintenanceService.php index 8b48df1af..70edcb7d0 100644 --- a/lib/Service/MaintenanceService.php +++ b/lib/Service/MaintenanceService.php @@ -173,7 +173,7 @@ public function setOccOutput(OutputInterface $output): void { * * @throws MaintenanceException */ - public function runMaintenance(int $level): void { + public function runMaintenance(int $level, bool $forceRefresh = false): void { $this->federatedUserService->bypassCurrentUserCondition(true); $this->lockMaintenanceRun(); @@ -181,19 +181,19 @@ public function runMaintenance(int $level): void { switch ($level) { case 1: - $this->runMaintenance1(); + $this->runMaintenance1($forceRefresh); break; case 2: - $this->runMaintenance2(); + $this->runMaintenance2($forceRefresh); break; case 3: - $this->runMaintenance3(); + $this->runMaintenance3($forceRefresh); break; case 4: - $this->runMaintenance4(); + $this->runMaintenance4($forceRefresh); break; case 5: - $this->runMaintenance5(); + $this->runMaintenance5($forceRefresh); break; } @@ -217,7 +217,7 @@ private function lockMaintenanceRun(): void { /** * every minute */ - private function runMaintenance1(): void { + private function runMaintenance1(bool $forceRefresh = false): void { try { $this->output('Remove circles with no owner'); $this->removeCirclesWithNoOwner(); @@ -229,7 +229,7 @@ private function runMaintenance1(): void { /** * every 10 minutes */ - private function runMaintenance2(): void { + private function runMaintenance2(bool $forceRefresh = false): void { try { $this->output('Remove members with no circles'); $this->removeMembersWithNoCircles(); @@ -247,7 +247,7 @@ private function runMaintenance2(): void { /** * every hour */ - private function runMaintenance3(): void { + private function runMaintenance3(bool $forceRefresh = false): void { try { $this->output('Retry failed FederatedEvents (hourly)'); $this->eventWrapperService->retry(EventWrapperService::RETRY_HOURLY); @@ -259,7 +259,7 @@ private function runMaintenance3(): void { /** * every day */ - private function runMaintenance4(): void { + private function runMaintenance4(bool $forceRefresh = false): void { try { $this->output('Retry failed FederatedEvents (daily)'); $this->eventWrapperService->retry(EventWrapperService::RETRY_DAILY); @@ -285,18 +285,18 @@ private function runMaintenance4(): void { /** * every week */ - private function runMaintenance5(): void { + private function runMaintenance5(bool $forceRefresh = false): void { try { $this->output('Update memberships'); $this->updateAllMemberships(); } catch (Exception $e) { } -// try { -// $this->output('refresh displayNames older than 7d'); -// $this->refreshDisplayName(); -// } catch (Exception $e) { -// } + try { + $this->output('refresh members\' display name'); + $this->refreshDisplayName($forceRefresh); + } catch (Exception $e) { + } try { // Can be removed in NC27. @@ -403,7 +403,7 @@ private function updateAllMemberships(): void { * @throws RequestBuilderException * @throws InitiatorNotFoundException */ - private function refreshDisplayName(): void { + private function refreshDisplayName(bool $forceRefresh = false): void { $circleFilter = new Circle(); $circleFilter->setConfig(Circle::CFG_SINGLE); @@ -416,8 +416,8 @@ private function refreshDisplayName(): void { foreach ($circles as $circle) { $owner = $circle->getOwner(); - if ($owner->getDisplayUpdate() > (time() - 604800)) { - continue; + if (!$forceRefresh && $owner->getDisplayUpdate() > (time() - 691200)) { + continue; // ignore update done in the last 8 days. } if ($owner->getUserType() === Member::TYPE_USER) {