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/woocommerce-zapier/src/TaskHistory/Task.php
<?php

namespace OM4\WooCommerceZapier\TaskHistory;

use OM4\WooCommerceZapier\Exception\InvalidTaskException;
use OM4\WooCommerceZapier\TaskHistory\TaskDataStore;
use OM4\WooCommerceZapier\Webhook\ZapierWebhook;
use WC_Data;
use WC_DateTime;

defined( 'ABSPATH' ) || exit;

/**
 * Represents as single Task History Task record.
 *
 * @since 2.0.0
 */
class Task extends WC_Data {

	/**
	 * Stores Task data.
	 *
	 * @var array
	 */
	protected $data = array(
		'date_time'     => null,
		'webhook_id'    => null,
		'resource_type' => null,
		'resource_id'   => null,
		'message'       => '',
		'type'          => '',
	);

	/**
	 * Name of this data type.
	 *
	 * Used by WooCommerce core, which executes WordPress filters during save/updates.
	 *
	 * @var string
	 */
	protected $object_type = 'zapier_task';

	/**
	 * TaskDataStore instance.
	 *
	 * @var TaskDataStore
	 */
	protected $data_store;

	/**
	 * Constructor. Creates a new Task or loads and existing Task if specified.
	 *
	 * @param TaskDataStore  $data_store TaskDataStore instance.
	 * @param int|Task|array $task       Task ID to load from the DB (optional) or already queried data.
	 */
	public function __construct( TaskDataStore $data_store, $task = 0 ) {
		$this->data_store = $data_store;
		parent::__construct( $task );

		if ( $task instanceof Task ) {
			$this->set_id( $task->get_id() );
		} elseif ( is_numeric( $task ) ) {
			$this->set_id( $task );
		} elseif ( is_array( $task ) ) {
			$this->set_id( $task['history_id'] );
			$this->set_props( $task );
			$this->set_object_read( true );
		}

		// If we have an ID, load the webhook from the DB.
		if ( 0 !== $this->get_id() ) {
			try {
				$this->data_store->read( $this );
			} catch ( InvalidTaskException $e ) {
				$this->set_id( 0 );
				$this->set_object_read( true );
			}
		} else {
			// Creating a brand new Task.
			$this->set_date_time( new WC_DateTime() );
			$this->set_object_read( true );
		}

	}

	/*
	|--------------------------------------------------------------------------
	| Getters
	|--------------------------------------------------------------------------
	*/

	/**
	 * Get date/time.
	 *
	 * @param  string $context Get context.
	 *
	 * @return WC_DateTime Date/time object.
	 */
	public function get_date_time( $context = 'view' ) {
		return $this->get_prop( 'date_time', $context );
	}

	/**
	 * Get webhook id.
	 *
	 * @param  string $context Get context.
	 *
	 * @return integer
	 */
	public function get_webhook_id( $context = 'view' ) {
		return $this->get_prop( 'webhook_id', $context );
	}

	/**
	 * Get the webhook.
	 *
	 * @return ZapierWebhook The webhook.
	 */
	public function get_webhook() {
		return new ZapierWebhook( $this->get_webhook_id() );
	}

	/**
	 * Get resource type.
	 *
	 * @param  string $context Get context.
	 *
	 * @return string
	 */
	public function get_resource_type( $context = 'view' ) {
		return $this->get_prop( 'resource_type', $context );
	}

	/**
	 * Get resource id.
	 *
	 * @param  string $context Get context.
	 *
	 * @return integer
	 */
	public function get_resource_id( $context = 'view' ) {
		return $this->get_prop( 'resource_id', $context );
	}

	/**
	 * Get message.
	 *
	 * @param  string $context Get context.
	 *
	 * @return string
	 */
	public function get_message( $context = 'view' ) {
		return $this->get_prop( 'message', $context );
	}

	/**
	 * Get type.
	 *
	 * @param  string $context Get context.
	 *
	 * @return string
	 */
	public function get_type( $context = 'view' ) {
		return $this->get_prop( 'type', $context );
	}

	/*
	|--------------------------------------------------------------------------
	| Setters
	|--------------------------------------------------------------------------
	*/

	/**
	 * Set date/time.
	 *
	 * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date.
	 *
	 * @return void
	 */
	public function set_date_time( $date = null ) {
		if ( is_null( $date ) ) {
			$date = '';
		}
		$this->set_date_prop( 'date_time', $date );
	}

	/**
	 * Set webhook id.
	 *
	 * @param int $value Value to set.
	 *
	 * @return void
	 */
	public function set_webhook_id( $value ) {
		$this->set_prop( 'webhook_id', absint( $value ) );
	}

	/**
	 * Set resource type (eg product, order, customer, etc).
	 *
	 * @param string $value Value to set.
	 *
	 * @return void
	 */
	public function set_resource_type( $value ) {
		$this->set_prop( 'resource_type', $value );
	}

	/**
	 * Set resource id.
	 *
	 * @param int $value Value to set.
	 *
	 * @return void
	 */
	public function set_resource_id( $value ) {
		$this->set_prop( 'resource_id', absint( $value ) );
	}

	/**
	 * Set message.
	 *
	 * @param string $value Value to set.
	 *
	 * @return void
	 */
	public function set_message( $value ) {
		$this->set_prop( 'message', $value );
	}

	/**
	 * Set type.
	 *
	 * @param string $value Value to set.
	 *
	 * @return void
	 */
	public function set_type( $value ) {
		$this->set_prop( 'type', $value );
	}
}