setInterval($this->appConfig->getEditorsCheckInterval()); $this->setTimeSensitivity(IJob::TIME_SENSITIVE); } /** * Makes the background check * * @param array $argument unused argument */ protected function run($argument): void { if (empty($this->appConfig->getDocumentServerUrl())) { $this->logger->debug("Settings are empty"); return; } if (!$this->appConfig->settingsAreSuccessful()) { $this->logger->debug("Settings are not correct"); return; } $fileUrl = $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.emptyfile"); if (!$this->appConfig->useDemo() && !empty($this->appConfig->getStorageUrl())) { $fileUrl = str_replace($this->urlGenerator->getAbsoluteURL("/"), $this->appConfig->getStorageUrl(), $fileUrl); } $host = parse_url((string) $fileUrl)["host"]; if ($host === "localhost" || $host === "127.0.0.1") { $this->logger->debug("Localhost is not alowed for cron editors availability check. Please provide server address for internal requests from ONLYOFFICE Docs"); return; } $this->logger->debug("ONLYOFFICE check started by cron"); [$error, $version] = $this->documentService->checkDocServiceUrl(); if (!empty($error)) { $this->logger->info("ONLYOFFICE server is not available"); $this->appConfig->setSettingsError($error); $this->notifyAdmins(); } else { $this->logger->debug("ONLYOFFICE server availability check is finished successfully"); } } /** * Get the list of users to notify * * @return string[] */ private function getUsersToNotify(): array { $notifyGroups = ["admin"]; $notifyUsers = []; foreach ($notifyGroups as $notifyGroup) { $group = $this->groupManager->get($notifyGroup); if ($group === null || !($group instanceof IGroup)) { continue; } $users = $group->getUsers(); foreach ($users as $user) { $notifyUsers[] = $user->getUID(); } } return $notifyUsers; } /** * Send notification to admins */ private function notifyAdmins(): void { $notificationManager = \OCP\Server::get(\OCP\Notification\IManager::class); $notification = $notificationManager->createNotification(); $notification->setApp($this->appName) ->setDateTime(new \DateTime()) ->setObject("editorsCheck", $this->trans->t("ONLYOFFICE server is not available")) ->setSubject("editorscheck_info"); foreach ($this->getUsersToNotify() as $uid) { $notification->setUser($uid); $notificationManager->notify($notification); if ($this->appConfig->getEmailNotifications()) { $this->emailManager->notifyEditorsCheckEmail($uid); } } } }