MediaWiki master
RefreshSecondaryDataUpdate.php
Go to the documentation of this file.
1<?php
8
9namespace MediaWiki\Deferred;
10
11use Exception;
12use MediaWiki\Deferred\LinksUpdate\LinksUpdate;
13use MediaWiki\Exception\MWExceptionHandler;
14use MediaWiki\JobQueue\JobSpecification;
15use MediaWiki\Page\PageIdentity;
16use MediaWiki\Revision\RevisionRecord;
17use MediaWiki\Storage\DerivedPageDataUpdater;
18use MediaWiki\User\UserIdentity;
19use Wikimedia\Rdbms\ILBFactory;
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 // FIXME: The possible checked exception types should be better documented
108 // @phan-suppress-next-line PhanThrowTypeAbsent
109 throw $e; // trigger RefreshLinksJob enqueue via getAsJobSpecification()
110 }
111 }
112
114 public function getAsJobSpecification() {
115 return [
116 'domain' => $this->lbFactory->getLocalDomainID(),
117 'job' => new JobSpecification(
118 'refreshLinksPrioritized',
119 [
120 'namespace' => $this->page->getNamespace(),
121 'title' => $this->page->getDBkey(),
122 // Ensure fresh data are used, for normal data reuse the parser cache if it was saved
123 'rootJobTimestamp' => $this->freshness ?: $this->revisionRecord->getTimestamp(),
124 'useRecursiveLinksUpdate' => $this->recursive,
125 'triggeringUser' => [
126 'userId' => $this->user->getId(),
127 'userName' => $this->user->getName()
128 ],
129 'triggeringRevisionId' => $this->revisionRecord->getId(),
130 'causeAction' => $this->getCauseAction(),
131 'causeAgent' => $this->getCauseAgent()
132 ],
133 [ 'removeDuplicates' => true ]
134 )
135 ];
136 }
137}
138
139class_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.
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
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.