bbdfcf1705851e779c412b209f25220ba73bea6d
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
24 * Update object handling the cleanup of links tables after a page was deleted.
26 class LinksDeletionUpdate
extends SqlDataUpdate
{
27 /** @var WikiPage The WikiPage that was deleted */
33 * @param WikiPage $page Page we are updating
36 function __construct( WikiPage
$page ) {
37 parent
::__construct( false ); // no implicit transaction
41 if ( !$page->exists() ) {
42 throw new MWException( "Page ID not known, perhaps the page doesn't exist?" );
47 * Do some database updates after deletion
49 public function doUpdate() {
50 $title = $this->mPage
->getTitle();
51 $id = $this->mPage
->getId();
53 # Delete restrictions for it
54 $this->mDb
->delete( 'page_restrictions', array( 'pr_page' => $id ), __METHOD__
);
56 # Fix category table counts
58 $res = $this->mDb
->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__
);
60 foreach ( $res as $row ) {
61 $cats[] = $row->cl_to
;
64 $this->mPage
->updateCategoryCounts( array(), $cats );
66 # If using cascading deletes, we can skip some explicit deletes
67 if ( !$this->mDb
->cascadingDeletes() ) {
68 # Delete outgoing links
69 $this->mDb
->delete( 'pagelinks', array( 'pl_from' => $id ), __METHOD__
);
70 $this->mDb
->delete( 'imagelinks', array( 'il_from' => $id ), __METHOD__
);
71 $this->mDb
->delete( 'categorylinks', array( 'cl_from' => $id ), __METHOD__
);
72 $this->mDb
->delete( 'templatelinks', array( 'tl_from' => $id ), __METHOD__
);
73 $this->mDb
->delete( 'externallinks', array( 'el_from' => $id ), __METHOD__
);
74 $this->mDb
->delete( 'langlinks', array( 'll_from' => $id ), __METHOD__
);
75 $this->mDb
->delete( 'iwlinks', array( 'iwl_from' => $id ), __METHOD__
);
76 $this->mDb
->delete( 'redirect', array( 'rd_from' => $id ), __METHOD__
);
77 $this->mDb
->delete( 'page_props', array( 'pp_page' => $id ), __METHOD__
);
80 # If using cleanup triggers, we can skip some manual deletes
81 if ( !$this->mDb
->cleanupTriggers() ) {
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__
);