36 $option = $this->
getArg( 0 );
39 $maxUserId = $dbr->newSelectQueryBuilder()
40 ->select(
'MAX(user_id)' )
42 ->caller( __METHOD__ )
45 $duration =
'P' . (int)$this->
getOption(
'login-age', 5 ) .
'Y';
46 $cutoff = $dbr->timestamp( (
new DateTime() )->sub(
new DateInterval( $duration ) )->getTimestamp() );
47 for ( $min = 0; $min <= $maxUserId; $min += $this->
getBatchSize() ) {
48 $userIdsToClean = $dbr->newSelectQueryBuilder()
51 ->where( $dbr->expr(
'user_id',
'>=', $min ) )
52 ->where( $dbr->expr(
'user_id',
'<', $min + $this->getBatchSize() ) )
53 ->where( $dbr->expr(
'user_touched',
'<', $cutoff ) )
54 ->where( $dbr->expr(
'user_editcount',
'<', (
int)$this->getOption(
'max-editcount', 100 ) ) )
55 ->caller( __METHOD__ )->fetchFieldValues();
56 if ( $userIdsToClean === [] ) {
61 $this->
output(
'The script will clean up user_properties for the following users ' .
62 json_encode( $userIdsToClean ) .
"\n" );
66 $deleteQueryBuilder = $dbw->newDeleteQueryBuilder()
67 ->deleteFrom(
'user_properties' )
68 ->where( [
'up_user' => $userIdsToClean ] );
70 $deleteQueryBuilder->where( [
'up_property' => $option ] );
72 $deleteQueryBuilder->caller( __METHOD__ )->execute();
75 $cleaned += count( $userIdsToClean );
76 $this->
output(
'Cleaned up user_properties for users up to ' . ( $min + $this->
getBatchSize() ) .
77 ' and ' . $cleaned .
" users have been cleared.\n" );