28require_once __DIR__ .
'/Maintenance.php';
44 parent::__construct();
45 $this->
addDescription(
'Clean up hidden preferences or removed preferences' );
47 $this->
addOption(
'dry-run',
'Print debug info instead of actually deleting' );
48 $this->
addOption(
'hidden',
'Drop hidden preferences ($wgHiddenPrefs)' );
50 'Drop unknown preferences (not in $wgDefaultUserOptions or prefixed with "userjs-")' );
66 if ( !$hidden && !$unknown ) {
67 $this->
output(
"Did not select one of --hidden, --unknown, exiting\n" );
73 $hiddenPrefs = $this->
getConfig()->get( MainConfigNames::HiddenPrefs );
74 if ( !$hiddenPrefs ) {
75 $this->
output(
"No hidden preferences, skipping\n" );
77 foreach ( $hiddenPrefs as $hiddenPref ) {
80 'Dropping hidden preferences',
81 [
'up_property' => $hiddenPref ]
88 $defaultUserOptions = $this->
getServiceContainer()->getUserOptionsLookup()->getDefaultOptions(
null );
90 $dbr->expr(
'up_property', IExpression::NOT_LIKE,
91 new LikeValue(
'userjs-', $dbr->anyString() ) ),
92 $dbr->expr(
'up_property', IExpression::NOT_LIKE,
93 new LikeValue( UserOptionsLookup::LOCAL_EXCEPTION_SUFFIX, $dbr->anyString() ) ),
94 $dbr->expr(
'up_property',
'!=', array_keys( $defaultUserOptions ) ),
97 $this->
getHookRunner()->onDeleteUnknownPreferences( $where, $dbr );
98 $this->deleteByWhere( $dbr,
'Dropping unknown preferences', $where );
102 private function deleteByWhere( $dbr, $startMessage, $where ) {
103 $this->
output( $startMessage .
"...\n" );
108 $dbr->newSelectQueryBuilder()
109 ->from(
'user_properties' )
111 [
'up_user',
'up_property',
'up_value' ] :
112 [
'up_user',
'up_property' ] )
114 ->caller( __METHOD__ ),
115 [
'up_user',
'up_property' ],
121 foreach ( $iterator as $batch ) {
122 $numRows = count( $batch );
125 $this->
output(
"..doing $numRows entries\n" );
129 foreach ( $batch as $row ) {
132 " DRY RUN, would drop: " .
133 "[up_user] => '{$row->up_user}' " .
134 "[up_property] => '{$row->up_property}' " .
135 "[up_value] => '{$row->up_value}'\n"
139 $deleteWhere[$row->up_user][$row->up_property] =
true;
141 if ( $deleteWhere && !$dryRun ) {
142 $dbw->newDeleteQueryBuilder()
143 ->deleteFrom(
'user_properties' )
144 ->where( $dbw->makeWhereFrom2d( $deleteWhere,
'up_user',
'up_property' ) )
145 ->caller( __METHOD__ )->execute();
150 $this->
output(
"DONE! (handled $total entries)\n" );
156require_once RUN_MAINTENANCE_IF_MAIN;
Allows iterating a large number of rows in batches transparently.
Maintenance script that removes unused preferences from the database.
__construct()
Default constructor.
execute()
We will do this in three passes 1) The easiest is to drop the hidden preferences from the database.
A class containing constants representing the names of configuration variables.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getHookRunner()
Get a HookRunner for running core hooks.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.