65a8c0e0b1a11dfe7b50fc3ba48ace9ae445278f
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()
52 // Make sure all links update threads see the changes of each other.
53 // This handles the case when updates have to batched into several COMMITs.
54 $scopedLock = LinksUpdate
::acquirePageLock( $this->mDb
, $id );
56 # Delete restrictions for it
57 $this->mDb
->delete( 'page_restrictions', [ 'pr_page' => $id ], __METHOD__
);
59 # Fix category table counts
60 $cats = $this->mDb
->selectFieldValues(
66 $this->page
->updateCategoryCounts( [], $cats );
68 # If using cascading deletes, we can skip some explicit deletes
69 if ( !$this->mDb
->cascadingDeletes() ) {
70 # Delete outgoing links
71 $this->mDb
->delete( 'pagelinks', [ 'pl_from' => $id ], __METHOD__
);
72 $this->mDb
->delete( 'imagelinks', [ 'il_from' => $id ], __METHOD__
);
73 $this->mDb
->delete( 'categorylinks', [ 'cl_from' => $id ], __METHOD__
);
74 $this->mDb
->delete( 'templatelinks', [ 'tl_from' => $id ], __METHOD__
);
75 $this->mDb
->delete( 'externallinks', [ 'el_from' => $id ], __METHOD__
);
76 $this->mDb
->delete( 'langlinks', [ 'll_from' => $id ], __METHOD__
);
77 $this->mDb
->delete( 'iwlinks', [ 'iwl_from' => $id ], __METHOD__
);
78 $this->mDb
->delete( 'redirect', [ 'rd_from' => $id ], __METHOD__
);
79 $this->mDb
->delete( 'page_props', [ 'pp_page' => $id ], __METHOD__
);
82 # If using cleanup triggers, we can skip some manual deletes
83 if ( !$this->mDb
->cleanupTriggers() ) {
84 $title = $this->page
->getTitle();
85 # Find recentchanges entries to clean up...
86 $rcIdsForTitle = $this->mDb
->selectFieldValues( 'recentchanges',
89 'rc_type != ' . RC_LOG
,
90 'rc_namespace' => $title->getNamespace(),
91 'rc_title' => $title->getDBkey()
95 $rcIdsForPage = $this->mDb
->selectFieldValues( 'recentchanges',
97 [ 'rc_type != ' . RC_LOG
, 'rc_cur_id' => $id ],
101 # T98706: delete PK to avoid lock contention with RC delete log insertions
102 $rcIds = array_merge( $rcIdsForTitle, $rcIdsForPage );
104 $this->mDb
->delete( 'recentchanges', [ 'rc_id' => $rcIds ], __METHOD__
);
108 $this->mDb
->onTransactionIdle( function() use ( &$scopedLock ) {
109 // Release the lock *after* the final COMMIT for correctness
110 ScopedCallback
::consume( $scopedLock );
114 public function getAsJobSpecification() {
116 'wiki' => $this->mDb
->getWikiID(),
117 'job' => new JobSpecification(
119 [ 'pageId' => $this->pageId
],
120 [ 'removeDuplicates' => true ],
121 $this->page
->getTitle()