Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.83% |
23 / 24 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
GlobalConfigAnchorUpdateJob | |
95.83% |
23 / 24 |
|
66.67% |
2 / 3 |
6 | |
0.00% |
0 / 1 |
newSpec | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
run | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\MediaUploader\Config; |
4 | |
5 | use CommentStoreComment; |
6 | use GenericParameterJob; |
7 | use Job; |
8 | use JobSpecification; |
9 | use MediaWiki\Extension\MediaUploader\Campaign\CampaignContent; |
10 | use MediaWiki\Extension\MediaUploader\MediaUploaderServices; |
11 | use MediaWiki\MediaWikiServices; |
12 | use MWException; |
13 | |
14 | /** |
15 | * Job for updating the global config anchor page (Campaign:-). |
16 | * |
17 | * It refreshes the list of templates used by the anchor to ensure future recursive |
18 | * LinksUpdates will invalidate the global config cache. |
19 | */ |
20 | class GlobalConfigAnchorUpdateJob extends Job implements GenericParameterJob { |
21 | |
22 | public const NAME = 'globalConfigAnchorUpdate'; |
23 | |
24 | /** |
25 | * Returns a JobSpecification for this job. |
26 | * |
27 | * @return JobSpecification |
28 | */ |
29 | public static function newSpec(): JobSpecification { |
30 | return new JobSpecification( self::NAME, [] ); |
31 | } |
32 | |
33 | /** |
34 | * @param array $params |
35 | */ |
36 | public function __construct( array $params ) { |
37 | parent::__construct( self::NAME, $params ); |
38 | } |
39 | |
40 | /** |
41 | * @inheritDoc |
42 | * @throws MWException |
43 | */ |
44 | public function run(): bool { |
45 | $services = MediaWikiServices::getInstance(); |
46 | $wikiPageFactory = $services->getWikiPageFactory(); |
47 | $anchor = $wikiPageFactory->newFromLinkTarget( |
48 | CampaignContent::getGlobalConfigAnchorLinkTarget() |
49 | ); |
50 | |
51 | $content = $anchor->getContent(); |
52 | if ( !$content ) { |
53 | $contentHandler = $services->getContentHandlerFactory()->getContentHandler( |
54 | CampaignContent::MODEL_ID |
55 | ); |
56 | $content = $contentHandler->makeEmptyContent(); |
57 | } |
58 | |
59 | $pageUpdater = $anchor->newPageUpdater( |
60 | MediaUploaderServices::getSystemUser() |
61 | ); |
62 | $pageUpdater->setContent( 'main', $content ); |
63 | |
64 | $lastRevision = $anchor->getRevisionRecord(); |
65 | if ( $lastRevision ) { |
66 | $lastRevisionId = $lastRevision->getId(); |
67 | if ( $lastRevisionId ) { |
68 | // This is needed so that the edit is correctly marked as 'null' |
69 | $pageUpdater->setOriginalRevisionId( $lastRevisionId ); |
70 | } |
71 | } |
72 | |
73 | $pageUpdater->saveRevision( CommentStoreComment::newUnsavedComment( '' ) ); |
74 | |
75 | return true; |
76 | } |
77 | } |