2006-04-18 00:10:54 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-07-10 16:50:19 +00:00
|
|
|
* Fixes timestamp corruption caused by one or more webservers temporarily
|
|
|
|
|
* being set to the wrong time.
|
|
|
|
|
* The time offset must be known and consistent. Start and end times
|
|
|
|
|
* (in 14-character format) restrict the search, and must bracket the damage.
|
|
|
|
|
* There must be a majority of good timestamps in the search period.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2012-07-10 16:50:19 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2006-04-18 00:10:54 +00:00
|
|
|
*/
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2012-07-10 16:50:19 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that fixes timestamp corruption caused by one or
|
|
|
|
|
* more webservers temporarily being set to the wrong time.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class FixTimestamps extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( '' );
|
2009-08-18 23:06:24 +00:00
|
|
|
$this->addArg( 'offset', '' );
|
|
|
|
|
$this->addArg( 'start', 'Starting timestamp' );
|
|
|
|
|
$this->addArg( 'end', 'Ending timestamp' );
|
2006-04-18 00:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2010-05-22 16:50:39 +00:00
|
|
|
$offset = $this->getArg( 0 ) * 3600;
|
|
|
|
|
$start = $this->getArg( 1 );
|
|
|
|
|
$end = $this->getArg( 2 );
|
2009-08-02 19:35:17 +00:00
|
|
|
$grace = 60; // maximum normal clock offset
|
2010-05-22 16:50:39 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Find bounding revision IDs
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbw = $this->getDB( DB_MASTER );
|
2009-08-02 19:35:17 +00:00
|
|
|
$revisionTable = $dbw->tableName( 'revision' );
|
|
|
|
|
$res = $dbw->query( "SELECT MIN(rev_id) as minrev, MAX(rev_id) as maxrev FROM $revisionTable " .
|
|
|
|
|
"WHERE rev_timestamp BETWEEN '{$start}' AND '{$end}'", __METHOD__ );
|
|
|
|
|
$row = $dbw->fetchObject( $res );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
if ( is_null( $row->minrev ) ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "No revisions in search period." );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$minRev = $row->minrev;
|
|
|
|
|
$maxRev = $row->maxrev;
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Select all timestamps and IDs
|
|
|
|
|
$sql = "SELECT rev_id, rev_timestamp FROM $revisionTable " .
|
|
|
|
|
"WHERE rev_id BETWEEN $minRev AND $maxRev";
|
|
|
|
|
if ( $offset > 0 ) {
|
|
|
|
|
$sql .= " ORDER BY rev_id DESC";
|
|
|
|
|
$expectedSign = -1;
|
|
|
|
|
} else {
|
|
|
|
|
$expectedSign = 1;
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$res = $dbw->query( $sql, __METHOD__ );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$lastNormal = 0;
|
2016-02-17 09:09:32 +00:00
|
|
|
$badRevs = [];
|
2009-08-02 19:35:17 +00:00
|
|
|
$numGoodRevs = 0;
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-17 21:15:31 +00:00
|
|
|
foreach ( $res as $row ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$timestamp = wfTimestamp( TS_UNIX, $row->rev_timestamp );
|
|
|
|
|
$delta = $timestamp - $lastNormal;
|
|
|
|
|
$sign = $delta == 0 ? 0 : $delta / abs( $delta );
|
|
|
|
|
if ( $sign == 0 || $sign == $expectedSign ) {
|
|
|
|
|
// Monotonic change
|
|
|
|
|
$lastNormal = $timestamp;
|
2014-04-23 18:09:13 +00:00
|
|
|
++$numGoodRevs;
|
2009-08-02 19:35:17 +00:00
|
|
|
continue;
|
|
|
|
|
} elseif ( abs( $delta ) <= $grace ) {
|
|
|
|
|
// Non-monotonic change within grace interval
|
2014-04-23 18:09:13 +00:00
|
|
|
++$numGoodRevs;
|
2009-08-02 19:35:17 +00:00
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
// Non-monotonic change larger than grace interval
|
|
|
|
|
$badRevs[] = $row->rev_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$numBadRevs = count( $badRevs );
|
|
|
|
|
if ( $numBadRevs > $numGoodRevs ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError(
|
2014-04-23 18:09:13 +00:00
|
|
|
"The majority of revisions in the search interval are marked as bad.
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2010-12-04 03:20:14 +00:00
|
|
|
Are you sure the offset ($offset) has the right sign? Positive means the clock
|
2009-08-02 19:35:17 +00:00
|
|
|
was incorrectly set forward, negative means the clock was incorrectly set back.
|
|
|
|
|
|
2010-12-04 03:20:14 +00:00
|
|
|
If the offset is right, then increase the search interval until there are enough
|
2017-11-20 00:36:54 +00:00
|
|
|
good revisions to provide a majority reference." );
|
2009-08-02 19:35:17 +00:00
|
|
|
} elseif ( $numBadRevs == 0 ) {
|
|
|
|
|
$this->output( "No bad revisions found.\n" );
|
2010-05-22 16:50:39 +00:00
|
|
|
exit( 0 );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
$this->output( sprintf( "Fixing %d revisions (%.2f%% of revisions in search interval)\n",
|
|
|
|
|
$numBadRevs, $numBadRevs / ( $numGoodRevs + $numBadRevs ) * 100 ) );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$fixup = -$offset;
|
|
|
|
|
$sql = "UPDATE $revisionTable " .
|
2014-04-23 08:53:03 +00:00
|
|
|
"SET rev_timestamp="
|
|
|
|
|
. "DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
|
2009-08-02 19:35:17 +00:00
|
|
|
"WHERE rev_id IN (" . $dbw->makeList( $badRevs ) . ')';
|
|
|
|
|
$dbw->query( $sql, __METHOD__ );
|
|
|
|
|
$this->output( "Done\n" );
|
|
|
|
|
}
|
2006-04-18 00:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = FixTimestamps::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|