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

Discussions/Upgrades/MigrateDiscussionReply.php (1 issue)

1
<?php
2
3
namespace Elgg\Discussions\Upgrades;
4
5
use \Elgg\Upgrade\Batch;
6
use \Elgg\Upgrade\Result;
7
use \Elgg\Database\Update;
8
9
/**
10
 * Migrate 'object', 'discussion_reply' to 'object', 'comment'
11
 *
12
 * @since 3.0
13
 */
14
class MigrateDiscussionReply implements Batch {
15
	
16
	/**
17
	 * {@inheritDoc}
18
	 */
19
	public function getVersion() {
20
		return 2017112800;
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
		$hidden = access_show_hidden_entities(true);
36
		
37
		$count = elgg_get_entities([
38
			'type' => 'object',
39
			'subtype' => 'discussion_reply',
40
			'count' => true,
41
		]);
42
		
43
		access_show_hidden_entities($hidden);
44
		
45
		return $count;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $count also could return the type ElggEntity[]|false which is incompatible with the return type mandated by Elgg\Upgrade\Batch::countItems() of integer.
Loading history...
46
	}
47
	
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	public function needsIncrementOffset() {
52
		return false;
53
	}
54
	
55
	/**
56
	 * {@inheritDoc}
57
	 */
58
	public function run(Result $result, $offset) {
59
		
60
		$qb = Update::table('entities', 'e')
61
			->set('e.subtype', '"comment"')
62
			->where('e.subtype = "discussion_reply"');
63
		
64
		$count = $qb->execute();
65
		
66
		$result->addSuccesses($count);
67
		
68
		return $result;
69
	}
70
}
71