UOA_ERRORS::error( $recipe_id,  $user_id,  $recipe_log_id,  $args )

Validation function when the trigger action is hit


Parameters Parameters

$recipe_id

(Required)

$user_id

(Required)

$recipe_log_id

(Required)

$args

(Required)


Source Source

File: src/integrations/uncanny-automator/triggers/uoa-errors.php

	public function error( $recipe_id, $user_id, $recipe_log_id, $args ) {



		global $wpdb;
		// get recipe actions
		$table_name = $wpdb->prefix . 'uap_action_log';
		$q          = "SELECT automator_action_id FROM $table_name WHERE automator_recipe_log_id = {$recipe_log_id} AND error_message != ''";
		$errors     = $wpdb->get_results( $q );

		if ( empty( $errors ) ) {
			// bail early
			return;
		}
		if ( ! empty( $errors ) ) {

			$args = [
				'code'           => $this->trigger_code,
				'meta'           => $this->trigger_meta,
				'user_id'        => $user_id,
				'ignore_post_id' => true,
			];

			Automator()->maybe_add_trigger_entry( $args, false );

			$args = Automator()->maybe_add_trigger_entry( $args, false );
			if ( $args ) {
				foreach ( $args as $result ) {
					if ( true === $result['result'] ) {

						$recipe = get_post( $recipe_id );

						if ( $recipe ) {

							Automator()->insert_trigger_meta(
								[
									'user_id'        => $user_id,
									'trigger_id'     => $result['args']['trigger_id'],
									'meta_key'       => 'UOAERRORS_recipe_id',
									'meta_value'     => $recipe->ID,
									'trigger_log_id' => $result['args']['get_trigger_id'],
									'run_number'     => $result['args']['run_number'],
								]
							);
							Automator()->insert_trigger_meta(
								[
									'user_id'        => $user_id,
									'trigger_id'     => $result['args']['trigger_id'],
									'meta_key'       => 'UOAERRORS_recipe_title',
									'meta_value'     => $recipe->post_title,
									'trigger_log_id' => $result['args']['get_trigger_id'],
									'run_number'     => $result['args']['run_number'],
								]
							);
							Automator()->insert_trigger_meta(
								[
									'user_id'        => $user_id,
									'trigger_id'     => $result['args']['trigger_id'],
									'meta_key'       => 'UOAERRORS_recipe_edit_link',
									'meta_value'     => get_edit_post_link( $recipe->ID ),
									'trigger_log_id' => $result['args']['get_trigger_id'],
									'run_number'     => $result['args']['run_number'],
								]
							);
							Automator()->insert_trigger_meta(
								[
									'user_id'        => $user_id,
									'trigger_id'     => $result['args']['trigger_id'],
									'meta_key'       => 'UOAERRORS_recipe_log_url',
									'meta_value'     => "recipe_id=$recipe_id&user_id=$user_id",
									'trigger_log_id' => $result['args']['get_trigger_id'],
									'run_number'     => $result['args']['run_number'],
								]
							);
							Automator()->insert_trigger_meta(
								[
									'user_id'        => $user_id,
									'trigger_id'     => $result['args']['trigger_id'],
									'meta_key'       => 'UOAERRORS_action_log_url',
									'meta_value'     => "recipe_id=$recipe_id&user_id=$user_id",
									'trigger_log_id' => $result['args']['get_trigger_id'],
									'run_number'     => $result['args']['run_number'],
								]
							);
							// FUTURE USE STORE THE ACTION ID OR OTHER INFORMATION ABOUT THE ACTION THAT ERRORED OUT
							//				foreach ( $errors as $error ) {
							//					$automator_action_id = $error->automator_action_id;
							//					$action = get_post($automator_action_id);
							//					Automator()->insert_trigger_meta(
							//						[
							//							'user_id'        => $user_id,
							//							'trigger_id'     => $args['trigger_id'],
							//							'meta_key'       => 'UOAERRORS_action_id',
							//							'meta_value'     => $action->ID,
							//							'trigger_log_id' => $args['get_trigger_id'],
							//							'run_number'     => $args['run_number'],
							//						]
							//					);
							//
							//
							//				}
						}
						Automator()->maybe_trigger_complete( $result['args'] );
					}
				}
			}
		}
	}