* Remove unused user accounts from the database
* An unused account is one which has made no edits
*
- * @file
+ * 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
+ *
* @ingroup Maintenance
* @author Rob Church <robchur@gmail.com>
*/
-require_once( "Maintenance.php" );
+require_once( dirname(__FILE__) . '/Maintenance.php' );
class RemoveUnusedAccounts extends Maintenance {
public function __construct() {
parent::__construct();
- $this->addParam( 'delete', 'Actually delete the account' );
- $this->addParam( 'ignore-groups', 'List of comma-separated groups to exclude', false, true );
- $this->addParam( 'ignore-touched', 'Skip accounts touched in last N days', false, true );
+ $this->addOption( 'delete', 'Actually delete the account' );
+ $this->addOption( 'ignore-groups', 'List of comma-separated groups to exclude', false, true );
+ $this->addOption( 'ignore-touched', 'Skip accounts touched in last N days', false, true );
}
public function execute() {
}
$touched = $this->getOption( 'ignore-touched', "1" );
if( !ctype_digit( $touched ) ) {
- $this->error( "Please put a valid positive integer on the --ignore-touched parameter.\n", true );
+ $this->error( "Please put a valid positive integer on the --ignore-touched parameter.", true );
}
$touchedSeconds = 86400 * $touched;
- while( $row = $dbr->fetchObject( $res ) ) {
+ foreach( $res as $row ) {
# Check the account, but ignore it if it's within a $excludedGroups group or if it's touched within the $touchedSeconds seconds.
$instance = User::newFromId( $row->user_id );
if( count( array_intersect( $instance->getEffectiveGroups(), $excludedGroups ) ) == 0
'image' => 'img', 'oldimage' => 'oi' );
$count = 0;
- $dbo->immediateBegin();
+ $dbo->begin();
foreach( $checks as $table => $fprefix ) {
$conds = array( $fprefix . '_user' => $id );
$count += (int)$dbo->selectField( $table, 'COUNT(*)', $conds, __METHOD__ );
}
- $dbo->immediateCommit();
+ $dbo->commit();
return $count == 0;
}