Automattic\WooCommerce\Admin\RemoteInboxNotifications

SpecRunner::run_spec()public staticWC 1.0

Run the spec.

Method of the class: SpecRunner{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = SpecRunner::run_spec( $spec, $stored_state );
$spec(object) (required)
The spec to run.
$stored_state(object) (required)
Stored state.

SpecRunner::run_spec() code WC 8.7.0

public static function run_spec( $spec, $stored_state ) {
	$data_store = Notes::load_data_store();

	// Create or update the note.
	$existing_note_ids = $data_store->get_notes_with_name( $spec->slug );
	if ( ! is_countable( $existing_note_ids ) || count( $existing_note_ids ) === 0 ) {
		$note = new Note();
		$note->set_status( Note::E_WC_ADMIN_NOTE_PENDING );
	} else {
		$note = Notes::get_note( $existing_note_ids[0] );
		if ( $note === false ) {
			return;
		}
	}

	// Evaluate the spec and get the new note status.
	$previous_status = $note->get_status();
	try {
		$status = EvaluateAndGetStatus::evaluate(
			$spec,
			$previous_status,
			$stored_state,
			new RuleEvaluator()
		);
	} catch ( \Throwable $e ) {
		return $e;
	}

	// If the status is changing, update the created date to now.
	if ( $previous_status !== $status ) {
		$note->set_date_created( time() );
	}

	// Get the matching locale or fall back to en-US.
	$locale = self::get_locale( $spec->locales );

	if ( $locale === null ) {
		return;
	}

	// Set up the note.
	$note->set_title( $locale->title );
	$note->set_content( $locale->content );
	$note->set_content_data( isset( $spec->content_data ) ? $spec->content_data : (object) array() );
	$note->set_status( $status );
	$note->set_type( $spec->type );
	$note->set_name( $spec->slug );
	if ( isset( $spec->source ) ) {
		$note->set_source( $spec->source );
	}

	// Recreate actions.
	$note->set_actions( self::get_actions( $spec ) );

	$note->save();
}