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

EntityIdDisposerJob   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A newOutdatedEntitiesResultIterator() 0 3 1
A executeWith() 0 8 2
A run() 0 10 2
A doDisposeMarkedEnitites() 0 8 2
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