MediaWiki REL1_35
RefreshSecondaryDataUpdate.php
Go to the documentation of this file.
1<?php
26
37{
39 private $lbFactory;
41 private $page;
43 private $updater;
45 private $recursive;
46
50 private $user;
51
60 public function __construct(
61 ILBFactory $lbFactory,
62 User $user,
63 WikiPage $page,
64 RevisionRecord $revisionRecord,
66 array $options
67 ) {
68 parent::__construct();
69
70 $this->lbFactory = $lbFactory;
71 $this->user = $user;
72 $this->page = $page;
73 $this->revisionRecord = $revisionRecord;
74 $this->updater = $updater;
75 $this->recursive = !empty( $options['recursive'] );
76 }
77
79 return self::TRX_ROUND_ABSENT;
80 }
81
82 public function doUpdate() {
83 $updates = $this->updater->getSecondaryDataUpdates( $this->recursive );
84 foreach ( $updates as $update ) {
85 if ( $update instanceof LinksUpdate ) {
86 $update->setRevisionRecord( $this->revisionRecord );
87 $update->setTriggeringUser( $this->user );
88 }
89 if ( $update instanceof DataUpdate ) {
90 $update->setCause( $this->causeAction, $this->causeAgent );
91 }
92 }
93
94 // T221577, T248003: flush any transaction; each update needs outer transaction scope
95 // and the code above may have implicitly started one.
96 $this->lbFactory->commitMasterChanges( __METHOD__ );
97
98 $e = null;
99 foreach ( $updates as $update ) {
100 try {
101 DeferredUpdates::attemptUpdate( $update, $this->lbFactory );
102 } catch ( Exception $e ) {
103 // Try as many updates as possible on the first pass
104 MWExceptionHandler::rollbackMasterChangesAndLog( $e );
105 }
106 }
107
108 if ( $e instanceof Exception ) {
109 throw $e; // trigger RefreshLinksJob enqueue via getAsJobSpecification()
110 }
111 }
112
113 public function getAsJobSpecification() {
114 return [
115 'domain' => $this->lbFactory->getLocalDomainID(),
116 'job' => new JobSpecification(
117 'refreshLinksPrioritized',
118 [
119 'namespace' => $this->page->getTitle()->getNamespace(),
120 'title' => $this->page->getTitle()->getDBkey(),
121 // Reuse the parser cache if it was saved
122 'rootJobTimestamp' => $this->revisionRecord
123 ? $this->revisionRecord->getTimestamp()
124 : null,
125 'useRecursiveLinksUpdate' => $this->recursive,
126 'triggeringUser' => $this->user
127 ? [
128 'userId' => $this->user->getId(),
129 'userName' => $this->user->getName()
130 ]
131 : null,
132 'triggeringRevisionId' => $this->revisionRecord
133 ? $this->revisionRecord->getId()
134 : null,
135 'causeAction' => $this->getCauseAction(),
136 'causeAgent' => $this->getCauseAgent()
137 ],
138 [ 'removeDuplicates' => true ]
139 )
140 ];
141 }
142}
Abstract base class for update jobs that do something with some secondary data extracted from article...
Job queue task description base code.
Class the manages updates of *_link tables as well as similar extension-managed tables.
Page revision base class.
A handle for managing updates for derived page data on edit, import, purge, etc.
Update object handling the cleanup of secondary data after a page was edited.
__construct(ILBFactory $lbFactory, User $user, WikiPage $page, RevisionRecord $revisionRecord, DerivedPageDataUpdater $updater, array $options)
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
Class representing a MediaWiki article and history.
Definition WikiPage.php:51
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Deferrable update that specifies whether it must run outside of any explicit LBFactory transaction ro...
An interface for generating database load balancers.
return true
Definition router.php:92