Skip to content
Draft
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
22 changes: 22 additions & 0 deletions assets/js/gf-feed-forge-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ jQuery(function($) {
e.preventDefault();
gfffAbortQueue = true;
displayMessage(GFFF_ADMIN.abortSuccessMsg, 'error', '#entry_list_form');

$.post(ajaxurl, {
action: 'gf_process_feeds',
gf_process_feeds: GFFF_ADMIN.nonce,
abort_processing: true
}).done(function(response) {
if (response.success) {
gfffAbortQueue = true;
$('input[name="feed_process"]').prop('disabled', false);
closeModal(false);
location.reload();
}
});

// Hide the abort button after click
$(this).hide();
});

$('#doaction, #doaction2').click(function () {
Expand Down Expand Up @@ -87,6 +103,12 @@ jQuery(function($) {
total,
},
function (response) {
if (gfffAbortQueue || (response.success && response.data.aborted)) {
$('input[name="feed_process"]').prop('disabled', false);
closeModal(false);
return;
}

if (gfffAbortQueue) {
$('input[name="feed_process"]').prop('disabled', false);
closeModal(false);
Expand Down
38 changes: 38 additions & 0 deletions class-gwiz-gf-feed-forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class GWiz_GF_Feed_Forge extends GFAddOn {
protected $_short_title = 'Feed Forge';

const TRANSIENT_CURRENT_BATCH_OPTION_NAMES = 'gfff_current_batch_option_names';
const TRANSIENT_ABORT_FLAG = 'gfff_abort_processing';
const OPTION_BATCH_NAMES = 'gfff_current_batches';

public static function get_instance() {
if ( self::$instance === null ) {
Expand Down Expand Up @@ -381,8 +383,42 @@ public static function registered_addons() {
return apply_filters( 'gfff_registered_addons', $feed_addons );
}

public function abort_processing() {
$batch_names = get_option(self::OPTION_BATCH_NAMES, []);

foreach ( $batch_names as $batch_name ) {
delete_site_option($batch_name);
}

delete_option( self::OPTION_BATCH_NAMES );
delete_transient( self::TRANSIENT_CURRENT_BATCH_OPTION_NAMES );
set_transient( self::TRANSIENT_ABORT_FLAG, true, 10 );
}

public function should_abort() {
return get_transient( self::TRANSIENT_ABORT_FLAG );
}

public function track_batch( $batch_name ) {
$batch_names = get_option( self::OPTION_BATCH_NAMES, [] );
$batch_names[] = $batch_name;
update_option( self::OPTION_BATCH_NAMES, array_unique( $batch_names ) );
}

public function process_feeds() {
check_admin_referer( 'gf_process_feeds', 'gf_process_feeds' );

// Handle abort request
if ( rgpost( 'abort_processing' )) {
$this->abort_processing();
return;
}

// Check if we should abort
if ( $this->should_abort() ) {
return;
}

$form_id = absint( rgpost( 'formId' ) );
$leads = rgpost( 'leadIds' );
$feeds = json_decode( rgpost( 'feeds' ) );
Expand Down Expand Up @@ -478,6 +514,8 @@ public function process_feeds() {

$batch_option_names[] = $batch_option_name;

$this->track_batch( $batch_option_name );

set_transient( self::TRANSIENT_CURRENT_BATCH_OPTION_NAMES, $batch_option_names, DAY_IN_SECONDS );

if ( $count >= $total ) {
Expand Down