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