Completed
Push — master ( f5d374...685013 )
by mw
47:54 queued 25:05
created

newOutdatedEntitiesResultIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\MediaWiki\Jobs;
4
5
use Hooks;
6
use SMW\ApplicationFactory;
7
use SMW\SQLStore\PropertyTableIdReferenceDisposer;
8
use Title;
9
10
/**
11
 * @license GNU GPL v2+
12
 * @since 2.5
13
 *
14
 * @author mwjames
15
 */
16
class EntityIdDisposerJob extends JobBase {
17
18
	/**
19
	 * @var PropertyTableIdReferenceDisposer
20
	 */
21
	private $propertyTableIdReferenceDisposer;
22
23
	/**
24
	 * @since 2.5
25
	 *
26
	 * @param Title $title
27
	 * @param array $params job parameters
28
	 */
29 5
	public function __construct( Title $title, $params = array() ) {
30 5
		parent::__construct( 'SMW\EntityIdDisposerJob', $title, $params );
31
32 5
		$this->propertyTableIdReferenceDisposer = new PropertyTableIdReferenceDisposer(
33 5
			ApplicationFactory::getInstance()->getStore( '\SMW\SQLStore\SQLStore' )
34
		);
35 5
	}
36
37
	/**
38
	 * @since  2.5
39
	 *
40
	 * @return ResultIterator
41
	 */
42 3
	public function newOutdatedEntitiesResultIterator() {
43 3
		return $this->propertyTableIdReferenceDisposer->newOutdatedEntitiesResultIterator();
44
	}
45
46
	/**
47
	 * @since  2.5
48
	 *
49
	 * @param integer|stdClass $id
50
	 */
51 3
	public function executeWith( $id ) {
52
53 3
		if ( is_int( $id ) ) {
54 1
			return $this->propertyTableIdReferenceDisposer->cleanUpTableEntriesById( $id );
55
		}
56
57 2
		$this->propertyTableIdReferenceDisposer->cleanUpTableEntriesByRow( $id );
58 2
	}
59
60
	/**
61
	 * @see Job::run
62
	 *
63
	 * @since  2.5
64
	 */
65 2
	public function run() {
66
67 2
		if ( $this->hasParameter( 'id' ) ) {
68 1
			$this->executeWith( $this->getParameter( 'id' ) );
69
		} else {
70 1
			$this->doDisposeMarkedEnitites();
71
		}
72
73 2
		return true;
74
	}
75
76 1
	private function doDisposeMarkedEnitites() {
77
78 1
		$outdatedEntitiesResultIterator = $this->newOutdatedEntitiesResultIterator();
79
80 1
		foreach ( $outdatedEntitiesResultIterator as $row ) {
81 1
			$this->executeWith( $row );
82
		}
83 1
	}
84
85
}
86