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