Reset grossly inaccurate team hours to improve stats reliability.

See #125
This commit is contained in:
Ian Dunn 2019-12-13 14:34:54 -08:00
parent 3b97459b15
commit b68664c231
No known key found for this signature in database
GPG key ID: 99B971B50343CBCB

View file

@ -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 );
}