Tribe__Events__Aggregator__Tabs__New::ajax_fetch_import()


Source

File: src/Tribe/Aggregator/Tabs/New.php

	public function ajax_fetch_import() {
		$import_id = $_GET['import_id'];

		$record = Tribe__Events__Aggregator__Records::instance()->get_by_import_id( $import_id );

		if ( tribe_is_error( $record ) ) {
			wp_send_json_error( $record );
		}

		$result = $record->get_import_data();

		if ( isset( $result->data ) ) {
			$result->data->origin = $record->origin;
		}

		if ( is_wp_error( $result ) ) {
			wp_send_json_error( $result );
		}

		// if we've received a source name, let's set that in the record as soon as possible
		if ( ! empty( $result->data->source_name ) ) {
			$record->update_meta( 'source_name', $result->data->source_name );

			if ( ! empty( $record->post->post_parent ) ) {
				$parent_record = Tribe__Events__Aggregator__Records::instance()->get_by_post_id( $record->post->post_parent );

				if ( tribe_is_error( $parent_record ) ) {
					$parent_record->update_meta( 'source_name', $result->data->source_name );
				}
			}
		}

		// if there is a warning in the data let's localize it
		if ( ! empty( $result->warning_code ) ) {
			/** @var Tribe__Events__Aggregator__Service $service */
			$service         = tribe( 'events-aggregator.service' );
			$default_warning = ! empty( $result->warning ) ? $result->warning : null;
			$result->warning = $service->get_service_message( $result->warning_code, array(), $default_warning );
		}

		wp_send_json_success( $result );
	}