3 * Updater for link tracking tables after a page edit.
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
23 * Update object handling the cleanup of links tables after a page was deleted.
25 class LinksDeletionUpdate
extends SqlDataUpdate
implements EnqueueableDataUpdate
{
32 * @param WikiPage $page Page we are updating
33 * @param integer|null $pageId ID of the page we are updating [optional]
36 function __construct( WikiPage
$page, $pageId = null ) {
37 parent
::__construct( false ); // no implicit transaction
40 if ( $page->exists() ) {
41 $this->pageId
= $page->getId();
42 } elseif ( $pageId ) {
43 $this->pageId
= $pageId;
45 throw new MWException( "Page ID not known, perhaps the page doesn't exist?" );
49 public function doUpdate() {
50 # Page may already be deleted, so don't just getId()
53 # Delete restrictions for it
54 $this->mDb
->delete( 'page_restrictions', array( 'pr_page' => $id ), __METHOD__
);
56 # Fix category table counts
57 $cats = $this->mDb
->selectFieldValues(
60 array( 'cl_from' => $id ),
63 $this->page
->updateCategoryCounts( array(), $cats );
65 # If using cascading deletes, we can skip some explicit deletes
66 if ( !$this->mDb
->cascadingDeletes() ) {
67 # Delete outgoing links
68 $this->mDb
->delete( 'pagelinks', array( 'pl_from' => $id ), __METHOD__
);
69 $this->mDb
->delete( 'imagelinks', array( 'il_from' => $id ), __METHOD__
);
70 $this->mDb
->delete( 'categorylinks', array( 'cl_from' => $id ), __METHOD__
);
71 $this->mDb
->delete( 'templatelinks', array( 'tl_from' => $id ), __METHOD__
);
72 $this->mDb
->delete( 'externallinks', array( 'el_from' => $id ), __METHOD__
);
73 $this->mDb
->delete( 'langlinks', array( 'll_from' => $id ), __METHOD__
);
74 $this->mDb
->delete( 'iwlinks', array( 'iwl_from' => $id ), __METHOD__
);
75 $this->mDb
->delete( 'redirect', array( 'rd_from' => $id ), __METHOD__
);
76 $this->mDb
->delete( 'page_props', array( 'pp_page' => $id ), __METHOD__
);
79 # If using cleanup triggers, we can skip some manual deletes
80 if ( !$this->mDb
->cleanupTriggers() ) {
81 $title = $this->page
->getTitle();
82 # Find recentchanges entries to clean up...
83 $rcIdsForTitle = $this->mDb
->selectFieldValues( 'recentchanges',
86 'rc_type != ' . RC_LOG
,
87 'rc_namespace' => $title->getNamespace(),
88 'rc_title' => $title->getDBkey()
92 $rcIdsForPage = $this->mDb
->selectFieldValues( 'recentchanges',
94 array( 'rc_type != ' . RC_LOG
, 'rc_cur_id' => $id ),
98 # T98706: delete PK to avoid lock contention with RC delete log insertions
99 $rcIds = array_merge( $rcIdsForTitle, $rcIdsForPage );
101 $this->mDb
->delete( 'recentchanges', array( 'rc_id' => $rcIds ), __METHOD__
);
106 public function getAsJobSpecification() {
108 'wiki' => $this->mDb
->getWikiID(),
109 'job' => new JobSpecification(
111 array( 'pageId' => $this->pageId
),
112 array( 'removeDuplicates' => true ),
113 $this->page
->getTitle()