MediaWiki master
RefreshSecondaryDataUpdate.php
Go to the documentation of this file.
1<?php
32
43{
45 private $lbFactory;
47 private $page;
49 private $updater;
51 private $recursive;
53 private $freshness;
54
56 private $revisionRecord;
58 private $user;
59
68 public function __construct(
69 ILBFactory $lbFactory,
70 UserIdentity $user,
71 WikiPage $page,
72 RevisionRecord $revisionRecord,
74 array $options
75 ) {
76 parent::__construct();
77
78 $this->lbFactory = $lbFactory;
79 $this->user = $user;
80 $this->page = $page;
81 $this->revisionRecord = $revisionRecord;
82 $this->updater = $updater;
83 $this->recursive = !empty( $options['recursive'] );
84 $this->freshness = $options['freshness'] ?? false;
85 }
86
88 return self::TRX_ROUND_ABSENT;
89 }
90
91 public function doUpdate() {
92 $updates = $this->updater->getSecondaryDataUpdates( $this->recursive );
93 foreach ( $updates as $update ) {
94 if ( $update instanceof LinksUpdate ) {
95 $update->setRevisionRecord( $this->revisionRecord );
96 $update->setTriggeringUser( $this->user );
97 }
98 if ( $update instanceof DataUpdate ) {
99 $update->setCause( $this->causeAction, $this->causeAgent );
100 }
101 }
102
103 // T221577, T248003: flush any transaction; each update needs outer transaction scope
104 // and the code above may have implicitly started one.
105 $this->lbFactory->commitPrimaryChanges( __METHOD__ );
106
107 $e = null;
108 foreach ( $updates as $update ) {
109 try {
110 DeferredUpdates::attemptUpdate( $update );
111 } catch ( Exception $e ) {
112 // Try as many updates as possible on the first pass
113 MWExceptionHandler::rollbackPrimaryChangesAndLog( $e );
114 }
115 }
116
117 if ( $e instanceof Exception ) {
118 throw $e; // trigger RefreshLinksJob enqueue via getAsJobSpecification()
119 }
120 }
121
122 public function getAsJobSpecification() {
123 return [
124 'domain' => $this->lbFactory->getLocalDomainID(),
125 'job' => new JobSpecification(
126 'refreshLinksPrioritized',
127 [
128 'namespace' => $this->page->getTitle()->getNamespace(),
129 'title' => $this->page->getTitle()->getDBkey(),
130 // Ensure fresh data are used, for normal data reuse the parser cache if it was saved
131 'rootJobTimestamp' => $this->freshness ?: $this->revisionRecord->getTimestamp(),
132 'useRecursiveLinksUpdate' => $this->recursive,
133 'triggeringUser' => [
134 'userId' => $this->user->getId(),
135 'userName' => $this->user->getName()
136 ],
137 'triggeringRevisionId' => $this->revisionRecord->getId(),
138 'causeAction' => $this->getCauseAction(),
139 'causeAgent' => $this->getCauseAgent()
140 ],
141 [ 'removeDuplicates' => true ]
142 )
143 ];
144 }
145}
Job queue task description base code.
Abstract base class for update jobs that do something with some secondary data extracted from article...
Defer callable updates to run later in the PHP process.
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, UserIdentity $user, WikiPage $page, RevisionRecord $revisionRecord, DerivedPageDataUpdater $updater, array $options)
Base representation for an editable wiki page.
Definition WikiPage.php:79
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 representing user identity.
Manager of ILoadBalancer objects and, indirectly, IDatabase connections.