-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertDeleteWikiBlobs.php
110 lines (94 loc) · 3.02 KB
/
convertDeleteWikiBlobs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Set the correct include path for PHP so that we can run this script from
* $IP/extensions/ShoutWikiMaintenance and we don't need to move this file to
* $IP/maintenance/.
*/
ini_set( 'include_path', dirname( __FILE__ ) . '/../../maintenance' );
require_once( 'Maintenance.php' );
class ConvertDeleteWikiBlobs extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = 'Adds the relevant relations like setRelations using old log_params and converts them to serialized PHP.';
$this->addOption( 'run', 'Actually move stuff around instead of doing a dry run', false, false );
}
public function execute() {
$this->output( "Start the script" );
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
'logging',
array(
'log_id',
'log_params',
),
array(
'log_type' => 'createwiki',
'log_action' => 'delete',
),
__METHOD__,
array( 'ORDER BY' => 'log_timestamp ASC' )
);
foreach( $res as $row ) {
$unblobbed = $this->unserializeRow( $row->log_params, $row->log_id );
$this->output( "<" .rawurlencode($unblobbed['4::wikiname'] ). ">\n");
$this->setRelationsData( $unblobbed['4::wikiname'], $row->log_id );
}
}
private function unserializeRow( $loggingContents, $logID ) {
wfSuppressWarnings();
$check = unserialize( $loggingContents );
wfRestoreWarnings();
if( $check === false ) {
$check = $this->convertOldFormat( $loggingContents );
$this->reserializeRow( $check, $logID );
}
$loggingContents = $check;
return $loggingContents;
}
private function convertOldFormat( $oldFormatData ) {
// Function converts old format to new format.
//var_dump( "prior convert", rawurlencode( $oldFormatData ) );
$oldFormatCheck = explode("\n", $oldFormatData)[0];
//var_dump( "mid convert", rawurlencode( $oldFormatCheck ) );
$oldFormatCheck = trim( $oldFormatCheck );
//var_dump( "post convert", rawurlencode( $oldFormatCheck ) );
$explosion = explode( '.', $oldFormatCheck );
if( count( $explosion ) === 0 ) {
$lang = 'en';
} elseif( 1 < count( $explosion ) ) {
if( Language::isValidCode( $explosion[0] ) ) {
$lang = $explosion[0];
} else {
$lang = 'en';
}
} else {
$lang = 'en';
}
$newFormatData = array(
'4::wikiname' => $oldFormatCheck,
'5::language' => $lang,
);
return $newFormatData;
}
private function reserializeRow( $blobContents, $id ) {
// If a format update has occured, write the new format back to the database.
$blobContents = serialize( $blobContents );
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'logging', array( 'log_params' => $blobContents ), array( 'log_id' => $id ), __METHOD__ );
}
private function setRelationsData( $wikiname, $logid ) {
// Act like ManualLogEntry::setRelations.
$dbw = wfGetDB( DB_MASTER );
$dbw->insert(
'log_search',
array(
'ls_field' => 'deletedwiki',
'ls_value' => $wikiname,
'ls_log_id' => $logid,
),
__METHOD__
);
}
}
$maintClass = "ConvertDeleteWikiBlobs";
require_once RUN_MAINTENANCE_IF_MAIN;