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