setName('sharing:expiration-notification') ->setDescription('Notify share initiators when a share will expire the next day.'); } public function execute(InputInterface $input, OutputInterface $output): int { //Current time $minTime = $this->time->getDateTime(); $minTime->add(new \DateInterval('P1D')); $minTime->setTime(0, 0, 0); $maxTime = clone $minTime; $maxTime->setTime(23, 59, 59); $shares = $this->shareManager->getAllShares(); $now = $this->time->getDateTime(); /** @var IShare $share */ foreach ($shares as $share) { if ($share->getExpirationDate() === null || $share->getExpirationDate()->getTimestamp() < $minTime->getTimestamp() || $share->getExpirationDate()->getTimestamp() > $maxTime->getTimestamp()) { continue; } $notification = $this->notificationManager->createNotification(); $notification->setApp('files_sharing') ->setDateTime($now) ->setObject('share', $share->getFullId()) ->setSubject('expiresTomorrow'); // Only send to initiator for now $notification->setUser($share->getSharedBy()); $this->notificationManager->notify($notification); } return 0; } }