HEX
Server: LiteSpeed
System: Linux eko108.isimtescil.net 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: uyarreklamcomtr (11202)
PHP: 7.4.33
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/CleanupSyncedProducts.php.tar
httpdocs/wp-content/plugins/google-listings-and-ads/src/Jobs/CleanupSyncedProducts.php000064400000004254151546437660033532 0ustar00var/www/vhosts/uyarreklam.com.tr<?php
declare( strict_types=1 );

namespace Automattic\WooCommerce\GoogleListingsAndAds\Jobs;

defined( 'ABSPATH' ) || exit;

/**
 * Class CleanupSyncedProducts
 *
 * Marks products as unsynced when we disconnect the Merchant Account.
 * The Merchant Center must remain disconnected during the job. If it is
 * reconnected during the job it will stop processing, since the
 * ProductSyncer will take over and update all the products.
 *
 * @since 1.12.0
 *
 * @package Automattic\WooCommerce\GoogleListingsAndAds\Jobs
 */
class CleanupSyncedProducts extends AbstractProductSyncerBatchedJob {

	/**
	 * Get whether Merchant Center is connected.
	 *
	 * @return bool
	 */
	public function is_mc_connected(): bool {
		return $this->merchant_center->is_connected();
	}

	/**
	 * Get the name of the job.
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'cleanup_synced_products';
	}

	/**
	 * Can the job be scheduled.
	 * Only cleanup when the Merchant Center is disconnected.
	 *
	 * @param array|null $args
	 *
	 * @return bool Returns true if the job can be scheduled.
	 */
	public function can_schedule( $args = [] ): bool {
		return ! $this->is_running( $args ) && ! $this->is_mc_connected();
	}

	/**
	 * Get a single batch of items.
	 *
	 * If no items are returned the job will stop.
	 *
	 * @param int $batch_number The batch number increments for each new batch in the job cycle.
	 *
	 * @return int[]
	 */
	public function get_batch( int $batch_number ): array {
		return $this->product_repository->find_synced_product_ids( [], $this->get_batch_size(), $this->get_query_offset( $batch_number ) );
	}

	/**
	 * Process batch items.
	 * Skips processing if the Merchant Center has been connected again.
	 *
	 * @param int[] $items A single batch of WooCommerce product IDs from the get_batch() method.
	 */
	protected function process_items( array $items ) {
		if ( $this->is_mc_connected() ) {
			do_action(
				'woocommerce_gla_debug_message',
				sprintf(
					'Skipping cleanup of unsynced products because Merchant Center is connected: %s',
					implode( ',', $items )
				),
				__METHOD__
			);
			return;
		}

		$this->batch_product_helper->mark_batch_as_unsynced( $items );
	}
}