Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4 from Magenerds/feature/settings_on_cli_overwrit…
Browse files Browse the repository at this point in the history
…eable

Feature/settings on cli overwriteable
  • Loading branch information
sydekumf authored Oct 10, 2017
2 parents 0df7313 + 5f50051 commit 1805315
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 13 deletions.
43 changes: 41 additions & 2 deletions Console/Command/ExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*/
Expand All @@ -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
*
Expand All @@ -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();
Expand Down
19 changes: 9 additions & 10 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +37,7 @@ class Config
const XML_PATH_LAST_SYNC_DATETIME = 'system_diff/general/last_sync_datetime';

/**
* @var ScopeConfigInterface
* @var MutableScopeConfigInterface
*/
private $scopeConfig;

Expand All @@ -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,
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -135,7 +135,6 @@ public function getLastSyncDatetimeFormatted()
{
$dateTime = $this->getLastSyncDatetime();
if ($dateTime instanceof DateTimeInterface) {

return $this->timezone->formatDateTime($dateTime, \IntlDateFormatter::SHORT, true);
}

Expand Down
11 changes: 10 additions & 1 deletion Remote/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Magenerds\SystemDiff\Helper\Config;
use Magenerds\SystemDiff\Api\Data\ConfigDataInterfaceFactory;
use Psr\Log\LoggerInterface;

class AbstractClient
{
Expand All @@ -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;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Remote/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
2 changes: 2 additions & 0 deletions Remote/SoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 1805315

Please sign in to comment.