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
Bug
introduced
by
![]() |
|||
34 | $title = $title->getTitle(); |
||
35 | } |
||
36 | |||
37 | if ( !$title instanceof Title ) { |
||
0 ignored issues
–
show
|
|||
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
|
|||
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
|
|||
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 |