Tribe__Events__Aggregator__Records::action_do_import()

Start the import process.


Return

(null)


Top ↑

Source

File: src/Tribe/Aggregator/Records.php

	public function action_do_import() {
		 // First we convert the array to a json string
		$json = json_encode( $_POST );

		// The we convert the json string to a stdClass()
		$request = json_decode( $json );

		// Empty Required Variables
		if ( empty( $request->data->import_id ) || empty( $_GET['key'] ) ) {
			return wp_send_json_error();
		}

		$import_id = $request->data->import_id;
		$record = $this->get_by_import_id( $import_id );

		// We received an Invalid Import ID
		if ( tribe_is_error( $record ) ) {
			return wp_send_json_error();
		}

		// Verify if Hash matches sent Key
		if ( ! isset( $record->meta['hash'] ) || $record->meta['hash'] !== $_GET['key'] ) {
			return wp_send_json_error();
		}

		if ( ! empty( $_GET['trigger_new'] ) ) {
			$_GET['tribe_queue_sync'] = true;

			$record->update_meta( 'in_progress', null );
			$record->update_meta( 'queue_id', null );

			$record->set_status_as_pending();
			$record->process_posts( $request, true );
			$record->set_status_as_success();
		} else {
			$record->process_posts( $request, true );
		}

		return wp_send_json_success();
	}

Top ↑

Changelog

Changelog
Version Description
4.3.0 Introduced.