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/Webhook/Installer.php
<?php

namespace OM4\WooCommerceZapier\Webhook;

use OM4\WooCommerceZapier\Logger;
use OM4\WooCommerceZapier\Webhook\DataStore as WebhookDataStore;

defined( 'ABSPATH' ) || exit;

/**
 * Webhook-related functionality during plugin activation and deactivation:
 * - Pauses existing webhooks during deactivation.
 * - Re-activated paused webhooks during plugin reactivation.
 *
 * @since 2.0.0
 */
class Installer {

	/**
	 * Logger instance.
	 *
	 * @var Logger
	 */
	protected $logger;

	/**
	 * WebhookDataStore instance.
	 *
	 * @var WebhookDataStore
	 */
	protected $webhook_data_store;

	/**
	 * Constructor.
	 *
	 * @param Logger           $logger             The Logger.
	 * @param WebhookDataStore $webhook_data_store WebhookDataStore instance.
	 */
	public function __construct( Logger $logger, WebhookDataStore $webhook_data_store ) {
		$this->logger             = $logger;
		$this->webhook_data_store = $webhook_data_store;
	}

	/**
	 * Instructs the installer functionality to initialise itself.
	 *
	 * @return void
	 */
	public function initialise() {
		add_action( 'wc_zapier_plugin_deactivate', array( $this, 'pause_zapier_webhooks' ) );
		add_action( 'wc_zapier_db_upgrade_v_9_to_10', array( $this, 'unpause_zapier_webhooks' ) );
	}

	/**
	 * When a user deactivates the plugin, pause any existing Zapier webhooks so that no data is sent to them
	 * while the plugin is deactivated.
	 *
	 * @return void
	 */
	public function pause_zapier_webhooks() {
		$webhooks = $this->webhook_data_store->get_active_zapier_webhooks();

		if ( empty( $webhooks ) ) {
			return;
		}

		foreach ( $webhooks as $webhook ) {
			$webhook->set_status( 'paused' );
			$webhook->save();
			$this->logger->info( 'Active Webhook ID %d (%s) set to paused.', array( $webhook->get_id(), $webhook->get_name() ) );
		}
		$this->logger->info( '%d active webhook(s) paused.', array( count( $webhooks ) ) );
	}

	/**
	 * When a user activates the plugin, unpause any paused Zapier webhooks so that data will be
	 * (once again) sent to them.
	 *
	 * @return void
	 */
	public function unpause_zapier_webhooks() {
		$webhooks = $this->webhook_data_store->get_paused_zapier_webhooks();

		if ( empty( $webhooks ) ) {
			return;
		}

		foreach ( $webhooks as $webhook ) {
			$webhook->set_status( 'active' );
			$webhook->save();
			$this->logger->info( 'Paused Webhook ID %d (%s) set to active.', array( $webhook->get_id(), $webhook->get_name() ) );
		}
		$this->logger->info( '%d paused webhook(s) reactivated.', array( count( $webhooks ) ) );
	}
}