1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Integration; |
4
|
|
|
|
5
|
|
|
use Magento\Integration\Model\IntegrationService; |
6
|
|
|
use Magento\Integration\Model\OauthService; |
7
|
|
|
use Magento\Integration\Model\ResourceModel\Oauth\Token\CollectionFactory as TokenCollectionFactory; |
8
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
9
|
|
|
use N98\Magento\Command\Integration\Renderer\TableRenderer; |
10
|
|
|
use Symfony\Component\Console\Exception\RuntimeException; |
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ShowCommand |
17
|
|
|
* @package N98\Magento\Command\Integration |
18
|
|
|
*/ |
19
|
|
|
class ShowCommand extends AbstractMagentoCommand |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var IntegrationService |
23
|
|
|
*/ |
24
|
|
|
private $integrationService; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var OauthService |
28
|
|
|
*/ |
29
|
|
|
private $oauthService; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var TokenCollectionFactory |
33
|
|
|
*/ |
34
|
|
|
private $tokenCollectionFactory; |
35
|
|
|
|
36
|
|
|
protected function configure() |
37
|
|
|
{ |
38
|
|
|
$this |
39
|
|
|
->setName('integration:show') |
40
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'Name or ID of the integration') |
41
|
|
|
->setDescription('Show details of an existing integration.'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function inject( |
45
|
|
|
IntegrationService $integrationService, |
46
|
|
|
OauthService $oauthService, |
47
|
|
|
TokenCollectionFactory $tokenCollectionFactory |
48
|
|
|
) { |
49
|
|
|
$this->integrationService = $integrationService; |
50
|
|
|
$this->oauthService = $oauthService; |
51
|
|
|
$this->tokenCollectionFactory = $tokenCollectionFactory; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
56
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
57
|
|
|
* @return int|void |
58
|
|
|
* @throws \Exception |
59
|
|
|
*/ |
60
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
61
|
|
|
{ |
62
|
|
|
$integrationName = $input->getArgument('name'); |
63
|
|
|
|
64
|
|
|
$integrationModel = $this->integrationService->findByName($integrationName); |
65
|
|
|
|
66
|
|
|
if ($integrationModel->getId() <= 0 && is_numeric($integrationName)) { |
67
|
|
|
$integrationModel = $this->integrationService->get($integrationName); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if ($integrationModel->getId() <= 0) { |
71
|
|
|
throw new RuntimeException('Integration with this name or ID does not exist.'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$consumerModel = $this->oauthService->loadConsumer($integrationModel->getConsumerId()); |
75
|
|
|
|
76
|
|
|
$tokenModel = $this->tokenCollectionFactory |
77
|
|
|
->create() |
78
|
|
|
->addFilterByConsumerId($integrationModel->getConsumerId()) |
79
|
|
|
->getFirstItem(); |
80
|
|
|
|
81
|
|
|
$table = new TableRenderer( |
82
|
|
|
$output, |
83
|
|
|
$integrationModel, |
84
|
|
|
$consumerModel, |
85
|
|
|
$tokenModel |
86
|
|
|
); |
87
|
|
|
$table->render(); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|