Skip to content

Commit

Permalink
Fixed condition about checking and deleting expired page cursor. Adde…
Browse files Browse the repository at this point in the history
…d error return to the conditional check. Added text info for expired or deleted page cursor to frontend. Now deletes page cursor if lost or expired, tells the user, and starts post import from scratch
  • Loading branch information
codebard committed Nov 26, 2020
1 parent a9fe8c8 commit 3830438
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
jQuery( '#patreon_wp_post_import_status' ).css( 'color', '#f31d00' );
return;
}

if ( response == 'expired_or_lost_cursor_deleted') {
jQuery( '#patreon_wp_post_import_status' ).html( 'Expired or lost page cursor deleted. Post import will restart from scratch...' );
return;
}

if ( response == 'couldnt_get_posts') {
jQuery( '#patreon_wp_post_import_status' ).html( 'Failed to get posts from Patreon...' );
Expand Down
8 changes: 4 additions & 4 deletions classes/patreon_content_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public function import_posts_from_patreon( $args = array() ) {
$cursor = get_option( 'patreon-post-import-next-cursor', null );

$posts = $api_client->get_posts( false, 5, $cursor );

if ( isset( $posts['data']['errors'][0]['code'] ) AND $posts['data']['errors'][0]['code'] == 3 AND $posts['data']['errors'][0]['source']['parameter'] == 'page[cursor]' ) {

if ( isset( $posts['errors'][0]['code'] ) AND $posts['errors'][0]['code'] == 3 AND $posts['errors'][0]['source']['parameter'] == 'page[cursor]' ) {
// Cursor expired. Delete the cursor for next run and return
delete_option( 'patreon-post-import-next-cursor' );
return;
return 'expired_or_lost_cursor_deleted';
}

if ( !isset( $posts['data'] ) ) {
Expand Down
9 changes: 8 additions & 1 deletion classes/patreon_wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ static function updatePatreonUser() {
public static function checkPatreonCreatorID() {

// Check if creator id doesnt exist. Account for the case in which creator id was saved as empty by the Creator

self::$patreon_content_sync->import_posts_from_patreon();

if ( !get_option( 'patreon-creator-id', false ) OR get_option( 'patreon-creator-id', false )== '' ) {

// Making sure access credentials are there to avoid fruitlessly contacting the api:
Expand Down Expand Up @@ -1124,6 +1125,12 @@ public function import_next_batch_of_posts() {
echo 'no_ongoing_post_import';
exit;
}

if ( $import_return == 'expired_or_lost_cursor_deleted' ) {
// This means no post import ongoing
echo 'expired_or_lost_cursor_deleted';
exit;
}


}
Expand Down

0 comments on commit 3830438

Please sign in to comment.