Filter uncanny-automator-pro

automator_pro_auto_purge_logs_exclude_completed_with_errors

Filters whether to exclude completed logs with errors from automatic purging.

add_filter( 'automator_pro_auto_purge_logs_exclude_completed_with_errors', $callback, 10, 1 );

Description

Filters whether "Completed with errors" logs should be excluded from automatic purging. By default, this filter returns true, meaning these logs are excluded. Developers can return false to include them in the purge process.


Usage

add_filter( 'automator_pro_auto_purge_logs_exclude_completed_with_errors', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

// Prevent the "Completed with errors" status from being purged during automatic log cleanup.
add_filter( 'automator_pro_auto_purge_logs_exclude_completed_with_errors', function( $exclude ) {
    // By default, the filter returns true, meaning "Completed with errors" is excluded.
    // To include them in the purge, you would return false.
    // For this example, we'll keep the default behavior and explicitly return true.
    return true;
}, 10, 1 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

uncanny-automator-pro/src/core/extensions/activity-log-settings.php:180

public function delete_records( $purge_value = 1, $unit = 'days' ) {

		global $wpdb;

		$finished_statuses = apply_filters( 'automator_pro_auto_purge_logs_statuses_to_remove', Automator_Status::get_finished_statuses() );

		// Optionally not remove "Completed with errors".
		if ( true === apply_filters( 'automator_pro_auto_purge_logs_exclude_completed_with_errors', true ) ) {
			foreach ( $finished_statuses as $k => $v ) {
				if ( 2 === (int) $v ) {
					unset( $finished_statuses[ $k ] );
				}
			}
		}

		$datetime_base = $this->get_datetime_base( $purge_value, $unit );
		$previous_time = apply_filters( 'automator_pro_auto_purge_logs_previous_time', $datetime_base, $purge_value );
		$chunk_size    = apply_filters( 'automator_pro_auto_purge_chunk_size', self::PURGE_CHUNK_SIZE );
		$memory_limit  = $this->get_memory_limit_bytes() * self::MEMORY_THRESHOLD;

		$placeholders = implode( ',', array_fill( 0, count( $finished_statuses ), '%d' ) );

		do {
			// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
			$recipes = $wpdb->get_results(
				$wpdb->prepare(
					"SELECT `ID`, `automator_recipe_id`, `run_number`
					FROM {$wpdb->prefix}uap_recipe_log
					WHERE `date_time` < %s
						AND `completed` IN ({$placeholders})
					LIMIT %d",
					array_merge( array( $previous_time ), $finished_statuses, array( $chunk_size ) )
				)
			);

			if ( empty( $recipes ) ) {
				break;
			}

			foreach ( $recipes as $recipe ) {

				$recipe_id               = absint( $recipe->automator_recipe_id );
				$automator_recipe_log_id = absint( $recipe->ID );
				$run_number              = absint( $recipe->run_number );

				// Purge recipe logs.
				automator_purge_recipe_logs( $recipe_id, $automator_recipe_log_id );
				// Purge trigger logs.
				automator_purge_trigger_logs( $recipe_id, $automator_recipe_log_id );
				// Purge action logs.
				automator_purge_action_logs( $recipe_id, $automator_recipe_log_id );
				// Purge closure logs.
				automator_purge_closure_logs( $recipe_id, $automator_recipe_log_id );

				do_action( 'automator_recipe_log_deleted', $recipe_id, $automator_recipe_log_id, $run_number );
			}

			// If approaching memory limit, reschedule remaining work and bail.
			// Guard against duplicate scheduling — only queue if no pending run exists.
			if ( memory_get_usage( true ) > $memory_limit ) {
				if ( false === as_next_scheduled_action( self::$cron_schedule, array(), 'uncanny-automator' ) ) {
					as_schedule_single_action( time() + 60, self::$cron_schedule, array(), 'uncanny-automator' );
				}
				return;
			}
		} while ( count( $recipes ) >= $chunk_size );
	}


Scroll to Top