|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license AGPL-3.0 |
|
8
|
|
|
* |
|
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
11
|
|
|
* as published by the Free Software Foundation. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace OCA\Files_Sharing; |
|
24
|
|
|
|
|
25
|
|
|
use OC\BackgroundJob\TimedJob; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Delete all shares that are expired |
|
29
|
|
|
*/ |
|
30
|
|
|
class ExpireSharesJob extends TimedJob { |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* sets the correct interval for this timed job |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct() { |
|
36
|
|
|
// Run once a day |
|
37
|
|
|
$this->setInterval(24 * 60 * 60); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Makes the background job do its work |
|
42
|
|
|
* |
|
43
|
|
|
* @param array $argument unused argument |
|
44
|
|
|
*/ |
|
45
|
|
|
public function run($argument) { |
|
46
|
|
|
$connection = \OC::$server->getDatabaseConnection(); |
|
47
|
|
|
$logger = \OC::$server->getLogger(); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
//Current time |
|
50
|
|
|
$now = new \DateTime(); |
|
51
|
|
|
$now = $now->format('Y-m-d H:i:s'); |
|
52
|
|
|
|
|
53
|
|
|
/* |
|
54
|
|
|
* Expire file link shares only (for now) |
|
55
|
|
|
*/ |
|
56
|
|
|
$qb = $connection->getQueryBuilder(); |
|
57
|
|
|
$qb->select('id', 'file_source', 'uid_owner', 'item_type') |
|
58
|
|
|
->from('share') |
|
59
|
|
|
->where( |
|
60
|
|
|
$qb->expr()->andX( |
|
61
|
|
|
$qb->expr()->eq('share_type', $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK)), |
|
62
|
|
|
$qb->expr()->lte('expiration', $qb->expr()->literal($now)), |
|
63
|
|
|
$qb->expr()->orX( |
|
64
|
|
|
$qb->expr()->eq('item_type', $qb->expr()->literal('file')), |
|
65
|
|
|
$qb->expr()->eq('item_type', $qb->expr()->literal('folder')) |
|
66
|
|
|
) |
|
67
|
|
|
) |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$shares = $qb->execute(); |
|
71
|
|
|
while($share = $shares->fetch()) { |
|
72
|
|
|
\OCP\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']); |
|
73
|
|
|
} |
|
74
|
|
|
$shares->closeCursor(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.