Automator_DB_Handler_Triggers::add_meta( $trigger_id,  $trigger_log_id,  $run_number,  $args )


Parameters Parameters

$trigger_id

(Required)

$trigger_log_id

(Required)

$run_number

(Required)

$args

(Required)


Top ↑

Return Return

(bool|int|null)


Source Source

File: src/core/lib/utilities/db/class-automator-db-handler-triggers.php

	public function add_meta( int $trigger_id, int $trigger_log_id, int $run_number, array $args ) {
		$user_id    = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : null;
		$meta_key   = isset( $args['meta_key'] ) ? esc_attr( $args['meta_key'] ) : null;
		$meta_value = isset( $args['meta_value'] ) ? $args['meta_value'] : null;
		$run_time   = isset( $args['run_time'] ) ? $args['run_time'] : current_time( 'mysql' );
		// Set user ID
		if ( is_null( $user_id ) ) {
			$user_id = get_current_user_id();
		}

		if ( ! is_numeric( $trigger_log_id ) ) {
			Automator()->error->add_error( 'insert_trigger_meta', 'ERROR: You are trying to insert trigger meta without providing valid trigger_log_id', $this );

			return null;
		}

		if ( null === $meta_key || ! is_string( $meta_key ) ) {
			Automator()->error->add_error( 'insert_trigger_meta', 'ERROR: You are trying to insert trigger meta without providing a meta_key', $this );

			return null;
		}

		if ( null === $meta_value ) {
			Automator()->error->add_error( 'insert_trigger_meta', 'ERROR: You are trying to insert trigger meta without providing a meta_value', $this );

			return null;
		}

		if ( 'sentence_human_readable' === $meta_key ) {
			if ( ! empty( $this->get_sentence( $user_id, $trigger_log_id, $run_number, $meta_key ) ) ) {
				// sentence already added!
				return null;
			}
		}

		global $wpdb;
		$table_name = isset( Automator()->db->tables->trigger_meta ) ? Automator()->db->tables->trigger_meta : 'uap_trigger_log_meta';

		return $wpdb->insert(
			$wpdb->prefix . $table_name,
			array(
				'user_id'                  => $user_id,
				'automator_trigger_log_id' => $trigger_log_id,
				'automator_trigger_id'     => $trigger_id,
				'run_number'               => $run_number,
				'meta_key'                 => $meta_key,
				'meta_value'               => $meta_value,
				'run_time'                 => $run_time,
			),
			array(
				'%d',
				'%d',
				'%d',
				'%d',
				'%s',
				'%s',
				'%s',
			)
		);
	}