|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Nextcloud - passman |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
|
6
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\Passman\Service; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\IConfig; |
|
27
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
|
28
|
|
|
use OCP\ILogger; |
|
29
|
|
|
use OCA\Passman\Utility\Utils; |
|
30
|
|
|
use OCA\Passman\Activity; |
|
31
|
|
|
use OCP\IDBConnection; |
|
32
|
|
|
class CronService { |
|
33
|
|
|
|
|
34
|
|
|
private $credentialService; |
|
35
|
|
|
private $logger; |
|
36
|
|
|
private $utils; |
|
37
|
|
|
private $notificationService; |
|
38
|
|
|
private $activityService; |
|
39
|
|
|
private $db; |
|
40
|
|
|
public function __construct(CredentialService $credentialService, ILogger $logger, Utils $utils, NotificationService $notificationService, ActivityService $activityService, IDBConnection $db) { |
|
41
|
|
|
$this->credentialService = $credentialService; |
|
42
|
|
|
$this->logger = $logger; |
|
43
|
|
|
$this->utils = $utils; |
|
44
|
|
|
$this->notificationService = $notificationService; |
|
45
|
|
|
$this->activityService = $activityService; |
|
46
|
|
|
$this->db = $db; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function expireCredentials() { |
|
51
|
|
|
$this->logger->info('Passman cron test', array('app' => 'passman')); |
|
52
|
|
|
$expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime()); |
|
53
|
|
|
foreach($expired_credentials as $credential){ |
|
54
|
|
|
$link = ''; // @TODO create direct link to credential |
|
55
|
|
|
|
|
56
|
|
|
$sql = 'SELECT count(*) as rows from `*PREFIX*notifications` WHERE `subject`= \'credential_expired\' AND object_id=?'; |
|
57
|
|
|
$id = $credential->getId(); |
|
58
|
|
|
$result = $this->db->executeQuery($sql, array($id)); |
|
59
|
|
|
$this->logger->debug($credential->getLabel() .' is expired, checking notifications!', array('app' => 'passman')); |
|
60
|
|
|
$notifications = intval($result->fetch()['rows']); |
|
61
|
|
|
if($notifications === 0) { |
|
62
|
|
|
$this->logger->debug($credential->getLabel() .' is expired, adding notification!', array('app' => 'passman')); |
|
63
|
|
|
$this->activityService->add( |
|
64
|
|
|
Activity::SUBJECT_ITEM_EXPIRED, array($credential->getLabel(), $credential->getUserId()), |
|
65
|
|
|
'', array(), |
|
66
|
|
|
$link, $credential->getUserId(), Activity::TYPE_ITEM_EXPIRED); |
|
67
|
|
|
$this->notificationService->credentialExpiredNotification($credential); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |