Skip to content

Commit 06e3eac

Browse files
Staging Sites: Add CLI commands to clear WPCOM Performance Profiler data after site cloning (#45318)
* Add function to clear performance profiler data after site clone * changelog * Update changelog * Only delete performance report URL if option exists * Remove trailing semicolon from SQL query in performance profiler data cleanup * Update SQL query * Improve error handling and logging for performance profiler data cleanup
1 parent b32e64a commit 06e3eac

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Staging Sites: Add CLI commands to clear WPCOM Performance Profiler data after site cloning

projects/plugins/wpcomsh/woa.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,51 @@ function wpcomsh_woa_post_clone_set_staging_environment_type( $args, $assoc_args
207207
}
208208
add_action( 'wpcomsh_woa_post_clone', 'wpcomsh_woa_post_clone_set_staging_environment_type', 10, 2 );
209209

210+
/**
211+
* Clear performance profiler data.
212+
*
213+
* @param array $args Arguments.
214+
* @param array $assoc_args Associated arguments.
215+
*/
216+
function wpcomsh_woa_post_clone_clear_performance_profiler_data( $args, $assoc_args ) {
217+
global $wpdb;
218+
219+
$clear_performance_profiler_data = WP_CLI\Utils\get_flag_value( $assoc_args, 'clear-performance-profiler-data', false );
220+
if ( ! $clear_performance_profiler_data ) {
221+
return;
222+
}
223+
224+
if ( get_option( 'wpcom_performance_report_url' ) ) {
225+
WP_CLI::log( 'Deleting performance profiler option' );
226+
$result = WP_CLI::runcommand(
227+
'option delete wpcom_performance_report_url',
228+
array(
229+
'launch' => false,
230+
'exit_error' => false,
231+
'return' => 'all',
232+
)
233+
);
234+
235+
if ( 0 === $result->return_code ) {
236+
WP_CLI::success( 'Performance profiler option deleted' );
237+
} else {
238+
WP_CLI::warning( 'Failed to delete performance profiler option: ' . $result->stderr );
239+
}
240+
}
241+
242+
WP_CLI::log( 'Deleting performance profiler postmeta (if they exist)' );
243+
$query = "DELETE FROM {$wpdb->postmeta} WHERE meta_key = '_wpcom_performance_report_url'";
244+
$command = sprintf( 'db query "%s"', $query );
245+
WP_CLI::runcommand(
246+
$command,
247+
array(
248+
'launch' => false,
249+
'exit_error' => false,
250+
)
251+
);
252+
}
253+
add_action( 'wpcomsh_woa_post_clone', 'wpcomsh_woa_post_clone_clear_performance_profiler_data', 10, 2 );
254+
210255
/**
211256
* Install marketplace software after a site transfer.
212257
*

0 commit comments

Comments
 (0)