Automator_Recipe_Process_User::insert_recipe_log( $recipe_id,  $user_id, null $maybe_add_log_id = null )


Parameters Parameters

$recipe_id

(Required)

$user_id

(Required)

$maybe_add_log_id

(null) (Optional)

Default value: null


Top ↑

Return Return

(int)


Source Source

File: src/core/lib/process/class-automator-recipe-process-user.php

	public function insert_recipe_log( $recipe_id, $user_id, $maybe_add_log_id = null ) {

		global $wpdb;
		$table_name = $wpdb->prefix . 'uap_recipe_log';

		$results = $wpdb->get_var( $wpdb->prepare(
			"SELECT
				COUNT(completed)
				FROM $table_name
				WHERE 1=1
				AND completed = 1
				AND user_id = %d
				AND automator_recipe_id = %d", $user_id, $recipe_id ) );

		if ( 0 !== absint( $user_id ) ) {
			$num_times_recipe_run = Automator()->utilities->recipe_number_times_completed( $recipe_id, $results );
		} else {
			$num_times_recipe_run = false;
		}


		if ( ! $num_times_recipe_run ) {
			$run_number = Automator()->get->next_run_number( $recipe_id, $user_id );

			$insert = array(
				'date_time'           => '0000-00-00 00:00:00',
				'user_id'             => $user_id,
				'automator_recipe_id' => $recipe_id,
				'completed'           => - 1,
				'run_number'          => $run_number,
			);

			$format = array(
				'%s',
				'%d',
				'%d',
				'%d',
			);

			/*
			 * Force new ID
			 * if ( ! is_null( $maybe_add_log_id ) ) {
				$insert['ID'] = $maybe_add_log_id;
				$format[]     = '%d';
			}*/

			$wpdb->insert( $table_name, $insert, $format );
			$recipe_log_id = (int) $wpdb->insert_id;

			return $recipe_log_id;
		}

		return null;
	}