Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show a message when an indexing is stopped by the WP-CLI command #2549

Merged
merged 8 commits into from
Feb 3, 2022
16 changes: 9 additions & 7 deletions assets/js/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ function updateDisabledAttribute(element, value) {
function updateSyncDash() {
const progressBar = activeBox.querySelector('.ep-sync-box__progressbar_animated');

const progressBarWidth = (parseInt(processed, 10) / parseInt(toProcess, 10)) * 100;
const progressBarWidth =
toProcess === 0 ? 0 : (parseInt(processed, 10) / parseInt(toProcess, 10)) * 100;

if (
typeof progressBarWidth === 'number' &&
Expand All @@ -278,7 +279,7 @@ function updateSyncDash() {
progressBar.innerText = `${Math.trunc(width)}%`;
}

const isSyncing = ['initialsync', 'sync', 'pause', 'wpcli'].includes(syncStatus);
const isSyncing = ['initialsync', 'sync', 'pause', 'wpcli', 'interrupt'].includes(syncStatus);
if (isSyncing) {
progressBar.classList.remove('ep-sync-box__progressbar_complete');
} else {
Expand Down Expand Up @@ -308,17 +309,17 @@ function updateSyncDash() {
* Cancel a sync
*/
function cancelSync() {
toProcess = 0;
processed = 0;
totalProcessed = 0;

apiFetch({
url: ajaxurl,
method: 'POST',
body: new URLSearchParams({
action: 'ep_cancel_index',
nonce: epDash.nonce,
}),
}).then(() => {
toProcess = 0;
processed = 0;
totalProcessed = 0;
});
}

Expand Down Expand Up @@ -448,8 +449,9 @@ function updateStartDateTime(value) {
function shouldInterruptSync(value) {
if (value) {
syncStatus = 'interrupt';
updateSyncDash();
cancelSync();
updateSyncDash();
addLineToOutput(__('Sync interrupted by WP-CLI command', 'elasticpress'));
}
}

Expand Down
1 change: 1 addition & 0 deletions includes/classes/IndexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ protected function build_index_meta() {
Utils\update_option( 'ep_last_sync', time() );
Utils\delete_option( 'ep_need_upgrade_sync' );
Utils\delete_option( 'ep_feature_auto_activated_sync' );
delete_transient( 'ep_sync_interrupted' );

$start_date_time = date_create( 'now', wp_timezone() );

Expand Down