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