41 parent::__construct();
42 $this->
addDescription(
'Clean up hidden preferences or removed preferences' );
44 $this->
addOption(
'dry-run',
'Print debug info instead of actually deleting' );
45 $this->
addOption(
'hidden',
'Drop hidden preferences ($wgHiddenPrefs)' );
47 'Drop unknown preferences (not in $wgDefaultUserOptions or prefixed with "userjs-")' );
63 if ( !$hidden && !$unknown ) {
64 $this->
output(
"Did not select one of --hidden, --unknown, exiting\n" );
70 $hiddenPrefs = $this->
getConfig()->get( MainConfigNames::HiddenPrefs );
71 if ( !$hiddenPrefs ) {
72 $this->
output(
"No hidden preferences, skipping\n" );
74 foreach ( $hiddenPrefs as $hiddenPref ) {
77 'Dropping hidden preferences',
78 [
'up_property' => $hiddenPref ]
85 $defaultUserOptions = $this->
getServiceContainer()->getUserOptionsLookup()->getDefaultOptions(
null );
87 $dbr->expr(
'up_property', IExpression::NOT_LIKE,
88 new LikeValue(
'userjs-', $dbr->anyString() ) ),
89 $dbr->expr(
'up_property', IExpression::NOT_LIKE,
90 new LikeValue( UserOptionsLookup::LOCAL_EXCEPTION_SUFFIX, $dbr->anyString() ) ),
91 $dbr->expr(
'up_property',
'!=', array_keys( $defaultUserOptions ) ),
94 $this->
getHookRunner()->onDeleteUnknownPreferences( $where, $dbr );
95 $this->deleteByWhere( $dbr,
'Dropping unknown preferences', $where );
99 private function deleteByWhere( $dbr, $startMessage, $where ) {
100 $this->
output( $startMessage .
"...\n" );
106 [
'up_user',
'up_property' ],
110 $iterator->setFetchColumns( [
'up_user',
'up_property',
'up_value' ] );
112 $iterator->setFetchColumns( [
'up_user',
'up_property' ] );
114 $iterator->addConditions( $where );
115 $iterator->setCaller( __METHOD__ );
119 foreach ( $iterator as $batch ) {
120 $numRows = count( $batch );
123 $this->
output(
"..doing $numRows entries\n" );
127 foreach ( $batch as $row ) {
130 " DRY RUN, would drop: " .
131 "[up_user] => '{$row->up_user}' " .
132 "[up_property] => '{$row->up_property}' " .
133 "[up_value] => '{$row->up_value}'\n"
137 $deleteWhere[$row->up_user][$row->up_property] =
true;
139 if ( $deleteWhere && !$dryRun ) {
140 $dbw->newDeleteQueryBuilder()
141 ->deleteFrom(
'user_properties' )
142 ->where( $dbw->makeWhereFrom2d( $deleteWhere,
'up_user',
'up_property' ) )
143 ->caller( __METHOD__ )->execute();
148 $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.