HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/ielts-store/wp-content/plugins/automatewoo/includes/DatabaseUpdates/5.0.0.php
<?php
/**
 * Update to 5.0.0
 *
 * - set existing workflow types to "automatic"
 */

namespace AutomateWoo\DatabaseUpdates;

use AutomateWoo\Workflow_Query;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Database_Update_5_0_0
 *
 * @package AutomateWoo\DatabaseUpdates
 */
class Database_Update_5_0_0 extends AbstractDatabaseUpdate {

	/** @var string */
	protected $version = '5.0.0';

	/**
	 * @return bool
	 */
	protected function process() {
		$limit = 5;
		$query = $this->get_workflows_query( $limit );

		$results = $query->get_results();

		if ( empty( $results ) ) {
			return true; // no more items to process, return complete
		}

		foreach ( $results as $workflow ) {
			$workflow->update_meta( 'type', 'automatic' );

			$this->items_processed++;
		}

		return false;
	}

	/**
	 * @return bool|int
	 */
	public function get_items_to_process_count() {
		// Set limit to minimum since it's irrelevant to total count
		$query = $this->get_workflows_query( 1 );

		// We need a call to this function to be able to count the results
		$query->get_results();

		return $query->get_found_rows();
	}

	/**
	 * @param int $limit
	 * @return Workflow_Query
	 */
	private function get_workflows_query( $limit ) {
		$query = new Workflow_Query();

		$query->set_no_found_rows( false );
		$query->set_limit( $limit );

		$query->args['meta_query'][] = [
			'key'     => 'type',
			'compare' => 'NOT EXISTS',
		];

		return $query;
	}

	/**
	 * Called immediately after database update is completed.
	 */
	protected function finish() {
		global $wpdb;
		$table = $wpdb->prefix . 'automatewoo_unsubscribes';

		// Avoid DB errors
		if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ) ) === null ) {
			return;
		}

		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.SchemaChange

		// Only delete the table if it's empty
		$row_count = $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" );
		if ( is_numeric( $row_count ) && (int) $row_count === 0 ) {
			$wpdb->query( "DROP TABLE `{$table}`" );
		}

		// phpcs:enable

		parent::finish();
	}
}

return new Database_Update_5_0_0();