43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\SeventeenTrack\Console\Command;
|
|
|
|
use Esun\SeventeenTrack\Cron\SyncTracking;
|
|
use Esun\SeventeenTrack\Model\Config;
|
|
use Magento\Framework\Console\Cli;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class SyncCommand extends Command
|
|
{
|
|
public function __construct(
|
|
private readonly SyncTracking $sync,
|
|
private readonly Config $config
|
|
) {
|
|
parent::__construct('esun:17track:sync');
|
|
}
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this->setDescription('Register shipment numbers and synchronize delivery status with 17TRACK.');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
if (!$this->config->isEnabled() || $this->config->getApiKey() === '') {
|
|
$output->writeln('<error>17TRACK is disabled or the API key is missing.</error>');
|
|
return Cli::RETURN_FAILURE;
|
|
}
|
|
try {
|
|
$this->sync->execute();
|
|
$output->writeln('<info>17TRACK synchronization completed successfully.</info>');
|
|
return Cli::RETURN_SUCCESS;
|
|
} catch (\Throwable $exception) {
|
|
$output->writeln('<error>' . $exception->getMessage() . '</error>');
|
|
return Cli::RETURN_FAILURE;
|
|
}
|
|
}
|
|
}
|