From b68664c231016733db4ac55d855814a1878b5319 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Fri, 13 Dec 2019 14:34:54 -0800 Subject: [PATCH] Reset grossly inaccurate team hours to improve stats reliability. See #125 --- bin/modify-profile-data.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bin/modify-profile-data.php b/bin/modify-profile-data.php index fc55035..4cbfc9a 100644 --- a/bin/modify-profile-data.php +++ b/bin/modify-profile-data.php @@ -26,10 +26,11 @@ function main( $file, $args ) { WP_CLI::line(); WP_CLI::confirm( - "Be very careful when using this, as it will modify production data. It should only be run manually after careful review of the code. Take a backup of the db table before running this, in case anything goes wrong. Proceed?" + "Be very careful when using this, as it will modify production data. It should only be run manually after careful review of the code. When adding new code, try to make it idempotent so this can be safely re-run. Take a backup of the db table before running this, in case anything goes wrong. Proceed?" ); update_chosen_teams(); + update_inaccurate_hours(); WP_CLI::success( 'Done. Please manually check everything to make sure it worked correctly.' ); } @@ -102,3 +103,27 @@ function update_chosen_teams() { } } } + +/** + * Remove invalid hours values, now that they're prevented from being entered. + * + * @see https://github.com/WordPress/five-for-the-future/issues/125 + */ +function update_inaccurate_hours() { + global $wpdb; + + $query = $wpdb->prepare( " + UPDATE `bpmain_bp_xprofile_data` + SET value = 0 + WHERE + field_id = %d AND + ( + value > 60 OR + value REGEXP '[a-zA-Z]' + ) + ", + XProfile\FIELD_IDS['hours_per_week'] + ); + + $wpdb->query( $query ); +}