Commit 55552325 authored by Erick Hitter's avatar Erick Hitter
Browse files

PHPCS fixes

parent 5a55b18a
<?php <?php
/**
* Clean up plugin data via WP-CLI
*
* @package a8c_Cron_Control
*/
namespace Automattic\WP\Cron_Control\CLI; namespace Automattic\WP\Cron_Control\CLI;
...@@ -11,6 +16,8 @@ class One_Time_Fixers extends \WP_CLI_Command { ...@@ -11,6 +16,8 @@ class One_Time_Fixers extends \WP_CLI_Command {
* *
* @subcommand remove-all-plugin-data * @subcommand remove-all-plugin-data
* @synopsis [--dry-run=<dry-run>] * @synopsis [--dry-run=<dry-run>]
* @param array $args Array of positional arguments.
* @param array $assoc_args Array of flags.
*/ */
public function purge( $args, $assoc_args ) { public function purge( $args, $assoc_args ) {
global $wpdb; global $wpdb;
...@@ -22,11 +29,11 @@ class One_Time_Fixers extends \WP_CLI_Command { ...@@ -22,11 +29,11 @@ class One_Time_Fixers extends \WP_CLI_Command {
$dry_run = false; $dry_run = false;
} }
// Provide some idea of what's going on // Provide some idea of what's going on.
\WP_CLI::log( __( 'CRON CONTROL', 'automattic-cron-control' ) . "\n" ); \WP_CLI::log( __( 'CRON CONTROL', 'automattic-cron-control' ) . "\n" );
$table_name = \Automattic\WP\Cron_Control\Events_Store::instance()->get_table_name(); $table_name = \Automattic\WP\Cron_Control\Events_Store::instance()->get_table_name();
$count = (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$table_name}" ); $count = (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$table_name}" ); // Cannot prepare table name. @codingStandardsIgnoreLine
if ( $count > 1 ) { if ( $count > 1 ) {
\WP_CLI::log( sprintf( __( 'Found %s total items', 'automattic-cron-control' ), number_format_i18n( $count ) ) . "\n\n" ); \WP_CLI::log( sprintf( __( 'Found %s total items', 'automattic-cron-control' ), number_format_i18n( $count ) ) . "\n\n" );
...@@ -45,24 +52,24 @@ class One_Time_Fixers extends \WP_CLI_Command { ...@@ -45,24 +52,24 @@ class One_Time_Fixers extends \WP_CLI_Command {
\WP_CLI::log( "\n" . __( 'Starting...', 'automattic-cron-control' ) . "\n" ); \WP_CLI::log( "\n" . __( 'Starting...', 'automattic-cron-control' ) . "\n" );
} }
// Don't create new events while deleting events // Don't create new events while deleting events.
\Automattic\WP\Cron_Control\_suspend_event_creation(); \Automattic\WP\Cron_Control\_suspend_event_creation();
// Don't truncate as it requires DROP and resets auto-increment value // Don't truncate as it requires DROP and resets auto-increment value.
if ( ! $dry_run ) { if ( ! $dry_run ) {
$wpdb->query( "DELETE FROM {$table_name}" ); $wpdb->query( "DELETE FROM {$table_name}" ); // Cannot prepare table name. @codingStandardsIgnoreLine
} }
// Remove the now-stale cache when actively run // Remove the now-stale cache when actively run.
if ( ! $dry_run ) { if ( ! $dry_run ) {
\Automattic\WP\Cron_Control\_flush_internal_caches(); \Automattic\WP\Cron_Control\_flush_internal_caches();
\WP_CLI::log( "\n" . sprintf( __( 'Cleared the %s cache', 'automattic-cron-control' ), 'Cron Control' ) ); \WP_CLI::log( "\n" . sprintf( __( 'Cleared the %s cache', 'automattic-cron-control' ), 'Cron Control' ) );
} }
// Let event creation resume // Let event creation resume.
\Automattic\WP\Cron_Control\_resume_event_creation(); \Automattic\WP\Cron_Control\_resume_event_creation();
// Fin // Fin.
\WP_CLI::success( __( 'All done.', 'automattic-cron-control' ) ); \WP_CLI::success( __( 'All done.', 'automattic-cron-control' ) );
} }
...@@ -71,6 +78,8 @@ class One_Time_Fixers extends \WP_CLI_Command { ...@@ -71,6 +78,8 @@ class One_Time_Fixers extends \WP_CLI_Command {
* *
* @subcommand purge-legacy-cpt-entries * @subcommand purge-legacy-cpt-entries
* @synopsis [--batch-size=<batch-size>] [--dry-run=<dry-run>] * @synopsis [--batch-size=<batch-size>] [--dry-run=<dry-run>]
* @param array $args Array of positional arguments.
* @param array $assoc_args Array of flags.
*/ */
public function purge_cpt( $args, $assoc_args ) { public function purge_cpt( $args, $assoc_args ) {
global $wpdb; global $wpdb;
...@@ -82,13 +91,13 @@ class One_Time_Fixers extends \WP_CLI_Command { ...@@ -82,13 +91,13 @@ class One_Time_Fixers extends \WP_CLI_Command {
$dry_run = false; $dry_run = false;
} }
// Provide some idea of what's going on // Provide some idea of what's going on.
\WP_CLI::log( __( 'CRON CONTROL', 'automattic-cron-control' ) . "\n" ); \WP_CLI::log( __( 'CRON CONTROL', 'automattic-cron-control' ) . "\n" );
$count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = %s;", 'a8c_cron_ctrl_event' ) ); $count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = %s;", 'a8c_cron_ctrl_event' ) );
if ( $count > 1 ) { if ( $count > 0 ) {
\WP_CLI::log( sprintf( __( 'Found %s total items', 'automattic-cron-control' ), number_format_i18n( $count ) ) . "\n\n" ); \WP_CLI::log( sprintf( _n( 'Found %s item', 'Found %s total items', $count, 'automattic-cron-control' ), number_format_i18n( $count ) ) . "\n\n" );
\WP_CLI::confirm( __( 'Proceed?', 'automattic-cron-control' ) ); \WP_CLI::confirm( __( 'Proceed?', 'automattic-cron-control' ) );
} else { } else {
\WP_CLI::error( __( 'No entries found...aborting!', 'automattic-cron-control' ) ); \WP_CLI::error( __( 'No entries found...aborting!', 'automattic-cron-control' ) );
...@@ -101,7 +110,7 @@ class One_Time_Fixers extends \WP_CLI_Command { ...@@ -101,7 +110,7 @@ class One_Time_Fixers extends \WP_CLI_Command {
\WP_CLI::log( "\n" . __( 'Starting...', 'automattic-cron-control' ) . "\n" ); \WP_CLI::log( "\n" . __( 'Starting...', 'automattic-cron-control' ) . "\n" );
} }
// Determine how many batches this will take // Determine how many batches this will take.
if ( isset( $assoc_args['batch-size'] ) ) { if ( isset( $assoc_args['batch-size'] ) ) {
$page_size = max( 1, min( absint( $assoc_args['batch-size'] ), 500 ) ); $page_size = max( 1, min( absint( $assoc_args['batch-size'] ), 500 ) );
} else { } else {
...@@ -116,13 +125,13 @@ class One_Time_Fixers extends \WP_CLI_Command { ...@@ -116,13 +125,13 @@ class One_Time_Fixers extends \WP_CLI_Command {
$pages = ceil( $count / $page_size ); $pages = ceil( $count / $page_size );
} }
// Let's get on with it // Let's get on with it.
do { do {
\WP_CLI::log( "\n\n" . sprintf( __( 'Processing page %1$s of %2$s', 'automattic-cron-control' ), number_format_i18n( $page ), number_format_i18n( $pages ) ) . "\n" ); \WP_CLI::log( "\n\n" . sprintf( __( 'Processing page %1$s of %2$s', 'automattic-cron-control' ), number_format_i18n( $page ), number_format_i18n( $pages ) ) . "\n" );
$items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = %s LIMIT %d,%d", 'a8c_cron_ctrl_event', absint( ( $page - 1 ) * $page_size ),$page_size ) ); $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = %s LIMIT %d,%d", 'a8c_cron_ctrl_event', absint( ( $page - 1 ) * $page_size ),$page_size ) );
// Nothing more to do // Nothing more to do.
if ( ! is_array( $items ) || empty( $items ) ) { if ( ! is_array( $items ) || empty( $items ) ) {
\WP_CLI::log( __( 'No more items found!', 'automattic-cron-control' ) ); \WP_CLI::log( __( 'No more items found!', 'automattic-cron-control' ) );
break; break;
...@@ -138,24 +147,24 @@ class One_Time_Fixers extends \WP_CLI_Command { ...@@ -138,24 +147,24 @@ class One_Time_Fixers extends \WP_CLI_Command {
} }
} }
// Some cleanup // Some cleanup.
unset( $items ); unset( $items );
stop_the_insanity(); stop_the_insanity();
// Prepare for the next batch // Prepare for the next batch.
$page++; $page++;
if ( $page > $pages ) { if ( $page > $pages ) {
break; break;
} }
// Don't rush into the next batch, unless we haven't done anything // Don't rush into the next batch, unless we haven't done anything.
if ( ! $dry_run ) { if ( ! $dry_run ) {
sleep( 5 ); sleep( 5 );
} }
} while( true ); } while ( true );
// Fin // Fin.
\WP_CLI::success( __( 'All done.', 'automattic-cron-control' ) ); \WP_CLI::success( __( 'All done.', 'automattic-cron-control' ) );
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment