MediaWiki master
RefreshSecondaryDataUpdate.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Deferred;
10
11use Exception;
20
31{
33 private $lbFactory;
35 private $page;
37 private $updater;
39 private $recursive;
41 private $freshness;
42
44 private $revisionRecord;
46 private $user;
47
56 public function __construct(
57 ILBFactory $lbFactory,
58 UserIdentity $user,
59 PageIdentity $page,
60 RevisionRecord $revisionRecord,
62 array $options
63 ) {
64 parent::__construct();
65
66 $this->lbFactory = $lbFactory;
67 $this->user = $user;
68 $this->page = $page;
69 $this->revisionRecord = $revisionRecord;
70 $this->updater = $updater;
71 $this->recursive = !empty( $options['recursive'] );
72 $this->freshness = $options['freshness'] ?? false;
73 }
74
77 return self::TRX_ROUND_ABSENT;
78 }
79
80 public function doUpdate() {
81 $updates = $this->updater->getSecondaryDataUpdates( $this->recursive );
82 foreach ( $updates as $update ) {
83 if ( $update instanceof LinksUpdate ) {
84 $update->setRevisionRecord( $this->revisionRecord );
85 $update->setTriggeringUser( $this->user );
86 }
87 if ( $update instanceof DataUpdate ) {
88 $update->setCause( $this->causeAction, $this->causeAgent );
89 }
90 }
91
92 // T221577, T248003: flush any transaction; each update needs outer transaction scope
93 // and the code above may have implicitly started one.
94 $this->lbFactory->commitPrimaryChanges( __METHOD__ );
95
96 $e = null;
97 foreach ( $updates as $update ) {
98 try {
100 } catch ( Exception $e ) {
101 // Try as many updates as possible on the first pass
102 MWExceptionHandler::rollbackPrimaryChangesAndLog( $e );
103 }
104 }
105
106 if ( $e instanceof Exception ) {
107 throw $e; // trigger RefreshLinksJob enqueue via getAsJobSpecification()
108 }
109 }
110
112 public function getAsJobSpecification() {
113 return [
114 'domain' => $this->lbFactory->getLocalDomainID(),
115 'job' => new JobSpecification(
116 'refreshLinksPrioritized',
117 [
118 'namespace' => $this->page->getNamespace(),
119 'title' => $this->page->getDBkey(),
120 // Ensure fresh data are used, for normal data reuse the parser cache if it was saved
121 'rootJobTimestamp' => $this->freshness ?: $this->revisionRecord->getTimestamp(),
122 'useRecursiveLinksUpdate' => $this->recursive,
123 'triggeringUser' => [
124 'userId' => $this->user->getId(),
125 'userName' => $this->user->getName()
126 ],
127 'triggeringRevisionId' => $this->revisionRecord->getId(),
128 'causeAction' => $this->getCauseAction(),
129 'causeAgent' => $this->getCauseAgent()
130 ],
131 [ 'removeDuplicates' => true ]
132 )
133 ];
134 }
135}
137class_alias( RefreshSecondaryDataUpdate::class, 'RefreshSecondaryDataUpdate' );
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.
getAsJobSpecification()
array (domain => DB domain ID, job => IJobSpecification)
__construct(ILBFactory $lbFactory, UserIdentity $user, PageIdentity $page, RevisionRecord $revisionRecord, DerivedPageDataUpdater $updater, array $options)
getTransactionRoundRequirement()
int One of the class TRX_ROUND_* constants
Handler class for MWExceptions.
Job queue task description base code.
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.