Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / jobqueue / jobs / DeleteLinksJob.php
blob59677efad123dd0d45849e4fbfb92de627c58822
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 use MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate;
22 use MediaWiki\Deferred\LinksUpdate\LinksUpdate;
23 use MediaWiki\MediaWikiServices;
24 use MediaWiki\Title\Title;
25 use Wikimedia\Rdbms\IDBAccessObject;
27 /**
28 * Job to prune link tables for pages that were deleted
30 * @internal For use by core in LinksDeletionUpdate only.
31 * @since 1.27
32 * @ingroup JobQueue
34 class DeleteLinksJob extends Job {
35 public function __construct( Title $title, array $params ) {
36 parent::__construct( 'deleteLinks', $title, $params );
37 $this->removeDuplicates = true;
40 public function run() {
41 if ( $this->title === null ) {
42 $this->setLastError( "deleteLinks: Invalid title" );
43 return false;
46 $pageId = $this->params['pageId'];
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;
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;
64 $dbProvider = $services->getConnectionProvider();
65 $timestamp = $this->params['timestamp'] ?? null;
66 $page = $wikiPageFactory->newFromTitle( $this->title ); // title when deleted
68 $update = new LinksDeletionUpdate( $page, $pageId, $timestamp );
69 $update->setTransactionTicket( $dbProvider->getEmptyTransactionTicket( __METHOD__ ) );
70 $update->doUpdate();
72 return true;