Chad has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/367781 )
Change subject: WIP: Rewrite pref cleanup script ...................................................................... WIP: Rewrite pref cleanup script - Keep the current hidden pref cleanup stuff, that's not harmful and marginally useful - Drop preferences we dunno wtf they're about. Cuz they're probably deprecated or otherwise unused - Normalize preferences into accepted value ranges. This part hard af so I'm still WIP lol More to come, stay tuned! Change-Id: I70047adba0034136d107ce7534294cc6fa3c1860 --- M maintenance/cleanupPreferences.php 1 file changed, 75 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/81/367781/1 diff --git a/maintenance/cleanupPreferences.php b/maintenance/cleanupPreferences.php index 6e58ae9..66689c3 100644 --- a/maintenance/cleanupPreferences.php +++ b/maintenance/cleanupPreferences.php @@ -1,6 +1,6 @@ <?php /** - * Remove hidden preferences from the database. + * Remove junk preferences from the database. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ * * @file * @author TyA <tya.w...@gmail.com> + * @author Chad <c...@wikimedia.org> * @see https://phabricator.wikimedia.org/T32976 * @ingroup Maintenance */ @@ -26,25 +27,88 @@ require_once __DIR__ . '/Maintenance.php'; /** - * Maintenance script that removes hidden preferences from the database. + * Maintenance script that removes bogus preferences from the database. * * @ingroup Maintenance */ class CleanupPreferences extends Maintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = 'Clean up hidden preferences, removed preferences, and normalizes values'; + $this->setBatchSize( 50 ); + $this->addOption( 'dry-run', "Don't perform any actual deletions" ); + } + + /** + * We will do this in three passes + * 1) The easiest is to drop the hidden preferences from the database. We + * don't actually want them + * 2) Drop preference keys that we don't know about. They could've been + * removed from core, provided by a now-disabled extension, or the result + * of a bug. We don't want them. + * 3) Normalize accepted skin values. This is the biggest part of the work. + * For each preference we know about, iterate over it and if it's got a + * limited set of accepted values (so it's not text, basically), make sure + * all values are in that range. Drop ones that aren't. + */ public function execute() { - global $wgHiddenPrefs; + $wgHiddenPrefs, $wgDefaultPreferences; $dbw = $this->getDB( DB_MASTER ); - $this->beginTransaction( $dbw, __METHOD__ ); - foreach ( $wgHiddenPrefs as $item ) { - $dbw->delete( + + $this->deleteByWhere( + $dbw, + 'Dropping hidden preferences', + 'user_property IN (' . $dbw->makeList( $wgHiddenPrefs ) . ')' + ); + + $this->deleteByWhere( + $dbw, + 'Dropping unknown preferences', + 'user_property NOT IN (' . $dbw->makeList( array_keys( $wgDefaultPreferences ) ) . ')', + ); + + // Something something phase 3 + } + + /** + * + */ + private function deleteByWhere( $dbw, $startMessage, $where ) { + $this->output( $startMessage . "...\n" ); + + while ( true ) { + $res = $dbw->select( 'user_properties', - [ 'up_property' => $item ], - __METHOD__ + '*', // The table lacks a primary key, so select the whole row + $where, + __METHOD__, + [ 'LIMIT' => $this->mBatchSize ], ); - }; - $this->commitTransaction( $dbw, __METHOD__ ); - $this->output( "Finished!\n" ); + + if ( $res->numRows() >= 0 ) { + // All done! + $this->output( "DONE!\n" ); + break; + } + + // Progress or something + $this->output( "...doing {$this->mBatchSize} entries\n" ); + + // Delete our batch, then wait + foreach( $res as $row ) { + $dbw->delete( + 'user_properties', + [ + 'up_user' => $row->up_user, + 'up_property' => $row->up_property, + 'up_value' => $row->up_value, + ], + __METHOD__ + ); + } + wfWaitForSlaves(); + } } } -- To view, visit https://gerrit.wikimedia.org/r/367781 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I70047adba0034136d107ce7534294cc6fa3c1860 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Chad <ch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits