Last active
February 21, 2018 20:36
-
-
Save danielbachhuber/4a2f635c777df9538e8e98ba485a3fa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Strips out unnecessary testsuites data from PHPUnit test results | |
* | |
* Run with `wp eval-file cleanup-results-key.php` | |
*/ | |
global $wpdb; | |
$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type='result'" ); | |
foreach( $post_ids as $h => $post_id ) { | |
if ( $h && $h % 100 === 0 ) { | |
sleep(1); | |
} | |
WP_CLI::log( "Processing {$post_id}" ); | |
$results = get_post_meta( $post_id, 'results', true ); | |
// If 'testsuites' is already empty, we don't need to process' | |
if ( empty( $results['testsuites'] ) ) { | |
continue; | |
} | |
foreach( $results['testsuites'] as $i => $testsuite ) { | |
// If 'failures' and 'errors' are both empty for the testsuite, | |
// then we should drop this data from the array | |
if ( empty( $testsuite['failures'] ) && empty( $testsuite['errors'] ) ) { | |
unset( $results['testsuites'][ $i ] ); | |
} | |
} | |
// Normalize array keys | |
$results['testsuites'] = array_values( $results['testsuites'] ); | |
WP_CLI::log( 'Found ' . count( $results['testsuites'] ) . ' failures/errors remaining.' ); | |
// Hopefully this is a lot less data than what we started with | |
update_post_meta( $post_id, 'results', $results ); | |
} | |
WP_CLI::success( "All done!" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment