Completed
Push — master ( 314506...335380 )
by mw
100:54 queued 62:54
created

tests/phpunit/Utils/PageRefresher.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SMW\Tests\Utils;
4
5
use RuntimeException;
6
use SMW\ApplicationFactory;
7
use SMW\ContentParser;
8
use SMW\DIWikiPage;
9
use SMW\MediaWiki\Jobs\UpdateJob;
10
use SMW\Store;
11
use Title;
12
use WikiPage;
13
14
/**
15
 *
16
 * @group SMW
17
 * @group SMWExtension
18
 *
19
 * @license GNU GPL v2+
20
 * @since 2.0
21
 */
22
class PageRefresher {
23
24
	/**
25
	 * @since 2.0
26
	 *
27
	 * @param mixed $title
28
	 *
29
	 * @return PageRefresher
30
	 */
31
	public function doRefresh( $title ) {
32
33
		if ( $title instanceof WikiPage || $title instanceof DIWikiPage ) {
0 ignored issues
show
The class WikiPage does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
34
			$title = $title->getTitle();
35
		}
36
37
		if ( !$title instanceof Title ) {
0 ignored issues
show
The class Title does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
38
			throw new RuntimeException( 'Expected a title instance' );
39
		}
40
41
		$contentParser = new ContentParser( $title );
42
		$contentParser->forceToUseParser();
43
44
		$parserData = ApplicationFactory::getInstance()->newParserData(
45
			$title,
46
			$contentParser->parse()->getOutput()
47
		);
48
49
		$parserData->updateStore();
50
51
		return $this;
52
	}
53
54
	/**
55
	 * @since 2.1
56
	 *
57
	 * @param array $pages
58
	 *
59
	 * @return PageRefresher
60
	 */
61
	public function doRefreshPoolOfPages( array $pages ) {
62
		foreach ( $pages as $page ) {
63
			$this->doRefreshByUpdateJob( $page );
64
		}
65
	}
66
67
	/**
68
	 * @since 2.1
69
	 *
70
	 * @param mixed $title
71
	 *
72
	 * @return PageRefresher
73
	 */
74
	public function doRefreshByUpdateJob( $title ) {
75
76
		if ( $title instanceof WikiPage || $title instanceof DIWikiPage ) {
0 ignored issues
show
The class WikiPage does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
77
			$title = $title->getTitle();
78
		}
79
80
		if ( is_string( $title ) ) {
81
			$title = Title::newFromText( $title );
82
		}
83
84
		if ( !$title instanceof Title ) {
0 ignored issues
show
The class Title does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
85
			throw new RuntimeException( 'Expected a title instance' );
86
		}
87
88
		$job = new UpdateJob( $title );
89
		$job->run();
90
91
		return $this;
92
	}
93
94
}
95