| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Deferred; |
| 24 |
|
| 25 |
use Exception; |
| 26 |
use JobSpecification; |
| 27 |
use MediaWiki\Deferred\LinksUpdate\LinksUpdate; |
| 28 |
use MediaWiki\Page\PageIdentity; |
| 29 |
use MediaWiki\Revision\RevisionRecord; |
| 30 |
use MediaWiki\Storage\DerivedPageDataUpdater; |
| 31 |
use MediaWiki\User\UserIdentity; |
| 32 |
use MWExceptionHandler; |
| 33 |
use Wikimedia\Rdbms\ILBFactory; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
class RefreshSecondaryDataUpdate extends DataUpdate |
| 44 |
implements TransactionRoundAwareUpdate, EnqueueableDataUpdate |
| 45 |
{ |
| 46 |
|
| 47 |
private $lbFactory; |
| 48 |
|
| 49 |
private $page; |
| 50 |
|
| 51 |
private $updater; |
| 52 |
|
| 53 |
private $recursive; |
| 54 |
|
| 55 |
private $freshness; |
| 56 |
|
| 57 |
|
| 58 |
private $revisionRecord; |
| 59 |
|
| 60 |
private $user; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public function __construct( |
| 71 |
ILBFactory $lbFactory, |
| 72 |
UserIdentity $user, |
| 73 |
PageIdentity $page, |
| 74 |
RevisionRecord $revisionRecord, |
| 75 |
DerivedPageDataUpdater $updater, |
| 76 |
array $options |
| 77 |
) { |
| 78 |
parent::__construct(); |
| 79 |
|
| 80 |
$this->lbFactory = $lbFactory; |
| 81 |
$this->user = $user; |
| 82 |
$this->page = $page; |
| 83 |
$this->revisionRecord = $revisionRecord; |
| 84 |
$this->updater = $updater; |
| 85 |
$this->recursive = !empty( $options['recursive'] ); |
| 86 |
$this->freshness = $options['freshness'] ?? false; |
| 87 |
} |
| 88 |
|
| 89 |
public function getTransactionRoundRequirement() { |
| 90 |
return self::TRX_ROUND_ABSENT; |
| 91 |
} |
| 92 |
|
| 93 |
public function doUpdate() { |
| 94 |
$updates = $this->updater->getSecondaryDataUpdates( $this->recursive ); |
| 95 |
foreach ( $updates as $update ) { |
| 96 |
if ( $update instanceof LinksUpdate ) { |
| 97 |
$update->setRevisionRecord( $this->revisionRecord ); |
| 98 |
$update->setTriggeringUser( $this->user ); |
| 99 |
} |
| 100 |
if ( $update instanceof DataUpdate ) { |
| 101 |
$update->setCause( $this->causeAction, $this->causeAgent ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
$this->lbFactory->commitPrimaryChanges( __METHOD__ ); |
| 108 |
|
| 109 |
$e = null; |
| 110 |
foreach ( $updates as $update ) { |
| 111 |
try { |
| 112 |
DeferredUpdates::attemptUpdate( $update ); |
| 113 |
} catch ( Exception $e ) { |
| 114 |
|
| 115 |
MWExceptionHandler::rollbackPrimaryChangesAndLog( $e ); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
if ( $e instanceof Exception ) { |
| 120 |
throw $e; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
public function getAsJobSpecification() { |
| 125 |
return [ |
| 126 |
'domain' => $this->lbFactory->getLocalDomainID(), |
| 127 |
'job' => new JobSpecification( |
| 128 |
'refreshLinksPrioritized', |
| 129 |
[ |
| 130 |
'namespace' => $this->page->getNamespace(), |
| 131 |
'title' => $this->page->getDBkey(), |
| 132 |
|
| 133 |
'rootJobTimestamp' => $this->freshness ?: $this->revisionRecord->getTimestamp(), |
| 134 |
'useRecursiveLinksUpdate' => $this->recursive, |
| 135 |
'triggeringUser' => [ |
| 136 |
'userId' => $this->user->getId(), |
| 137 |
'userName' => $this->user->getName() |
| 138 |
], |
| 139 |
'triggeringRevisionId' => $this->revisionRecord->getId(), |
| 140 |
'causeAction' => $this->getCauseAction(), |
| 141 |
'causeAgent' => $this->getCauseAgent() |
| 142 |
], |
| 143 |
[ 'removeDuplicates' => true ] |
| 144 |
) |
| 145 |
]; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
class_alias( RefreshSecondaryDataUpdate::class, 'RefreshSecondaryDataUpdate' ); |