Page MenuHomeMiraheze
Paste P365

T6095
ActivePublic

Authored by Southparkfan on Jan 1 2021, 19:18.
Referenced Files
F1372708: T6095
Jan 1 2021, 19:18
Subscribers
None
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @author Southparkfan
* @version 1.0
*/
require_once '/srv/mediawiki/w/maintenance/Maintenance.php';
class ApplyPatchT6095 extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = 'ApplyPatchT6095';
}
public function execute() {
global $wgLocalDatabases;
sort( $wgLocalDatabases );
$dbClusterArr = [
'c1' => [],
'c2' => [],
'c3' => [],
'c4' => [],
];
foreach ( $wgLocalDatabases as $wikiDb ) {
$wikiObj = new RemoteWiki( $wikiDb );
$dbClusterArr[$wikiObj->getDBCluster()][] = $wikiDb;
unset( $wikiObj );
}
foreach ( $dbClusterArr['c2'] as $wikiDb ) {
$dbObj = wfGetDB( DB_MASTER, [], $wikiDb );
$rlTable = [];
$rlTable[$wikiDb] = [];
foreach ( $dbObj->query( 'DESCRIBE rottenlinks' ) as $row ) {
$rlTable[$wikiDb][$row->Field] = [
'Type' => $row->Type,
'Key' => $row->Key
];
}
if ( !isset( $rlTable[$wikiDb]['rl_id'] ) ) {
$this->output( "ALTER TABLE {$wikiDb}.rottenlinks DROP INDEX IF EXISTS `PRIMARY`;\n" );
$this->output( "ALTER TABLE {$wikiDb}.rottenlinks ADD COLUMN rl_id INT AUTO_INCREMENT PRIMARY KEY;\n" );
$this->output( "ALTER TABLE {$wikiDb}.rottenlinks MODIFY COLUMN rl_id INT AUTO_INCREMENT FIRST;\n" );
}
if ( $rlTable[$wikiDb]['rl_externallink']['Type'] != 'blob' ) {
$this->output( "ALTER TABLE {$wikiDb}.rottenlinks MODIFY COLUMN rl_externallink BLOB NOT NULL;\n" );
}
}
}
}
$maintClass = 'ApplyPatchT6095';
require_once RUN_MAINTENANCE_IF_MAIN;