MediaWiki master
RefreshSecondaryDataUpdate.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Deferred;
24
25use Exception;
34
45{
47 private $lbFactory;
49 private $page;
51 private $updater;
53 private $recursive;
55 private $freshness;
56
58 private $revisionRecord;
60 private $user;
61
70 public function __construct(
71 ILBFactory $lbFactory,
72 UserIdentity $user,
73 PageIdentity $page,
74 RevisionRecord $revisionRecord,
76 array $options
77 ) {
78 parent::__construct();
79
80 $this->lbFactory = $lbFactory;
81 $this->user = $user;
82 $this->page = $page;
83 $this->revisionRecord = $revisionRecord;
84 $this->updater = $updater;
85 $this->recursive = !empty( $options['recursive'] );
86 $this->freshness = $options['freshness'] ?? false;
87 }
88
90 return self::TRX_ROUND_ABSENT;
91 }
92
93 public function doUpdate() {
94 $updates = $this->updater->getSecondaryDataUpdates( $this->recursive );
95 foreach ( $updates as $update ) {
96 if ( $update instanceof LinksUpdate ) {
97 $update->setRevisionRecord( $this->revisionRecord );
98 $update->setTriggeringUser( $this->user );
99 }
100 if ( $update instanceof DataUpdate ) {
101 $update->setCause( $this->causeAction, $this->causeAgent );
102 }
103 }
104
105 // T221577, T248003: flush any transaction; each update needs outer transaction scope
106 // and the code above may have implicitly started one.
107 $this->lbFactory->commitPrimaryChanges( __METHOD__ );
108
109 $e = null;
110 foreach ( $updates as $update ) {
111 try {
113 } catch ( Exception $e ) {
114 // Try as many updates as possible on the first pass
115 MWExceptionHandler::rollbackPrimaryChangesAndLog( $e );
116 }
117 }
118
119 if ( $e instanceof Exception ) {
120 throw $e; // trigger RefreshLinksJob enqueue via getAsJobSpecification()
121 }
122 }
123
124 public function getAsJobSpecification() {
125 return [
126 'domain' => $this->lbFactory->getLocalDomainID(),
127 'job' => new JobSpecification(
128 'refreshLinksPrioritized',
129 [
130 'namespace' => $this->page->getNamespace(),
131 'title' => $this->page->getDBkey(),
132 // Ensure fresh data are used, for normal data reuse the parser cache if it was saved
133 'rootJobTimestamp' => $this->freshness ?: $this->revisionRecord->getTimestamp(),
134 'useRecursiveLinksUpdate' => $this->recursive,
135 'triggeringUser' => [
136 'userId' => $this->user->getId(),
137 'userName' => $this->user->getName()
138 ],
139 'triggeringRevisionId' => $this->revisionRecord->getId(),
140 'causeAction' => $this->getCauseAction(),
141 'causeAgent' => $this->getCauseAgent()
142 ],
143 [ 'removeDuplicates' => true ]
144 )
145 ];
146 }
147}
149class_alias( RefreshSecondaryDataUpdate::class, 'RefreshSecondaryDataUpdate' );
Job queue task description base code.
Handler class for MWExceptions.
Abstract base class for update jobs that do something with some secondary data extracted from article...
static attemptUpdate(DeferrableUpdate $update)
Attempt to run an update with the appropriate transaction round state if needed.
Class the manages updates of *_link tables as well as similar extension-managed tables.
Update object handling the cleanup of secondary data after a page was edited.
__construct(ILBFactory $lbFactory, UserIdentity $user, PageIdentity $page, RevisionRecord $revisionRecord, DerivedPageDataUpdater $updater, array $options)
Page revision base class.
A handle for managing updates for derived page data on edit, import, purge, etc.
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...
Interface for objects (potentially) representing an editable wiki page.
Interface for objects representing user identity.
Manager of ILoadBalancer objects and, indirectly, IDatabase connections.