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 | use Wikimedia\Rdbms\IDBAccessObject; |
26 | |
27 | /** |
28 | * Job to prune link tables for pages that were deleted |
29 | * |
30 | * @internal For use by core in LinksDeletionUpdate only. |
31 | * @since 1.27 |
32 | * @ingroup JobQueue |
33 | */ |
34 | class 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 | } |