MediaWiki master
DeleteLinksJob.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Page;
8
15
23class DeleteLinksJob extends Job {
24 public function __construct( Title $title, array $params ) {
25 parent::__construct( 'deleteLinks', $title, $params );
26 $this->removeDuplicates = true;
27 }
28
30 public function run() {
31 if ( $this->title === null ) {
32 $this->setLastError( "deleteLinks: Invalid title" );
33 return false;
34 }
35
36 $pageId = $this->params['pageId'];
37
38 // Serialize links updates by page ID so they see each others' changes
39 $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
40 $scopedLock = LinksUpdate::acquirePageLock( $dbw, $pageId, 'job' );
41 if ( $scopedLock === null ) {
42 $this->setLastError( 'LinksUpdate already running for this page, try again later.' );
43 return false;
44 }
45
47 $wikiPageFactory = $services->getWikiPageFactory();
48 if ( $wikiPageFactory->newFromID( $pageId, IDBAccessObject::READ_LATEST ) ) {
49 // The page was restored somehow or something went wrong
50 $this->setLastError( "deleteLinks: Page #$pageId exists" );
51 return false;
52 }
53
54 $dbProvider = $services->getConnectionProvider();
55 $timestamp = $this->params['timestamp'] ?? null;
56 $page = $wikiPageFactory->newFromTitle( $this->title ); // title when deleted
57
58 $update = new LinksDeletionUpdate( $page, $pageId, $timestamp );
59 $update->setTransactionTicket( $dbProvider->getEmptyTransactionTicket( __METHOD__ ) );
60 $update->doUpdate();
61
62 return true;
63 }
64}
Update object handling the cleanup of links tables after a page was deleted.
Class the manages updates of *_link tables as well as similar extension-managed tables.
Describe and execute a background job.
Definition Job.php:28
array $params
Array of job parameters.
Definition Job.php:33
setLastError( $error)
Definition Job.php:425
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Job to prune link tables for pages that were deleted.
__construct(Title $title, array $params)
run()
Run the job.If this method returns false or completes exceptionally, the job runner will retry execut...
Represents a title within MediaWiki.
Definition Title.php:69
Interface for database access objects.