Completed
Push — stable9 ( 485cb1...e094cf )
by Lukas
26:41 queued 26:23
created

ExpireSharesJob::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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();
0 ignored issues
show
Unused Code introduced by
$logger is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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