Skip to content

Commit

Permalink
bug40299 - invalid node "4::tags" in API response
Browse files Browse the repository at this point in the history
1. replace 4::tags with tags
2. maintenance script to fix existing data

Change-Id: I762af893146052d0c79e9db97f38baa5ed4254c7
  • Loading branch information
bsitu authored and kaldari committed Sep 18, 2012
1 parent 2fc1fd4 commit 6d9105c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/ApiPageTriageTagging.php
Expand Up @@ -83,7 +83,7 @@ public function execute() {
$logEntry->setComment( $note );
}
$logEntry->setParameters( array(
'4::tags' => $params['taglist'],
'tags' => $params['taglist'],
) );
$logEntry->publish( $logEntry->insert() );
}
Expand Down
9 changes: 7 additions & 2 deletions includes/PageTriageLogFormatter.php
Expand Up @@ -9,9 +9,14 @@ protected function getActionMessage() {
$params = array(
Message::rawParam( $this->getPerformerElement() ),
$this->entry->getPerformer()->getName(),
Message::rawParam( $this->makePageLink( $this->entry->getTarget() ) ),
'4::tags' => $wgContLang->listToText( $parameters['4::tags'] )
Message::rawParam( $this->makePageLink( $this->entry->getTarget() ) )
);
// backward compatibility
if ( isset( $parameters['4::tags'] ) ) {
$params['4::tags'] = $wgContLang->listToText( $parameters['4::tags'] );
} else {
$params['tags'] = $wgContLang->listToText( $parameters['tags'] );
}

return wfMessage( 'logentry-' . $this->entry->getType() . '-' . $this->entry->getSubtype(), $params );
}
Expand Down
71 changes: 71 additions & 0 deletions tools/cleanupPageTriageLog.php
@@ -0,0 +1,71 @@
<?php
/**
* update parameter name from '4::tags' to 'tags' in pagetriage-curation
* and pagetriage-deletion log
*
* @ingroup Maintenance
*/

require_once( dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );

/**
* Maintenance script that updates parameter name from '4::tags' to 'tags' in pagetriage-curation
* and pagetriage-deletion log
*
* @ingroup Maintenance
*/
class CleanupPageTriageLog extends Maintenance {

protected $batchSize = 100;

public function execute() {
$dbw = wfGetDB( DB_MASTER );
$dbr = wfGetDB( DB_SLAVE );

// clean up the following type and action
$logTypes = array(
array( 'type' => 'pagetriage-curation', 'action' => 'tag' ),
array( 'type' => 'pagetriage-curation', 'action' => 'delete' ),
array( 'type' => 'pagetriage-deletion', 'action' => 'delete' )
);

foreach ( $logTypes as $type ) {
$count = $this->batchSize;
$startTime = wfTimestamp( TS_UNIX ) - 60 * 24 * 60 * 60;

while ( $count == $this->batchSize ) {
$res = $dbr->select(
array( 'logging' ),
array( 'log_id', 'log_timestamp', 'log_params' ),
array(
'log_type' => $type['type'],
'log_action' => $type['action'],
'log_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $startTime ) )
),
__METHOD__,
array( 'LIMIT' => $this->batchSize, 'ORDER BY' => 'log_timestamp' )
);

$count = 0;
foreach( $res as $row ) {
$newLogParams = str_replace( 's:7:"4::tags";', 's:4:"tags";', $row->log_params );

$dbw->update(
'logging',
array( 'log_params' => $newLogParams ),
array( 'log_id' => $row->log_id )
);

$startTime = wfTimestamp( TS_UNIX, $row->log_timestamp );
$count++;
}

$this->output( "processed " . $type['type'] . ' ' . $type['action'] . ': ' . $count . "\n" );
wfWaitForSlaves();
}
}
}
}

$maintClass = 'CleanupPageTriageLog'; // Tells it to run the class
require_once( RUN_MAINTENANCE_IF_MAIN );

0 comments on commit 6d9105c

Please sign in to comment.