Automator_Recipe_Process_User::maybe_create_recipe_log_entry( int $recipe_id, int $user_id, bool $create_recipe = true, array $args = array(), bool $maybe_simulate = false, null $maybe_add_log_id = null )


Parameters Parameters

$recipe_id

(int) (Required)

$user_id

(int) (Required)

$create_recipe

(bool) (Optional)

Default value: true

$args

(array) (Optional)

Default value: array()

$maybe_simulate

(bool) (Optional)

Default value: false

$maybe_add_log_id

(null) (Optional)

Default value: null


Top ↑

Return Return

(array)


Source Source

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

	public function maybe_create_recipe_log_entry( $recipe_id, $user_id, $create_recipe = true, $args = array(), $maybe_simulate = false, $maybe_add_log_id = null ) {
		global $wpdb;

		$recipe_log_id = $wpdb->get_var(
			$wpdb->prepare(
				"SELECT ID
						FROM {$wpdb->prefix}uap_recipe_log
						WHERE completed NOT IN (1,2,5,9)
						AND automator_recipe_id = %d
						AND user_id = %d",
				$recipe_id,
				$user_id
			)
		);
		if ( $recipe_log_id && 0 !== absint( $user_id ) ) {
			return array(
				'existing'      => true,
				'recipe_log_id' => $recipe_log_id,
			);
		} elseif ( true === $maybe_simulate ) {
			/*
			 * @since 2.0
			 * @author Saad S.
			 */
			if ( ! is_null( $maybe_add_log_id ) ) {
				return array(
					'existing'      => false,
					'recipe_log_id' => $this->insert_recipe_log( $recipe_id, $user_id, $maybe_add_log_id ),
				);
			} else {

				/**
				 * Query changed from Table schema to Max(ID) to support wider MySQL settings
				 * Next Auto_Increment in certain environments returned last inserted ID instead of
				 * next one. Manually add 1 to get next insert ID
				 *
				 * @version 2.6.3
				 *
				 * Query changed back to AUTO_INCREMENT but added another query to reset cache
				 * @version 2.9
				 * @author  Saad S.
				 */

				//Check if it's MySQL 8+
				$check_mysql8 = $wpdb->get_results( "SHOW VARIABLES LIKE 'information_schema_stats_expiry'" );
				if ( ! empty( $check_mysql8 ) ) {
					$wpdb->query( 'SET information_schema_stats_expiry = 0;' );
				}

				$recipe_log_id = $wpdb->get_var( "SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '{$wpdb->prefix}uap_recipe_log';" );

				return array(
					'existing'      => false,
					'recipe_log_id' => $recipe_log_id,
				);
			}
		} elseif ( true === $create_recipe ) {
			return array(
				'existing'      => false,
				'recipe_log_id' => $this->insert_recipe_log( $recipe_id, $user_id, null ),
			);
		}

		return array(
			'existing'      => false,
			'recipe_log_id' => null,
		);
	}


Top ↑

Changelog Changelog

Changelog
Version Description
2.0 Introduced.