Files
remote_ip/app/common/Command/UpdateIp.php
2023-06-18 19:20:06 -04:00

43 lines
1.1 KiB
PHP

<?php
namespace ProVM\Command;
use Exception;
use PDOException;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use ProVM\Service\Remote;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'update',
hidden: false
)]
class UpdateIp extends Command
{
public function __construct(protected Remote $service, protected LoggerInterface $logger, string $name = 'update')
{
parent::__construct($name);
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Update IP');
try {
$io->info('Obtaining IP and updating database');
$this->service->update();
$io->info('Done');
return Command::SUCCESS;
} catch (PDOException $e) {
$this->logger->warning($e);
return Command::FAILURE;
} catch (Exception $e) {
$this->logger->error($e);
return Command::FAILURE;
}
}
}