MediaWiki master
DeleteLinksJob.php
Go to the documentation of this file.
1<?php
22
29
37class DeleteLinksJob extends Job {
38 public function __construct( Title $title, array $params ) {
39 parent::__construct( 'deleteLinks', $title, $params );
40 $this->removeDuplicates = true;
41 }
42
43 public function run() {
44 if ( $this->title === null ) {
45 $this->setLastError( "deleteLinks: Invalid title" );
46 return false;
47 }
48
49 $pageId = $this->params['pageId'];
50
51 // Serialize links updates by page ID so they see each others' changes
52 $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
53 $scopedLock = LinksUpdate::acquirePageLock( $dbw, $pageId, 'job' );
54 if ( $scopedLock === null ) {
55 $this->setLastError( 'LinksUpdate already running for this page, try again later.' );
56 return false;
57 }
58
60 $wikiPageFactory = $services->getWikiPageFactory();
61 if ( $wikiPageFactory->newFromID( $pageId, IDBAccessObject::READ_LATEST ) ) {
62 // The page was restored somehow or something went wrong
63 $this->setLastError( "deleteLinks: Page #$pageId exists" );
64 return false;
65 }
66
67 $dbProvider = $services->getConnectionProvider();
68 $timestamp = $this->params['timestamp'] ?? null;
69 $page = $wikiPageFactory->newFromTitle( $this->title ); // title when deleted
70
71 $update = new LinksDeletionUpdate( $page, $pageId, $timestamp );
72 $update->setTransactionTicket( $dbProvider->getEmptyTransactionTicket( __METHOD__ ) );
73 $update->doUpdate();
74
75 return true;
76 }
77}
78
80class_alias( DeleteLinksJob::class, 'DeleteLinksJob' );
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:41
array $params
Array of job parameters.
Definition Job.php:46
setLastError( $error)
Definition Job.php:435
Job to prune link tables for pages that were deleted.
__construct(Title $title, array $params)
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Represents a title within MediaWiki.
Definition Title.php:78
Interface for database access objects.