Automattic\WooCommerce\Admin\RemoteInboxNotifications

SpecRunner::run_spec()public staticWC 1.0

Run the spec.

Метод класса: SpecRunner{}

No Hooks.

Return

null. Nothing.

Usage

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

Code of SpecRunner::run_spec() WC 7.1.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 ( 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();
	$status          = EvaluateAndGetStatus::evaluate(
		$spec,
		$previous_status,
		$stored_state,
		new RuleEvaluator()
	);

	// 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();
}