Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RemoveDuplicateNS
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3require_once( dirname(dirname(dirname(dirname(__DIR__)))) . '/maintenance/Maintenance.php' );
4
5/**
6 * If in table oldimage oi_archive_name contains
7 * multiple NS prefixes, this script fixes it
8 */
9class RemoveDuplicateNS extends Maintenance {
10
11    function __construct() {
12        parent::__construct();
13
14        $this->requireExtension( 'NSFileRepo' );
15    }
16
17    function execute() {
18        $dbw = wfGetDB( DB_PRIMARY );
19        print( "USING DB: " . $dbw->getDBName() . "\n" );
20        $images = $dbw->select( 'oldimage',
21            array( 'oi_name', 'oi_archive_name' ),
22            array(),
23            __METHOD__
24        );
25
26        foreach( $images as $image ) {
27            $archiveTS = explode( '!', $image->oi_archive_name )[0];
28            $archiveName = explode( '!', $image->oi_archive_name )[1];
29            $archiveBits = explode( ':', $archiveName );
30            if( count($archiveBits) > 2 ) {
31                $archiveNS = $archiveBits[0];
32                $archiveFName = $archiveBits[count($archiveBits)-1];
33                unset($archiveBits[count($archiveBits)-1] );
34                $archiveFill = implode( ':', $archiveBits );
35                print( "Removing: " . $archiveFill . PHP_EOL );
36                $dbw->update(
37                    'oldimage',
38                    array(
39                        'oi_archive_name = ' . $dbw->strreplace( 'oi_archive_name',
40                            $dbw->addQuotes( $archiveFill ), $dbw->addQuotes( $archiveNS ) )
41                    ),
42                    array( 'oi_name' => $image->oi_name ),
43                    __METHOD__
44                );
45            } else {
46                continue;
47            }
48        }
49
50    }
51}
52
53$maintClass = RemoveDuplicateNS::class;
54require_once( RUN_MAINTENANCE_IF_MAIN );