28 require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
40 $this->
addArg(
'offset',
'' );
41 $this->
addArg(
'start',
'Starting timestamp' );
42 $this->
addArg(
'end',
'Ending timestamp' );
46 $offset = $this->
getArg( 0 ) * 3600;
47 $start = $this->
getArg( 1 );
52 # Find bounding revision IDs
54 $revisionTable = $dbw->tableName(
'revision' );
55 $res = $dbw->query(
"SELECT MIN(rev_id) as minrev, MAX(rev_id) as maxrev FROM $revisionTable " .
56 "WHERE rev_timestamp BETWEEN '{$start}' AND '{$end}'", __METHOD__ );
57 $row =
$res->fetchObject();
59 if ( $row->minrev ===
null ) {
60 $this->
fatalError(
"No revisions in search period." );
63 $minRev = $row->minrev;
64 $maxRev = $row->maxrev;
66 # Select all timestamps and IDs
67 $sql =
"SELECT rev_id, rev_timestamp FROM $revisionTable " .
68 "WHERE rev_id BETWEEN $minRev AND $maxRev";
70 $sql .=
" ORDER BY rev_id DESC";
76 $res = $dbw->query( $sql, __METHOD__ );
82 foreach (
$res as $row ) {
83 $timestamp = (int)
wfTimestamp( TS_UNIX, $row->rev_timestamp );
84 $delta = $timestamp - $lastNormal;
85 $sign = $delta == 0 ? 0 : $delta / abs( $delta );
86 if ( $sign == 0 || $sign == $expectedSign ) {
88 $lastNormal = $timestamp;
90 } elseif ( abs( $delta ) <= $grace ) {
95 $badRevs[] = $row->rev_id;
99 $numBadRevs = count( $badRevs );
100 if ( $numBadRevs > $numGoodRevs ) {
102 "The majority of revisions in the search interval are marked as bad.
104 Are you sure the offset ($offset) has the right sign? Positive means the clock
105 was incorrectly set forward, negative means the clock was incorrectly set back.
107 If the offset is right, then increase the search interval until there are enough
108 good revisions to provide a majority reference." );
109 } elseif ( $numBadRevs == 0 ) {
110 $this->
output(
"No bad revisions found.\n" );
114 $this->
output( sprintf(
"Fixing %d revisions (%.2f%% of revisions in search interval)\n",
115 $numBadRevs, $numBadRevs / ( $numGoodRevs + $numBadRevs ) * 100 ) );
118 $sql =
"UPDATE $revisionTable " .
120 .
"DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
121 "WHERE rev_id IN (" . $dbw->makeList( $badRevs ) .
')';
122 $dbw->query( $sql, __METHOD__ );
123 $this->
output(
"Done\n" );
128 require_once RUN_MAINTENANCE_IF_MAIN;
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Maintenance script that fixes timestamp corruption caused by one or more webservers temporarily being...
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.