40 parent::__construct();
41 $this->
addDescription(
'Clean up hidden preferences or removed preferences' );
43 $this->
addOption(
'dry-run',
'Print debug info instead of actually deleting' );
44 $this->
addOption(
'hidden',
'Drop hidden preferences ($wgHiddenPrefs)' );
46 'Drop unknown preferences (not in $wgDefaultUserOptions or prefixed with "userjs-")' );
62 if ( !$hidden && !$unknown ) {
63 $this->
output(
"Did not select one of --hidden, --unknown, exiting\n" );
69 $hiddenPrefs = $this->
getConfig()->get( MainConfigNames::HiddenPrefs );
70 if ( !$hiddenPrefs ) {
71 $this->
output(
"No hidden preferences, skipping\n" );
73 foreach ( $hiddenPrefs as $hiddenPref ) {
76 'Dropping hidden preferences',
77 [
'up_property' => $hiddenPref ]
84 $defaultUserOptions = $this->
getServiceContainer()->getUserOptionsLookup()->getDefaultOptions(
null );
86 $dbr->expr(
'up_property', IExpression::NOT_LIKE,
new LikeValue(
'userjs-', $dbr->anyString() ) ),
87 $dbr->expr(
'up_property',
'!=', array_keys( $defaultUserOptions ) ),
90 $this->
getHookRunner()->onDeleteUnknownPreferences( $where, $dbr );
91 $this->deleteByWhere( $dbr,
'Dropping unknown preferences', $where );
95 private function deleteByWhere( $dbr, $startMessage, $where ) {
96 $this->
output( $startMessage .
"...\n" );
102 [
'up_user',
'up_property' ],
106 $iterator->setFetchColumns( [
'up_user',
'up_property',
'up_value' ] );
108 $iterator->setFetchColumns( [
'up_user',
'up_property' ] );
110 $iterator->addConditions( $where );
111 $iterator->setCaller( __METHOD__ );
115 foreach ( $iterator as $batch ) {
116 $numRows = count( $batch );
119 $this->
output(
"..doing $numRows entries\n" );
123 foreach ( $batch as $row ) {
126 " DRY RUN, would drop: " .
127 "[up_user] => '{$row->up_user}' " .
128 "[up_property] => '{$row->up_property}' " .
129 "[up_value] => '{$row->up_value}'\n"
133 $deleteWhere[$row->up_user][$row->up_property] =
true;
135 if ( $deleteWhere && !$dryRun ) {
136 $dbw->newDeleteQueryBuilder()
137 ->deleteFrom(
'user_properties' )
138 ->where( $dbw->makeWhereFrom2d( $deleteWhere,
'up_user',
'up_property' ) )
139 ->caller( __METHOD__ )->execute();
144 $this->
output(
"DONE! (handled $total entries)\n" );
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getHookRunner()
Get a HookRunner for running core hooks.
waitForReplication()
Wait for replica DBs to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.