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
Loading history...
|
|||
67 | |||
68 | return $result; |
||
69 | } |
||
70 | } |