Update docs/hooks.txt for ShowSearchHitTitle
[mediawiki.git] / includes / jobqueue / jobs / DeleteLinksJob.php
blob5c0f89f73f0e62c7fbe131d26d7e56f88ba4e043
1 <?php
2 /**
3 * Job to update link tables for pages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup JobQueue
23 use \MediaWiki\MediaWikiServices;
25 /**
26 * Job to prune link tables for pages that were deleted
28 * Only DataUpdate classes should construct these jobs
30 * @ingroup JobQueue
31 * @since 1.27
33 class DeleteLinksJob extends Job {
34 function __construct( Title $title, array $params ) {
35 parent::__construct( 'deleteLinks', $title, $params );
36 $this->removeDuplicates = true;
39 function run() {
40 if ( is_null( $this->title ) ) {
41 $this->setLastError( "deleteLinks: Invalid title" );
42 return false;
45 $pageId = $this->params['pageId'];
47 // Serialize links updates by page ID so they see each others' changes
48 $scopedLock = LinksUpdate::acquirePageLock( wfGetDB( DB_MASTER ), $pageId, 'job' );
50 if ( WikiPage::newFromID( $pageId, WikiPage::READ_LATEST ) ) {
51 // The page was restored somehow or something went wrong
52 $this->setLastError( "deleteLinks: Page #$pageId exists" );
53 return false;
56 $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
57 $timestamp = isset( $this->params['timestamp'] ) ? $this->params['timestamp'] : null;
58 $page = WikiPage::factory( $this->title ); // title when deleted
60 $update = new LinksDeletionUpdate( $page, $pageId, $timestamp );
61 $update->setTransactionTicket( $factory->getEmptyTransactionTicket( __METHOD__ ) );
62 $update->doUpdate();
64 return true;