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

Store error logs for each import job #1038

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/feedzy-rss-feed-import.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
.feedzy_page_feedzy-integration .feedzy-header{
margin-bottom: 40px;
}
.feedzy-api-error,

.feedzy-error-critical {
color: #ff0000;
}
Expand Down
29 changes: 29 additions & 0 deletions feedzy-rss-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,35 @@ function feedzy_themeisle_log_event( $name, $msg, $type, $file, $line ) {
}
}

/**
* Store import job errors in metadata.
*
* @param string $name Name.
* @param string $msg Error message.
* @param string $type Error type.
*
* @return void
*/
function feedzy_import_job_logs( $name, $msg, $type ) {
if ( ! in_array( $type, apply_filters( 'feedzy_allowed_store_log_types', array( 'error' ) ), true ) ) {
return;
}
if ( ! wp_doing_ajax() || wp_doing_cron() ) {
return;
}
if ( apply_filters( 'feedzy_skip_store_error_logs', false ) ) {
return;
}
global $themeisle_log_event;

if ( ! empty( $themeisle_log_event ) && count( $themeisle_log_event ) >= 200 ) {
return;
}

$themeisle_log_event[] = $msg;
}
add_action( 'themeisle_log_event', 'feedzy_import_job_logs', 20, 3 );

add_filter( 'themeisle_sdk_enable_telemetry', '__return_true' );

add_filter(
Expand Down
59 changes: 44 additions & 15 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public function enqueue_styles() {
'action_btn_text_1' => __( 'Choose image', 'feedzy-rss-feeds' ),
'action_btn_text_2' => __( 'Replace image', 'feedzy-rss-feeds' ),
'author_helper' => __( 'If the author you are looking for isn\'t found, you can input the author username.', 'feedzy-rss-feeds' ),
'clearLogButton' => __( 'Clear Log', 'feedzy-rss-feeds' ),
'okButton' => __( 'Ok', 'feedzy-rss-feeds' ),
'removeErrorLogsMsg' => __( 'Removed all error logs.', 'feedzy-rss-feeds' ),
),
)
);
Expand Down Expand Up @@ -893,7 +896,7 @@ private function get_last_run_details( $post_id ) {
$errors = $this->get_import_errors( $post_id );
// popup for errors found.
if ( ! empty( $errors ) ) {
$msg .= '<div class="feedzy-errors-found-' . $post_id . ' feedzy-dialog" title="' . __( 'Errors', 'feedzy-rss-feeds' ) . '">' . $errors . '</div>';
$msg .= '<div class="feedzy-errors-found-' . $post_id . ' feedzy-errors-dialog" title="' . __( 'Errors', 'feedzy-rss-feeds' ) . '" data-id="' . $post_id . '">' . $errors . '</div>';
}

// remember, cypress will work off the data-value attributes.
Expand Down Expand Up @@ -1096,23 +1099,28 @@ public function ajax() {
case 'remove_upsell_notice':
$this->remove_import_upsell();
break;
case 'clear_error_logs':
$this->clear_error_logs();
break;
}
}

/**
* AJAX called method to remove import upsell notice.
*
* @since 3.4.1
* @access public
*/
public function remove_import_upsell() {
if ( ! is_user_logged_in() ) {
return;
}
$user_id = get_current_user_id();
update_user_meta( $user_id, 'feedzy_import_upsell_notice', 'dismissed' );

wp_send_json_success();
}
/**
* AJAX called method to remove import upsell notice.
*
* @since 3.4.1
* @access public
*/
public function remove_import_upsell() {
if ( ! is_user_logged_in() ) {
return;
}
$user_id = get_current_user_id();
update_user_meta( $user_id, 'feedzy_import_upsell_notice', 'dismissed' );

wp_send_json_success();
}
/**
* AJAX called method to update post status.
*
Expand Down Expand Up @@ -1361,6 +1369,7 @@ public function run_cron( $max = 100, $job_id = 0 ) {
* @access private
*/
private function run_job( $job, $max ) {
global $themeisle_log_event;
$source = get_post_meta( $job->ID, 'source', true );
$inc_key = get_post_meta( $job->ID, 'inc_key', true );
$exc_key = get_post_meta( $job->ID, 'exc_key', true );
Expand Down Expand Up @@ -2101,6 +2110,10 @@ function( $term ) {
$count
);
}

if ( ! empty( $themeisle_log_event ) ) {
$import_errors = array_merge( $themeisle_log_event, $import_errors );
}
update_post_meta( $job->ID, 'import_errors', $import_errors );

// the order of these matters in how they are finally shown in the summary.
Expand Down Expand Up @@ -3313,4 +3326,20 @@ public function get_actions_runner( $actions = '', $type = '' ) {
$action_instance->set_settings( $this->settings );
return $action_instance;
}

/**
* Clear error logs.
*/
private function clear_error_logs() {
check_ajax_referer( FEEDZY_BASEFILE, 'security' );
$id = ! empty( $_POST['id'] ) ? (int) $_POST['id'] : 0;
if ( $id ) {
delete_post_meta( $id, 'import_errors' );
}
wp_send_json(
array(
'status' => 1,
)
);
}
}
9 changes: 8 additions & 1 deletion includes/views/css/import-metabox-edit.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,11 @@ span.feedzy-spinner {

#TB_ajaxContent div.dry_run span i.fail {
color: #ca4a1f;
}
}

.feedzy-errors-dialog + .ui-widget-content .ui-dialog-buttonset {
width: 100%;
}
.feedzy-errors-dialog + .ui-widget-content button.feedzy-clear-logs {
margin-left: 0;
}
56 changes: 52 additions & 4 deletions includes/views/js/import-metabox-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,59 @@
"ui-dialog-content": "feedzy-dialog-content",
},
width: 500,
buttons: {
Ok: function () {
$(this).dialog("close");
buttons:[
{
text: feedzy.i10n.okButton,
click: function () {
$(this).dialog('close');
}
}
]
});

// Error logs popup.
$(".feedzy-errors-dialog").dialog({
modal: true,
autoOpen: false,
height: 400,
width: 500,
buttons:[
{
text: feedzy.i10n.clearLogButton,
class: 'button button-primary feedzy-clear-logs',
click: function (event) {
var clearButton = $(event.target);
var dialogBox = $(this);
$('<span class="feedzy-spinner spinner is-active"></span>').insertAfter(clearButton);
clearButton.attr('disabled', true);
$.post(
ajaxurl,
{
security: feedzy.ajax.security,
id: $(this).attr('data-id'),
action: 'feedzy',
_action: 'clear_error_logs',
},
function () {
clearButton
.next('.feedzy-spinner')
.remove();

dialogBox
.find('.feedzy-error.feedzy-api-error')
.html('<div class="notice notice-success"><p>' + feedzy.i10n.removeErrorLogsMsg + '</p></div>')
}
);
}
},
},
{
text: feedzy.i10n.okButton,
class: 'alignright',
click: function () {
$(this).dialog('close');
}
}
]
});

$(".feedzy-dialog-open").on("click", function (e) {
Expand Down
Loading