2016-09-23 21:05:27 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Nextcloud - passman
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Sander Brand <brantje@gmail.com>
|
|
|
|
* @copyright Sander Brand 2016
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Passman\Service;
|
|
|
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCA\Passman\Utility\Utils;
|
2016-09-23 22:52:41 +08:00
|
|
|
use OCA\Passman\Activity;
|
2016-09-24 02:50:14 +08:00
|
|
|
use OCP\IDBConnection;
|
2016-09-23 21:05:27 +08:00
|
|
|
class CronService {
|
|
|
|
|
|
|
|
private $credentialService;
|
|
|
|
private $logger;
|
|
|
|
private $utils;
|
|
|
|
private $notificationService;
|
2016-09-23 22:52:41 +08:00
|
|
|
private $activityService;
|
2016-09-24 02:50:14 +08:00
|
|
|
private $db;
|
|
|
|
public function __construct(CredentialService $credentialService, ILogger $logger, Utils $utils, NotificationService $notificationService, ActivityService $activityService, $db) {
|
2016-09-23 21:05:27 +08:00
|
|
|
$this->credentialService = $credentialService;
|
|
|
|
$this->logger = $logger;
|
|
|
|
$this->utils = $utils;
|
|
|
|
$this->notificationService = $notificationService;
|
2016-09-23 22:52:41 +08:00
|
|
|
$this->activityService = $activityService;
|
2016-09-24 02:50:14 +08:00
|
|
|
$this->db = $db;
|
2016-09-23 21:05:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function expireCredentials() {
|
|
|
|
$this->logger->info('Passman cron test', array('app' => 'passman'));
|
|
|
|
$expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime());
|
|
|
|
foreach($expired_credentials as $credential){
|
2016-09-23 22:52:41 +08:00
|
|
|
$link = ''; // @TODO create direct link to credential
|
2016-09-24 02:50:14 +08:00
|
|
|
|
2016-09-24 03:09:06 +08:00
|
|
|
$sql = 'SELECT count(*) as rows from `*PREFIX*notifications` WHERE `subject`= \'credential_expired\' AND object_id=?';
|
2016-09-24 02:50:14 +08:00
|
|
|
$query = $this->db->prepareQuery($sql);
|
|
|
|
$query->bindParam(1, $credential->getId(), \PDO::PARAM_INT);
|
|
|
|
$result = $query->execute();
|
|
|
|
if($result->fetchRow()['rows'] === 0) {
|
|
|
|
$this->activityService->add(
|
|
|
|
Activity::SUBJECT_ITEM_EXPIRED, array($credential->getLabel(), $credential->getUserId()),
|
|
|
|
'', array(),
|
2016-09-24 18:59:19 +08:00
|
|
|
$link, $credential->getUserId(), Activity::TYPE_ITEM_EXPIRED);
|
2016-09-24 02:50:14 +08:00
|
|
|
$this->notificationService->credentialExpiredNotification($credential);
|
|
|
|
}
|
2016-09-23 22:52:41 +08:00
|
|
|
|
2016-09-23 21:05:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|