From d04a01c7ed574f2becfff807e50265aff71c3989 Mon Sep 17 00:00:00 2001 From: Florian Beyerlein Date: Wed, 4 Oct 2017 08:52:39 +0200 Subject: [PATCH 1/2] Log errors in client. --- Remote/AbstractClient.php | 11 ++++++++++- Remote/RestClient.php | 2 ++ Remote/SoapClient.php | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Remote/AbstractClient.php b/Remote/AbstractClient.php index 0c2f54c..a6c9f2e 100644 --- a/Remote/AbstractClient.php +++ b/Remote/AbstractClient.php @@ -11,6 +11,7 @@ use Magenerds\SystemDiff\Helper\Config; use Magenerds\SystemDiff\Api\Data\ConfigDataInterfaceFactory; +use Psr\Log\LoggerInterface; class AbstractClient { @@ -24,18 +25,26 @@ class AbstractClient */ protected $configDataFactory; + /** + * @var LoggerInterface + */ + protected $logger; + /** * Client constructor. * * @param Config $configHelper * @param ConfigDataInterfaceFactory $configDataFactory + * @param LoggerInterface $logger */ public function __construct( Config $configHelper, - ConfigDataInterfaceFactory $configDataFactory + ConfigDataInterfaceFactory $configDataFactory, + LoggerInterface $logger ) { $this->helper = $configHelper; $this->configDataFactory = $configDataFactory; + $this->logger = $logger; } /** diff --git a/Remote/RestClient.php b/Remote/RestClient.php index d46ee50..9774f7b 100644 --- a/Remote/RestClient.php +++ b/Remote/RestClient.php @@ -36,6 +36,8 @@ public function fetch() throw new \Exception("REST response could not be read"); } + // From here error state -> exception. + $this->logger->error($response->getBody()); throw new \Exception("Request to remote was not successfull"); } } \ No newline at end of file diff --git a/Remote/SoapClient.php b/Remote/SoapClient.php index 687b6e3..319b5bf 100644 --- a/Remote/SoapClient.php +++ b/Remote/SoapClient.php @@ -39,6 +39,8 @@ public function fetch() return $this->configDataFactory->create(['data' => $this->buildDataFromJson($response->result->data->string)]); } + // error + $this->logger->error($httpClient->getLastResponse()); throw new \Exception("SOAP response could not be read"); } } \ No newline at end of file From 5f50051740be842d991c3acabd23947581666d7d Mon Sep 17 00:00:00 2001 From: Florian Beyerlein Date: Wed, 4 Oct 2017 08:53:49 +0200 Subject: [PATCH 2/2] API type, Remote URL and Access Token overwriteable on CLI --- Console/Command/ExecuteCommand.php | 43 ++++++++++++++++++++++++++++-- Helper/Config.php | 19 +++++++------ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Console/Command/ExecuteCommand.php b/Console/Command/ExecuteCommand.php index 6e76734..cd8e633 100644 --- a/Console/Command/ExecuteCommand.php +++ b/Console/Command/ExecuteCommand.php @@ -10,8 +10,10 @@ namespace Magenerds\SystemDiff\Console\Command; use Magenerds\SystemDiff\Helper\Config; +use Magento\Framework\App\Config\MutableScopeConfigInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Magenerds\SystemDiff\Service\PerformSystemDiffService; @@ -32,6 +34,13 @@ class ExecuteCommand extends Command */ const EXIT_CODE_EXCEPTION = 4; + /** + * Command options + */ + const OPTION_REMOTE_SYSTEM_URL = 'remote-system-url'; + const OPTION_API_TYPE = 'api-type'; + const OPTION_ACCESS_TOKEN = 'access-token'; + /** * @var PerformSystemDiffService */ @@ -42,33 +51,52 @@ class ExecuteCommand extends Command */ private $configHelper; + /** + * @var MutableScopeConfigInterface + */ + private $scopeConfig; + /** * ExecuteCommand constructor. * - * @param PerformSystemDiffService $performSystemDiffService - * @param Config $configHelper + * @param PerformSystemDiffService $performSystemDiffService + * @param MutableScopeConfigInterface $scopeConfig + * @param Config $configHelper */ public function __construct( PerformSystemDiffService $performSystemDiffService, + MutableScopeConfigInterface $scopeConfig, Config $configHelper ) { parent::__construct(self::COMMAND_NAME); + $this->performSystemDiffService = $performSystemDiffService; + $this->scopeConfig = $scopeConfig; $this->configHelper = $configHelper; } /** * Configures the current command. + * + * @return void */ public function configure() { $this->setName(self::COMMAND_NAME); $this->setDescription(self::COMMAND_DESCRIPTION); + $this->addOption(self::OPTION_API_TYPE, 'a', InputOption::VALUE_OPTIONAL, 'Overwrite configured api type'); + $this->addOption(self::OPTION_REMOTE_SYSTEM_URL, 'u', InputOption::VALUE_OPTIONAL, + 'Overwrite configured remote url'); + $this->addOption(self::OPTION_ACCESS_TOKEN, 't', InputOption::VALUE_OPTIONAL, + 'Overwrite configured access token'); + parent::configure(); } /** + * Perform system diff via service. + * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * @@ -77,6 +105,17 @@ public function configure() public function execute(InputInterface $input, OutputInterface $output) { $exitStatus = 0; + + if ($url = $input->getOption(self::OPTION_REMOTE_SYSTEM_URL)) { + $this->scopeConfig->setValue(Config::XML_PATH_REMOTE_SYSTEM_URL, $url); + } + if ($api = $input->getOption(self::OPTION_API_TYPE)) { + $this->scopeConfig->setValue(Config::XML_PATH_API_TYPE, $api); + } + if ($token = $input->getOption(self::OPTION_ACCESS_TOKEN)) { + $this->scopeConfig->setValue(Config::XML_PATH_ACCESS_TOKEN, $token); + } + try { $output->write('Performing sync and diff...'); $this->performSystemDiffService->performDiff(); diff --git a/Helper/Config.php b/Helper/Config.php index 53f208d..6629874 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -9,10 +9,10 @@ namespace Magenerds\SystemDiff\Helper; +use Magento\Framework\App\Config\MutableScopeConfigInterface; use DateTimeInterface; use Magenerds\SystemDiff\Model\DiffConfig; use Magenerds\SystemDiff\Model\ResourceModel\DiffConfig as DiffConfigResource; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magenerds\SystemDiff\Model\ResourceModel\DiffConfig\CollectionFactory; use Magenerds\SystemDiff\Model\DiffConfigFactory; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; @@ -37,7 +37,7 @@ class Config const XML_PATH_LAST_SYNC_DATETIME = 'system_diff/general/last_sync_datetime'; /** - * @var ScopeConfigInterface + * @var MutableScopeConfigInterface */ private $scopeConfig; @@ -64,14 +64,14 @@ class Config /** * Config constructor. * - * @param ScopeConfigInterface $scopeConfig - * @param CollectionFactory $collectionFactory - * @param DiffConfigFactory $diffConfigFactory - * @param TimezoneInterface $timezone - * @param DateTime $dateTime + * @param MutableScopeConfigInterface $scopeConfig + * @param CollectionFactory $collectionFactory + * @param DiffConfigFactory $diffConfigFactory + * @param TimezoneInterface $timezone + * @param DateTime $dateTime */ public function __construct( - ScopeConfigInterface $scopeConfig, + MutableScopeConfigInterface $scopeConfig, CollectionFactory $collectionFactory, DiffConfigFactory $diffConfigFactory, TimezoneInterface $timezone, @@ -80,8 +80,8 @@ public function __construct( $this->scopeConfig = $scopeConfig; $this->diffConfigCollectionFactory = $collectionFactory; $this->diffConfigFactory = $diffConfigFactory; - $this->dateTime = $dateTime; $this->timezone = $timezone; + $this->dateTime = $dateTime; } /** @@ -135,7 +135,6 @@ public function getLastSyncDatetimeFormatted() { $dateTime = $this->getLastSyncDatetime(); if ($dateTime instanceof DateTimeInterface) { - return $this->timezone->formatDateTime($dateTime, \IntlDateFormatter::SHORT, true); }