Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
FRExtraCacheUpdateJob | |
0.00% |
0 / 51 |
|
0.00% |
0 / 5 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
doBacklinkPurge | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
doUpdateLinks | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
doUpdateSyncState | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | use MediaWiki\MediaWikiServices; |
4 | use MediaWiki\Title\Title; |
5 | |
6 | /** |
7 | * Job class for handling deferred FRExtraCacheUpdates |
8 | * @ingroup JobQueue |
9 | */ |
10 | class FRExtraCacheUpdateJob extends Job { |
11 | /** |
12 | * @param Title $title The title linked to |
13 | * @param array $params Job parameters (start and end page_ids) |
14 | */ |
15 | public function __construct( $title, $params ) { |
16 | parent::__construct( 'flaggedrevs_CacheUpdate', $title, $params ); |
17 | |
18 | $this->params['type'] ??= 'purge'; |
19 | // The range (start/end) make 'purge' jobs a bad candidate for de-duplication. |
20 | $this->removeDuplicates = in_array( |
21 | $this->params['type'], [ 'updatelinks', 'updatesyncstate' ] |
22 | ); |
23 | } |
24 | |
25 | /** |
26 | * @inheritDoc |
27 | */ |
28 | public function run() { |
29 | if ( $this->params['type'] === 'purge' ) { |
30 | return $this->doBacklinkPurge(); |
31 | } elseif ( $this->params['type'] === 'updatelinks' ) { |
32 | return $this->doUpdateLinks(); |
33 | } elseif ( $this->params['type'] === 'updatesyncstate' ) { |
34 | return $this->doUpdateSyncState(); |
35 | } else { |
36 | throw new InvalidArgumentException( "Missing 'type' parameter." ); |
37 | } |
38 | } |
39 | |
40 | /** |
41 | * @return bool |
42 | */ |
43 | private function doBacklinkPurge() { |
44 | $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
45 | |
46 | $update = new FRExtraCacheUpdate( $this->title ); |
47 | # Get query conditions |
48 | $conds = $update->getToCondition(); |
49 | if ( $this->params['start'] ) { |
50 | $conds[] = $dbr->expr( 'ftr_from', '>=', $this->params['start'] ); |
51 | } |
52 | if ( $this->params['end'] ) { |
53 | $conds[] = $dbr->expr( 'ftr_from', '<=', $this->params['end'] ); |
54 | } |
55 | // Run query to get page Ids |
56 | $pageIds = $dbr->newSelectQueryBuilder() |
57 | ->select( 'ftr_from' ) |
58 | ->from( 'flaggedrevs_tracking' ) |
59 | ->where( $conds ) |
60 | ->caller( __METHOD__ ) |
61 | ->fetchFieldValues(); |
62 | // Invalidate the pages |
63 | $update->invalidateIDs( $pageIds ); |
64 | return true; |
65 | } |
66 | |
67 | private function doUpdateLinks() { |
68 | $fpage = FlaggableWikiPage::getTitleInstance( $this->title ); |
69 | $srev = $fpage->getStableRev(); |
70 | if ( $srev ) { |
71 | $pOpts = $fpage->makeParserOptions( 'canonical' ); |
72 | $stableOut = FlaggedRevs::parseStableRevision( $srev, $pOpts ); |
73 | |
74 | if ( $stableOut ) { |
75 | // Update the stable-only dependency links right now |
76 | $frDepUpdate = new FRDependencyUpdate( $this->title, $stableOut ); |
77 | $frDepUpdate->doUpdate( FRDependencyUpdate::IMMEDIATE ); |
78 | |
79 | return true; |
80 | } |
81 | } |
82 | |
83 | // If not page or revision was found, remove the stable-only links |
84 | FlaggedRevs::clearStableOnlyDeps( $fpage->getId() ); |
85 | return true; |
86 | } |
87 | |
88 | private function doUpdateSyncState() { |
89 | $fpage = FlaggableWikiPage::getTitleInstance( $this->title ); |
90 | if ( !$fpage->getId() || !$fpage->getStable() ) { |
91 | return true; |
92 | } |
93 | |
94 | $synced = $fpage->stableVersionIsSynced(); |
95 | if ( $fpage->syncedInTracking() != $synced ) { |
96 | $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
97 | |
98 | $dbw->newUpdateQueryBuilder() |
99 | ->update( 'flaggedpages' ) |
100 | ->set( [ 'fp_reviewed' => $synced ? 1 : 0 ] ) |
101 | ->where( [ 'fp_page_id' => $fpage->getId() ] ) |
102 | ->caller( __METHOD__ ) |
103 | ->execute(); |
104 | } |
105 | return true; |
106 | } |
107 | } |