Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

PublicLikesAnnotations::needsIncrementOffset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Elgg\Likes\Upgrades;
3
4
use Elgg\Upgrade\Batch;
5
use Elgg\Upgrade\Result;
6
7
class PublicLikesAnnotations implements Batch {
8
	
9
	/**
10
	 * {@inheritdoc}
11
	 */
12
	public function getVersion() {
13
		return 2017120700;
14
	}
15
16
	/**
17
	 * {@inheritdoc}
18
	 */
19
	public function needsIncrementOffset() {
20
		return false;
21
	}
22
	
23
	/**
24
	 * {@inheritdoc}
25
	 */
26
	public function shouldBeSkipped() {
27
		return empty($this->countItems());
28
	}
29
	
30
	/**
31
	 * {@inheritdoc}
32
	 */
33
	public function countItems() {
34
		$dbprefix = elgg_get_config('dbprefix');
35
		$public = ACCESS_PUBLIC;
36
		
37
		$query = "SELECT COUNT(*) as total
38
			FROM {$dbprefix}annotations
39
			WHERE name = 'likes'
40
			AND access_id != {$public}
41
		";
42
		
43
		$row = get_data_row($query);
44
		if (empty($row)) {
45
			return 0;
46
		}
47
		
48
		return (int) $row->total;
49
	}
50
	
51
	/**
52
	 * {@inheritDoc}
53
	 */
54
	public function run(Result $result, $offset) {
55
		$dbprefix = elgg_get_config('dbprefix');
56
		$public = ACCESS_PUBLIC;
57
		
58
		$query = "UPDATE {$dbprefix}annotations
59
			SET access_id = {$public}
60
			WHERE name = 'likes'
61
			AND access_id != {$public}
62
		";
63
		
64
		$count = update_data($query, [], true);
65
		
66
		$result->addSuccesses($count);
0 ignored issues
show
Bug introduced by
$count of type boolean is incompatible with the type integer expected by parameter $num of Elgg\Upgrade\Result::addSuccesses(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
		$result->addSuccesses(/** @scrutinizer ignore-type */ $count);
Loading history...
67
		
68
		return $result;
69
	}
70
}