Skip to content

Commit

Permalink
Merge pull request #2204 from Automattic/update/using_versions_safer
Browse files Browse the repository at this point in the history
Adds confirm message
  • Loading branch information
pschoffer committed Jun 11, 2021
2 parents 1eda744 + b0a3677 commit 9de6cd0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions search/includes/classes/commands/class-corecommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private function _shift_version_after_index( $assoc_args ) {
$search = \Automattic\VIP\Search\Search::instance();

$indexables = $this->_parse_indexables( $assoc_args );
$skip_confirm = isset( $assoc_args['skip-confirm'] ) && $assoc_args['skip-confirm'];

foreach ( $indexables as $indexable ) {
WP_CLI::line( sprintf( 'Updating active version for "%s"', $indexable->slug ) );
Expand All @@ -45,6 +46,10 @@ private function _shift_version_after_index( $assoc_args ) {
WP_CLI::error( sprintf( 'Error activating next version: %s', $result->get_error_message() ) );
}

if ( ! $skip_confirm ) {
WP_CLI::confirm( '⚠️ You are about to remove a previously used index version. It is advised to verify that the new version is being used before continuing. Continue?' );
}

WP_CLI::line( sprintf( 'Removing inactive version for "%s"', $indexable->slug ) );
$result = $search->versioning->delete_version( $indexable, 'previous' );
if ( is_wp_error( $result ) ) {
Expand Down Expand Up @@ -141,6 +146,7 @@ public function index( $args, $assoc_args ) {
$this->_verify_arguments_compatibility( $assoc_args );

$using_versions = $assoc_args['using-versions'] ?? false;
$skip_confirm = isset( $assoc_args['skip-confirm'] ) && $assoc_args['skip-confirm'];

$this->_maybe_setup_index_version( $assoc_args );

Expand Down Expand Up @@ -184,6 +190,8 @@ public function index( $args, $assoc_args ) {
}

if ( $using_versions ) {
// resetting skip-confirm after it was cleared for elasticpress
$assoc_args['skip-confirm'] = $skip_confirm;
$this->_shift_version_after_index( $assoc_args );
}
}
Expand Down

0 comments on commit 9de6cd0

Please sign in to comment.