Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DeleteLinksJob | |
0.00% |
0 / 23 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 |
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. |
7 | * |
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. |
12 | * |
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 |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | use MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate; |
22 | use MediaWiki\Deferred\LinksUpdate\LinksUpdate; |
23 | use MediaWiki\MediaWikiServices; |
24 | use MediaWiki\Title\Title; |
25 | |
26 | /** |
27 | * Job to prune link tables for pages that were deleted |
28 | * |
29 | * @internal For use by core in LinksDeletionUpdate only. |
30 | * @since 1.27 |
31 | * @ingroup JobQueue |
32 | */ |
33 | class DeleteLinksJob extends Job { |
34 | public function __construct( Title $title, array $params ) { |
35 | parent::__construct( 'deleteLinks', $title, $params ); |
36 | $this->removeDuplicates = true; |
37 | } |
38 | |
39 | public function run() { |
40 | if ( $this->title === null ) { |
41 | $this->setLastError( "deleteLinks: Invalid title" ); |
42 | return false; |
43 | } |
44 | |
45 | $pageId = $this->params['pageId']; |
46 | |
47 | // Serialize links updates by page ID so they see each others' changes |
48 | $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
49 | $scopedLock = LinksUpdate::acquirePageLock( $dbw, $pageId, 'job' ); |
50 | if ( $scopedLock === null ) { |
51 | $this->setLastError( 'LinksUpdate already running for this page, try again later.' ); |
52 | return false; |
53 | } |
54 | |
55 | $services = MediaWikiServices::getInstance(); |
56 | $wikiPageFactory = $services->getWikiPageFactory(); |
57 | if ( $wikiPageFactory->newFromID( $pageId, IDBAccessObject::READ_LATEST ) ) { |
58 | // The page was restored somehow or something went wrong |
59 | $this->setLastError( "deleteLinks: Page #$pageId exists" ); |
60 | return false; |
61 | } |
62 | |
63 | $dbProvider = $services->getConnectionProvider(); |
64 | $timestamp = $this->params['timestamp'] ?? null; |
65 | $page = $wikiPageFactory->newFromTitle( $this->title ); // title when deleted |
66 | |
67 | $update = new LinksDeletionUpdate( $page, $pageId, $timestamp ); |
68 | $update->setTransactionTicket( $dbProvider->getEmptyTransactionTicket( __METHOD__ ) ); |
69 | $update->doUpdate(); |
70 | |
71 | return true; |
72 | } |
73 | } |