process_airtable_record( $record ); // Temporarily save created or saved content ID if ( ! empty( $content_id ) && ! is_wp_error( $content_id ) ) { $this->append_run_result( $content_id, $importer ); } } // Delete temporary option delete_option( $item_id ); if ( $run_id === $importer->get_run_id() && 0 === $this->get_remaining_actions_count( $importer_id, $run_id ) ) { $importer->delete_removed_contents(); $importer->end_run( 'success' ); } } /** * Get count of remaining actions */ protected function get_remaining_actions_count( $importer_id, $run_id = null ) { $args = array( 'importer_id' => $importer_id, ); if ( $run_id ) { $args['run_id'] = $run_id; } $actions = as_get_scheduled_actions( array( 'hook' => 'airwpsync_process_records', 'status' => \ActionScheduler_Store::STATUS_PENDING, 'partial_args_matching' => 'like', 'args' => $args, 'per_page' => -1, ) ); return count( $actions ); } /** * Append new content_id to the run result */ protected function append_run_result( $content_id, $importer ) { $content_ids = get_post_meta( $importer->infos()->get( 'id' ), 'content_ids', true ) ?: array(); if ( ! is_array( $content_ids ) ) { $content_ids = array(); } $content_ids[] = $content_id; update_post_meta( $importer->infos()->get( 'id' ), 'content_ids', $content_ids ); } }