38 parent::__construct();
39 $this->
addDescription(
'Clean up hidden preferences or removed preferences' );
41 $this->
addOption(
'dry-run',
'Print debug info instead of actually deleting' );
42 $this->
addOption(
'hidden',
'Drop hidden preferences ($wgHiddenPrefs)' );
44 'Drop unknown preferences (not in $wgDefaultUserOptions or prefixed with "userjs-")' );
60 if ( !$hidden && !$unknown ) {
61 $this->
output(
"Did not select one of --hidden, --unknown, exiting\n" );
67 $hiddenPrefs = $this->
getConfig()->get( MainConfigNames::HiddenPrefs );
68 if ( !$hiddenPrefs ) {
69 $this->
output(
"No hidden preferences, skipping\n" );
71 foreach ( $hiddenPrefs as $hiddenPref ) {
74 'Dropping hidden preferences',
75 [
'up_property' => $hiddenPref ]
82 $defaultUserOptions = $this->
getServiceContainer()->getUserOptionsLookup()->getDefaultOptions();
84 'up_property NOT' . $dbr->buildLike(
'userjs-', $dbr->anyString() ),
85 'up_property NOT IN (' . $dbr->makeList( array_keys( $defaultUserOptions ) ) .
')',
88 $this->
getHookRunner()->onDeleteUnknownPreferences( $where, $dbr );
89 $this->deleteByWhere( $dbr,
'Dropping unknown preferences', $where );
93 private function deleteByWhere( $dbr, $startMessage, $where ) {
94 $this->
output( $startMessage .
"...\n" );
100 [
'up_user',
'up_property' ],
104 $iterator->setFetchColumns( [
'up_user',
'up_property',
'up_value' ] );
106 $iterator->setFetchColumns( [
'up_user',
'up_property' ] );
108 $iterator->addConditions( $where );
109 $iterator->setCaller( __METHOD__ );
113 foreach ( $iterator as $batch ) {
114 $numRows = count( $batch );
117 $this->
output(
"..doing $numRows entries\n" );
121 foreach ( $batch as $row ) {
124 " DRY RUN, would drop: " .
125 "[up_user] => '{$row->up_user}' " .
126 "[up_property] => '{$row->up_property}' " .
127 "[up_value] => '{$row->up_value}'\n"
131 $deleteWhere[$row->up_user][$row->up_property] =
true;
133 if ( $deleteWhere && !$dryRun ) {
136 $dbw->makeWhereFrom2d( $deleteWhere,
'up_user',
'up_property' ),
143 $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.