Skip to content

Commit

Permalink
PLUGINS-6943 - added log saving for import fails
Browse files Browse the repository at this point in the history
  • Loading branch information
meteor-ec committed Nov 5, 2024
1 parent f571311 commit 59b28af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
19 changes: 19 additions & 0 deletions includes/importer/class-ecwid-import-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Ecwid_Import_Page {
const AJAX_ACTION_CHECK_IMPORT = 'ec-store-check-import';
const AJAX_ACTION_DO_WOO_IMPORT = 'ec-store-do-woo-import';
const ACTION_GET_WOO_IMPORT_LOG = 'ec-store-get-woo-import-log';
const AJAX_ACTION_SEND_ERROR_TO_LOGS = 'ec-store-send-error-to-logs';

const PARAM_FROM_IMPORT_ONBOARDING = 'from-woo-import-message';

Expand All @@ -22,6 +23,8 @@ public function init_actions() {
add_action( 'wp_ajax_' . self::AJAX_ACTION_DO_WOO_IMPORT, array( $this, 'do_woo_import' ) );
add_action( 'current_screen', array( $this, 'do_reconnect' ) );
add_action( 'admin_post_' . self::ACTION_GET_WOO_IMPORT_LOG, array( $this, 'get_woo_import_log' ) );

add_action( 'wp_ajax_' . self::AJAX_ACTION_SEND_ERROR_TO_LOGS, array( $this, 'send_error_to_logs' ) );
}

public function process_woo_onboarding_redirect() {
Expand Down Expand Up @@ -65,6 +68,7 @@ public function enqueue_scripts() {
array(
'check_token_action' => self::AJAX_ACTION_CHECK_IMPORT,
'do_woo_import_action' => self::AJAX_ACTION_DO_WOO_IMPORT,
'send_error_to_logs' => self::AJAX_ACTION_SEND_ERROR_TO_LOGS,
'_ajax_nonce' => wp_create_nonce( self::AJAX_ACTION_DO_WOO_IMPORT ),
)
);
Expand Down Expand Up @@ -121,6 +125,21 @@ public function do_woo_import() {
die();
}

public function send_error_to_logs() {
check_ajax_referer( self::AJAX_ACTION_DO_WOO_IMPORT );

if ( ! current_user_can( 'manage_options' ) ) {
die();
}

$importer = new Ecwid_Importer();
$result = $importer->send_import_error_to_logs();

echo json_encode( $result );

die();
}

protected function _get_billing_page_url() {
return 'admin.php?page=' . Ecwid_Admin::ADMIN_SLUG . '&ec-page=billing';
}
Expand Down
8 changes: 7 additions & 1 deletion includes/importer/class-ecwid-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public function tick() {
return $progress;
}


public function append_batch( $batch_item ) {
$this->_batch[] = $batch_item;

Expand Down Expand Up @@ -299,6 +298,13 @@ public function send_import_mark_to_log() {
return $api->get_store_update_stats( $params );
}

public function send_import_error_to_logs() {
$api = new Ecwid_Api_V3();
$params = array( 'wp_import_woo_fail' => get_ecwid_store_id() );

return $api->get_store_update_stats( $params );
}

public static function is_localhost() {

if ( get_option( self::OPTIONS_SEPARATE_IMAGE_LOADING, false ) ) {
Expand Down
15 changes: 15 additions & 0 deletions js/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,29 @@ jQuery(document).ready(function () {

if (status.planLimitHit) {
showWooImportAlert('limit');
send_mark_to_logs('limit');
} else if (Object.keys(status.error).length > 0 || Object.keys(status.errorMessages).length > 0) {
showWooImportAlert('warning');
send_mark_to_logs();
} else {
showWooImportAlert('success');
}

switchWooImportState('complete');
}

send_mark_to_logs = function (reason = null) {
var data = {
'action': ecwid_importer.send_error_to_logs,
'_ajax_nonce': ecwid_importer._ajax_nonce,
settings: settings
};

jQuery.ajax({
'url': ajaxurl,
'data': data
});
};
};

jQuery('#ec-importer-woo-go').on('click', function () {
Expand Down

0 comments on commit 59b28af

Please sign in to comment.