3 * Optional upgrade script to populate *_from_namespace fields
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
21 * @ingroup Maintenance
24 require_once __DIR__
. '/Maintenance.php';
27 * Maintenance script to populate *_from_namespace fields
29 * @ingroup Maintenance
31 class PopulateBacklinkNamespace
extends LoggedUpdateMaintenance
{
32 public function __construct() {
33 parent
::__construct();
34 $this->mDescription
= "Populate the *_from_namespace fields";
37 protected function getUpdateKey() {
38 return 'populate *_from_namespace';
41 protected function updateSkippedMessage() {
42 return '*_from_namespace column of backlink tables already populated.';
45 public function doDBUpdates() {
46 $force = $this->getOption( 'force' );
48 $db = $this->getDB( DB_MASTER
);
50 $this->output( "Updating *_from_namespace fields in links tables.\n" );
52 $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__
);
54 $this->output( "Nothing to do." );
57 $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__
);
60 $end +
= $this->mBatchSize
- 1;
62 $blockEnd = $start +
$this->mBatchSize
- 1;
63 while ( $blockEnd <= $end ) {
64 $this->output( "...doing page_id from $blockStart to $blockEnd\n" );
65 $cond = "page_id BETWEEN $blockStart AND $blockEnd";
66 $res = $db->select( 'page', array( 'page_id', 'page_namespace' ), $cond, __METHOD__
);
67 foreach ( $res as $row ) {
68 $db->update( 'pagelinks',
69 array( 'pl_from_namespace' => $row->page_namespace
),
70 array( 'pl_from' => $row->page_id
),
73 $db->update( 'templatelinks',
74 array( 'tl_from_namespace' => $row->page_namespace
),
75 array( 'tl_from' => $row->page_id
),
78 $db->update( 'imagelinks',
79 array( 'il_from_namespace' => $row->page_namespace
),
80 array( 'il_from' => $row->page_id
),
84 $blockStart +
= $this->mBatchSize
- 1;
85 $blockEnd +
= $this->mBatchSize
- 1;
92 $maintClass = "PopulateBacklinkNamespace";
93 require_once RUN_MAINTENANCE_IF_MAIN
;