MediaWiki  master
RefreshSecondaryDataUpdate.php
Go to the documentation of this file.
1 <?php
27 
38 {
40  private $lbFactory;
42  private $page;
44  private $updater;
46  private $recursive;
47 
49  private $revisionRecord;
51  private $user;
52 
61  public function __construct(
67  array $options
68  ) {
69  parent::__construct();
70 
71  $this->lbFactory = $lbFactory;
72  $this->user = $user;
73  $this->page = $page;
74  $this->revisionRecord = $revisionRecord;
75  $this->updater = $updater;
76  $this->recursive = !empty( $options['recursive'] );
77  }
78 
79  public function getTransactionRoundRequirement() {
80  return self::TRX_ROUND_ABSENT;
81  }
82 
83  public function doUpdate() {
84  $updates = $this->updater->getSecondaryDataUpdates( $this->recursive );
85  foreach ( $updates as $update ) {
86  if ( $update instanceof LinksUpdate ) {
87  $update->setRevisionRecord( $this->revisionRecord );
88  $update->setTriggeringUser( $this->user );
89  }
90  if ( $update instanceof DataUpdate ) {
91  $update->setCause( $this->causeAction, $this->causeAgent );
92  }
93  }
94 
95  // T221577, T248003: flush any transaction; each update needs outer transaction scope
96  // and the code above may have implicitly started one.
97  $this->lbFactory->commitPrimaryChanges( __METHOD__ );
98 
99  $e = null;
100  foreach ( $updates as $update ) {
101  try {
102  DeferredUpdates::attemptUpdate( $update, $this->lbFactory );
103  } catch ( Exception $e ) {
104  // Try as many updates as possible on the first pass
106  }
107  }
108 
109  if ( $e instanceof Exception ) {
110  throw $e; // trigger RefreshLinksJob enqueue via getAsJobSpecification()
111  }
112  }
113 
114  public function getAsJobSpecification() {
115  return [
116  'domain' => $this->lbFactory->getLocalDomainID(),
117  'job' => new JobSpecification(
118  'refreshLinksPrioritized',
119  [
120  'namespace' => $this->page->getTitle()->getNamespace(),
121  'title' => $this->page->getTitle()->getDBkey(),
122  // Reuse the parser cache if it was saved
123  'rootJobTimestamp' => $this->revisionRecord
124  ? $this->revisionRecord->getTimestamp()
125  : null,
126  'useRecursiveLinksUpdate' => $this->recursive,
127  'triggeringUser' => $this->user
128  ? [
129  'userId' => $this->user->getId(),
130  'userName' => $this->user->getName()
131  ]
132  : null,
133  'triggeringRevisionId' => $this->revisionRecord
134  ? $this->revisionRecord->getId()
135  : null,
136  'causeAction' => $this->getCauseAction(),
137  'causeAgent' => $this->getCauseAgent()
138  ],
139  [ 'removeDuplicates' => true ]
140  )
141  ];
142  }
143 }
RefreshSecondaryDataUpdate\$updater
DerivedPageDataUpdater $updater
Definition: RefreshSecondaryDataUpdate.php:44
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
DeferredUpdates\attemptUpdate
static attemptUpdate(DeferrableUpdate $update, ILBFactory $lbFactory)
Attempt to run an update with the appropriate transaction round state it expects.
Definition: DeferredUpdates.php:488
RefreshSecondaryDataUpdate\getTransactionRoundRequirement
getTransactionRoundRequirement()
Definition: RefreshSecondaryDataUpdate.php:79
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:60
LinksUpdate
Class the manages updates of *_link tables as well as similar extension-managed tables.
Definition: LinksUpdate.php:39
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
TransactionRoundAwareUpdate
Deferrable update that specifies whether it must run outside of any explicit LBFactory transaction ro...
Definition: TransactionRoundAwareUpdate.php:11
DataUpdate
Abstract base class for update jobs that do something with some secondary data extracted from article...
Definition: DataUpdate.php:30
EnqueueableDataUpdate
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Definition: EnqueueableDataUpdate.php:12
RefreshSecondaryDataUpdate\$revisionRecord
RevisionRecord null $revisionRecord
Definition: RefreshSecondaryDataUpdate.php:49
RefreshSecondaryDataUpdate\$page
WikiPage $page
Definition: RefreshSecondaryDataUpdate.php:42
RefreshSecondaryDataUpdate\$user
UserIdentity null $user
Definition: RefreshSecondaryDataUpdate.php:51
MWExceptionHandler\rollbackPrimaryChangesAndLog
static rollbackPrimaryChangesAndLog(Throwable $e, $catcher=self::CAUGHT_BY_OTHER)
Roll back any open database transactions and log the stack trace of the throwable.
Definition: MWExceptionHandler.php:126
JobSpecification
Job queue task description base code.
Definition: JobSpecification.php:42
RefreshSecondaryDataUpdate\$recursive
bool $recursive
Definition: RefreshSecondaryDataUpdate.php:46
RefreshSecondaryDataUpdate\doUpdate
doUpdate()
Perform the actual work.
Definition: RefreshSecondaryDataUpdate.php:83
RefreshSecondaryDataUpdate\$lbFactory
ILBFactory $lbFactory
Definition: RefreshSecondaryDataUpdate.php:40
RefreshSecondaryDataUpdate
Update object handling the cleanup of secondary data after a page was edited.
Definition: RefreshSecondaryDataUpdate.php:38
RefreshSecondaryDataUpdate\__construct
__construct(ILBFactory $lbFactory, UserIdentity $user, WikiPage $page, RevisionRecord $revisionRecord, DerivedPageDataUpdater $updater, array $options)
Definition: RefreshSecondaryDataUpdate.php:61
MediaWiki\Storage\DerivedPageDataUpdater
A handle for managing updates for derived page data on edit, import, purge, etc.
Definition: DerivedPageDataUpdater.php:105
RefreshSecondaryDataUpdate\getAsJobSpecification
getAsJobSpecification()
Definition: RefreshSecondaryDataUpdate.php:114
Wikimedia\Rdbms\ILBFactory
An interface for generating database load balancers.
Definition: ILBFactory.php:33