HEX
Server: Apache
System: Linux sxb1plmcpnl510113.prod.sxb1.secureserver.net 4.18.0-553.58.1.lve.el8.x86_64 #1 SMP Fri Jul 4 12:07:06 UTC 2025 x86_64
User: acnbijigo78q (10488831)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home/acnbijigo78q/public_html/wp-content/plugins/wpml-import/classes/UI/Endpoints/Command.php
<?php

namespace WPML\Import\UI\Endpoints;

use WPML\Ajax\IHandler;
use WPML\Collect\Support\Collection;
use WPML\FP\Either;
use WPML\FP\Left;
use WPML\FP\Right;
use WPML\Import\Commands\Provider as CommandsProvider;

class Command implements IHandler {

	const KEY_COMMAND_CLASS     = 'commandClass';
	const KEY_INDEX             = 'index';
	const KEY_STATUS            = 'status';
	const KEY_COUNT_TOTAL_ITEMS = 'countTotalItems';
	const KEY_COUNT_PROCESSED   = 'countProcessed';

	const STATUS_PROCESSING = 'processing';
	const STATUS_COMPLETE   = 'complete';

	const POSTS_PER_BATCH = 20;

	/**
	 * @param Collection $data
	 *
	 * @return Either
	 */
	public function run( Collection $data ) {
		$command = CommandsProvider::getCommandInstance( $data->get( self::KEY_COMMAND_CLASS ) );

		if ( ! $command ) {
			return Left::of( [] );
		}

		$index           = (int) $data->get( self::KEY_INDEX, 0 );
		$countTotalItems = (int) $data->get( self::KEY_COUNT_TOTAL_ITEMS, 0 );
		$countProcessed  = (int) $data->get( self::KEY_COUNT_PROCESSED, 0 );

		if ( $index ) {
			$countProcessedInStep = $command->run();
			if ( 0 === $countProcessedInStep ) {
				$processStatus = self::STATUS_COMPLETE;
			} else {
				$countProcessed += $countProcessedInStep;
				$processStatus   = $countProcessed >= $countTotalItems ? self::STATUS_COMPLETE : self::STATUS_PROCESSING;
			}
		} else {
			$countTotalItems = $command->countPendingItems();
			$processStatus   = self::STATUS_PROCESSING;
		}

		return Right::of( [
			self::KEY_INDEX             => $index + 1,
			self::KEY_STATUS            => $processStatus,
			self::KEY_COUNT_TOTAL_ITEMS => $countTotalItems,
			self::KEY_COUNT_PROCESSED   => $countProcessed,
		] );
	}
}