1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Roeland Jago Douma <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OCA\Files_Sharing; |
23
|
|
|
|
24
|
|
|
use OC\BackgroundJob\TimedJob; |
25
|
|
|
use OCP\Share\IManager; |
26
|
|
|
use OCP\IDBConnection; |
27
|
|
|
use OCP\Share\Exceptions\ShareNotFound; |
28
|
|
|
use OCP\ILogger; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Delete all shares that are expired |
32
|
|
|
*/ |
33
|
|
|
class ExpireSharesJob extends TimedJob { |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Database connection |
37
|
|
|
* |
38
|
|
|
* @var IDBConnection |
39
|
|
|
*/ |
40
|
|
|
private $connection; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Share manager |
44
|
|
|
* |
45
|
|
|
* @var IManager |
46
|
|
|
*/ |
47
|
|
|
private $shareManager; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Logger |
51
|
|
|
* |
52
|
|
|
* @var ILogger |
53
|
|
|
*/ |
54
|
|
|
private $logger; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Constructor |
58
|
|
|
* |
59
|
|
|
* @param IDBConnection $connection connection |
60
|
|
|
*/ |
61
|
|
|
public function __construct(IDBConnection $connection, IManager $shareManager, ILogger $logger) { |
62
|
|
|
$this->connection = $connection; |
63
|
|
|
$this->shareManager = $shareManager; |
64
|
|
|
$this->logger = $logger; |
65
|
|
|
// Run once a day |
66
|
|
|
$this->setInterval(24 * 60 * 60); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Makes the background job do its work |
71
|
|
|
* |
72
|
|
|
* @param array $argument unused argument |
73
|
|
|
*/ |
74
|
|
|
public function run($argument) { |
75
|
|
|
// Current time |
76
|
|
|
$now = new \DateTime(); |
77
|
|
|
$now = $now->format('Y-m-d H:i:s'); |
78
|
|
|
|
79
|
|
|
// Expire file link shares only (for now) |
80
|
|
|
$qb = $this->connection->getQueryBuilder(); |
81
|
|
|
$qb->select('id', 'file_source', 'uid_owner', 'item_type') |
|
|
|
|
82
|
|
|
->from('share') |
83
|
|
|
->where( |
84
|
|
|
$qb->expr()->andX( |
85
|
|
|
$qb->expr()->eq('share_type', $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK)), |
86
|
|
|
$qb->expr()->lte('expiration', $qb->expr()->literal($now)), |
87
|
|
|
$qb->expr()->orX( |
88
|
|
|
$qb->expr()->eq('item_type', $qb->expr()->literal('file')), |
89
|
|
|
$qb->expr()->eq('item_type', $qb->expr()->literal('folder')) |
|
|
|
|
90
|
|
|
) |
91
|
|
|
) |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$shares = $qb->execute(); |
95
|
|
|
while ($share = $shares->fetch()) { |
96
|
|
|
try { |
97
|
|
|
// the getShareById already deletes those automatically |
98
|
|
|
$this->shareManager->getShareById('ocinternal:' . $share['id']); |
99
|
|
|
} catch (ShareNotFound $e) { |
100
|
|
|
// ignore, already deleted |
101
|
|
|
$this->logger->debug('ExpireSharesJob: Share with id "' . $share['id'] . '" was already deleted', ['app' => 'files_sharing']); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
$shares->closeCursor(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.