Skip to content

Commit ff40015

Browse files
feat: store error logs for each import job
1 parent cbb5f3b commit ff40015

File tree

4 files changed

+130
-19
lines changed

4 files changed

+130
-19
lines changed

feedzy-rss-feed.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,30 @@ function feedzy_themeisle_log_event( $name, $msg, $type, $file, $line ) {
245245
}
246246
}
247247

248+
/**
249+
* Store import job errors in metadata.
250+
*
251+
* @param string $name Name.
252+
* @param string $msg Error message.
253+
* @param string $type Error type.
254+
*
255+
* @return void
256+
*/
257+
function feedzy_import_job_logs( $name, $msg, $type ) {
258+
if ( ! in_array( $type, apply_filters( 'feedzy_allowed_store_log_types', array( 'error' ) ), true ) ) {
259+
return;
260+
}
261+
if ( ! wp_doing_ajax() || wp_doing_cron() ) {
262+
return;
263+
}
264+
if ( apply_filters( 'feedzy_skip_store_error_logs', false ) ) {
265+
return;
266+
}
267+
global $themeisle_log_event;
268+
$themeisle_log_event[] = $msg;
269+
}
270+
add_action( 'themeisle_log_event', 'feedzy_import_job_logs', 20, 3 );
271+
248272
add_filter( 'themeisle_sdk_enable_telemetry', '__return_true' );
249273

250274
add_filter(

includes/admin/feedzy-rss-feeds-import.php

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ public function enqueue_styles() {
162162
'action_btn_text_1' => __( 'Choose image', 'feedzy-rss-feeds' ),
163163
'action_btn_text_2' => __( 'Replace image', 'feedzy-rss-feeds' ),
164164
'author_helper' => __( 'If the author you are looking for isn\'t found, you can input the author username.', 'feedzy-rss-feeds' ),
165+
'clearLogButton' => __( 'Clear Log', 'feedzy-rss-feeds' ),
166+
'okButton' => __( 'Ok', 'feedzy-rss-feeds' ),
167+
'removeErrorLogsMsg' => __( 'Removed all error logs.', 'feedzy-rss-feeds' ),
165168
),
166169
)
167170
);
@@ -893,7 +896,7 @@ private function get_last_run_details( $post_id ) {
893896
$errors = $this->get_import_errors( $post_id );
894897
// popup for errors found.
895898
if ( ! empty( $errors ) ) {
896-
$msg .= '<div class="feedzy-errors-found-' . $post_id . ' feedzy-dialog" title="' . __( 'Errors', 'feedzy-rss-feeds' ) . '">' . $errors . '</div>';
899+
$msg .= '<div class="feedzy-errors-found-' . $post_id . ' feedzy-errors-dialog" title="' . __( 'Errors', 'feedzy-rss-feeds' ) . '" data-id="' . $post_id . '">' . $errors . '</div>';
897900
}
898901

899902
// remember, cypress will work off the data-value attributes.
@@ -1096,23 +1099,28 @@ public function ajax() {
10961099
case 'remove_upsell_notice':
10971100
$this->remove_import_upsell();
10981101
break;
1102+
case 'clear_error_logs':
1103+
$this->clear_error_logs();
1104+
break;
1105+
}
1106+
}
1107+
1108+
/**
1109+
* AJAX called method to remove import upsell notice.
1110+
*
1111+
* @since 3.4.1
1112+
* @access public
1113+
*/
1114+
public function remove_import_upsell() {
1115+
if ( ! is_user_logged_in() ) {
1116+
return;
10991117
}
1118+
$user_id = get_current_user_id();
1119+
update_user_meta( $user_id, 'feedzy_import_upsell_notice', 'dismissed' );
1120+
1121+
wp_send_json_success();
11001122
}
1101-
/**
1102-
* AJAX called method to remove import upsell notice.
1103-
*
1104-
* @since 3.4.1
1105-
* @access public
1106-
*/
1107-
public function remove_import_upsell() {
1108-
if ( ! is_user_logged_in() ) {
1109-
return;
1110-
}
1111-
$user_id = get_current_user_id();
1112-
update_user_meta( $user_id, 'feedzy_import_upsell_notice', 'dismissed' );
11131123

1114-
wp_send_json_success();
1115-
}
11161124
/**
11171125
* AJAX called method to update post status.
11181126
*
@@ -1361,6 +1369,7 @@ public function run_cron( $max = 100, $job_id = 0 ) {
13611369
* @access private
13621370
*/
13631371
private function run_job( $job, $max ) {
1372+
global $themeisle_log_event;
13641373
$source = get_post_meta( $job->ID, 'source', true );
13651374
$inc_key = get_post_meta( $job->ID, 'inc_key', true );
13661375
$exc_key = get_post_meta( $job->ID, 'exc_key', true );
@@ -2101,6 +2110,10 @@ function( $term ) {
21012110
$count
21022111
);
21032112
}
2113+
2114+
if ( ! empty( $themeisle_log_event ) ) {
2115+
$import_errors = array_merge( $themeisle_log_event, $import_errors );
2116+
}
21042117
update_post_meta( $job->ID, 'import_errors', $import_errors );
21052118

21062119
// the order of these matters in how they are finally shown in the summary.
@@ -3313,4 +3326,20 @@ public function get_actions_runner( $actions = '', $type = '' ) {
33133326
$action_instance->set_settings( $this->settings );
33143327
return $action_instance;
33153328
}
3329+
3330+
/**
3331+
* Clear error logs.
3332+
*/
3333+
private function clear_error_logs() {
3334+
check_ajax_referer( FEEDZY_BASEFILE, 'security' );
3335+
$id = ! empty( $_POST['id'] ) ? (int) $_POST['id'] : 0;
3336+
if ( $id ) {
3337+
delete_post_meta( $id, 'import_errors' );
3338+
}
3339+
wp_send_json(
3340+
array(
3341+
'status' => 1,
3342+
)
3343+
);
3344+
}
33163345
}

includes/views/css/import-metabox-edit.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,14 @@ span.feedzy-spinner {
130130

131131
#TB_ajaxContent div.dry_run span i.fail {
132132
color: #ca4a1f;
133+
}
134+
135+
.feedzy-errors-dialog + .ui-widget-content .ui-dialog-buttonset {
136+
width: 100%;
137+
}
138+
.feedzy-errors-dialog + .ui-widget-content button.feedzy-clear-logs {
139+
margin-left: 0;
140+
}
141+
.feedzy-error.feedzy-api-error .notice-success {
142+
color: #3c434a;
133143
}

includes/views/js/import-metabox-edit.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,11 +676,59 @@
676676
"ui-dialog-content": "feedzy-dialog-content",
677677
},
678678
width: 500,
679-
buttons: {
680-
Ok: function () {
681-
$(this).dialog("close");
679+
buttons:[
680+
{
681+
text: feedzy.i10n.okButton,
682+
click: function () {
683+
$(this).dialog('close');
684+
}
685+
}
686+
]
687+
});
688+
689+
// Error logs popup.
690+
$(".feedzy-errors-dialog").dialog({
691+
modal: true,
692+
autoOpen: false,
693+
height: 400,
694+
width: 500,
695+
buttons:[
696+
{
697+
text: feedzy.i10n.clearLogButton,
698+
class: 'button button-primary feedzy-clear-logs',
699+
click: function (event) {
700+
var clearButton = $(event.target);
701+
var dialogBox = $(this);
702+
$('<span class="feedzy-spinner spinner is-active"></span>').insertAfter(clearButton);
703+
clearButton.attr('disabled', true);
704+
$.post(
705+
ajaxurl,
706+
{
707+
security: feedzy.ajax.security,
708+
id: $(this).attr('data-id'),
709+
action: 'feedzy',
710+
_action: 'clear_error_logs',
711+
},
712+
function () {
713+
clearButton
714+
.next('.feedzy-spinner')
715+
.remove();
716+
717+
dialogBox
718+
.find('.feedzy-error.feedzy-api-error')
719+
.html('<div class="notice notice-success"><p>' + feedzy.i10n.removeErrorLogsMsg + '</p></div>')
720+
}
721+
);
722+
}
682723
},
683-
},
724+
{
725+
text: feedzy.i10n.okButton,
726+
class: 'alignright',
727+
click: function () {
728+
$(this).dialog('close');
729+
}
730+
}
731+
]
684732
});
685733

686734
$(".feedzy-dialog-open").on("click", function (e) {

0 commit comments

Comments
 (0)