. * */ namespace OCA\Passman\Service; use OCA\Passman\Activity; use OCA\Passman\Db\Credential; use OCA\Passman\Utility\Utils; use OCP\DB\Exception; use Psr\Log\LoggerInterface; class CronService { public function __construct( private CredentialService $credentialService, private LoggerInterface $logger, private Utils $utils, private NotificationService $notificationService, private ActivityService $activityService, ) { } public function expireCredentials() { /** @var Credential[] $expired_credentials */ $expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime()); foreach ($expired_credentials as $credential) { try { $this->logger->debug($credential->getLabel() . ' is expired, checking notifications!', ['app' => 'passman']); if (!$this->notificationService->hasCredentialExpirationNotification($credential)) { $link = $this->credentialService->getDirectEditLink($credential); $this->logger->debug($credential->getLabel() . ' is expired, adding notification!', ['app' => 'passman']); $this->activityService->add( Activity::SUBJECT_ITEM_EXPIRED, [$credential->getLabel(), $credential->getUserId()], '', [], $link, $credential->getUserId(), Activity::TYPE_ITEM_EXPIRED); $this->notificationService->credentialExpiredNotification($credential, $link); } } catch (Exception $exception) { $this->logger->error('Error while creating a notification: ' . $exception->getMessage(), ['app' => 'passman']); } } } }