2006-06-05 05:21:12 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Fix the user_registration field.
|
|
|
|
|
* In particular, for values which are NULL, set them to the date of the first edit
|
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-06-05 05:21:12 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2022-12-16 11:41:52 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2006-06-05 05:21:12 +00:00
|
|
|
|
2012-07-10 16:50:19 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that fixes the user_registration field.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class FixUserRegistration extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Fix the user_registration field' );
|
2015-03-16 20:07:33 +00:00
|
|
|
$this->setBatchSize( 1000 );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2006-06-05 05:21:12 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2006-06-05 05:21:12 +00:00
|
|
|
|
2015-03-16 20:07:33 +00:00
|
|
|
$lastId = 0;
|
|
|
|
|
do {
|
|
|
|
|
// Get user IDs which need fixing
|
2023-09-21 11:54:38 +00:00
|
|
|
$res = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( 'user_id' )
|
|
|
|
|
->from( 'user' )
|
2024-01-17 17:48:40 +00:00
|
|
|
->where( [ $dbw->expr( 'user_id', '>', $lastId ), 'user_registration' => null ] )
|
2023-09-21 11:54:38 +00:00
|
|
|
->orderBy( 'user_id' )
|
|
|
|
|
->limit( $this->getBatchSize() )
|
|
|
|
|
->caller( __METHOD__ )->fetchResultSet();
|
2023-09-26 18:40:35 +00:00
|
|
|
|
2015-03-16 20:07:33 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$id = $row->user_id;
|
|
|
|
|
$lastId = $id;
|
2023-09-26 18:40:35 +00:00
|
|
|
|
2015-03-16 20:07:33 +00:00
|
|
|
// Get first edit time
|
2023-10-13 08:19:26 +00:00
|
|
|
$actorStore = $this->getServiceContainer()->getActorStore();
|
2023-09-26 18:40:35 +00:00
|
|
|
$userIdentity = $actorStore->getUserIdentityByUserId( $id );
|
|
|
|
|
if ( !$userIdentity ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$timestamp = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( 'MIN(rev_timestamp)' )
|
|
|
|
|
->from( 'revision' )
|
|
|
|
|
->where( [ 'rev_actor' => $userIdentity->getId() ] )
|
|
|
|
|
->caller( __METHOD__ )->fetchField();
|
|
|
|
|
|
2015-03-16 20:07:33 +00:00
|
|
|
// Update
|
2015-03-17 02:33:25 +00:00
|
|
|
if ( $timestamp !== null ) {
|
2023-09-26 18:40:35 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'user' )
|
|
|
|
|
->set( [ 'user_registration' => $timestamp ] )
|
|
|
|
|
->where( [ 'user_id' => $id ] )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
|
|
|
|
|
2015-03-16 20:07:33 +00:00
|
|
|
$user = User::newFromId( $id );
|
|
|
|
|
$user->invalidateCache();
|
|
|
|
|
$this->output( "Set registration for #$id to $timestamp\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "Could not find registration for #$id NULL\n" );
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2016-09-05 20:14:41 +00:00
|
|
|
$this->output( "Waiting for replica DBs..." );
|
2022-10-24 18:31:49 +00:00
|
|
|
$this->waitForReplication();
|
2015-03-16 20:07:33 +00:00
|
|
|
$this->output( " done.\n" );
|
2017-11-05 08:09:51 +00:00
|
|
|
} while ( $res->numRows() >= $this->getBatchSize() );
|
2006-06-05 05:21:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = FixUserRegistration::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|