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

Elgg/Pages/Upgrades/MigratePageTopRiver.php (1 issue)

1
<?php
2
3
namespace Elgg\Pages\Upgrades;
4
5
use ElggRiverItem;
6
use \Elgg\Upgrade\Batch;
7
use \Elgg\Upgrade\Result;
8
9
/**
10
 * Migrate river entries for 'object', 'page_top' to 'object', 'page'
11
 *
12
 * @since 3.0
13
 */
14
class MigratePageTopRiver implements Batch {
15
	
16
	/**
17
	 * {@inheritDoc}
18
	 */
19
	public function getVersion() {
20
		return 2017110701;
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
		
35
		$dbprefix = elgg_get_config('dbprefix');
36
		
37
		$query = "SELECT COUNT(*) as total
38
			FROM {$dbprefix}river
39
			WHERE type = 'object'
40
			AND subtype = 'page_top'
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 needsIncrementOffset() {
55
		return false;
56
	}
57
	
58
	/**
59
	 * {@inheritDoc}
60
	 */
61
	public function run(Result $result, $offset) {
62
		
63
		$dbprefix = elgg_get_config('dbprefix');
64
		
65
		$query = "UPDATE {$dbprefix}river
66
			SET subtype = 'page'
67
			WHERE type = 'object'
68
			AND subtype = 'page_top'
69
		";
70
		
71
		$count = update_data($query, [], true);
72
		
73
		$result->addSuccesses($count);
0 ignored issues
show
$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

73
		$result->addSuccesses(/** @scrutinizer ignore-type */ $count);
Loading history...
74
		
75
		return $result;
76
	}
77
}
78