Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdminAnalyzer.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\ObjectManagerInterface;
13 use Symfony\Component\Console\Input\InputInterface;
14 use Symfony\Component\Console\Output\OutputInterface;
15 
19 class AdminAnalyzer extends \Symfony\Component\Console\Command\Command
20 {
26  private $output;
27 
33  private $objectManager;
34 
40  private $urlAnalyzer;
41 
46  public function __construct(
47  ObjectManagerInterface $objectManager,
48  UrlAnalyzer $urlAnalyzer
49  ) {
50  parent::__construct();
51  $this->objectManager = $objectManager;
52  $this->urlAnalyzer = $urlAnalyzer;
53  }
54 
60  protected function configure()
61  {
62  parent::configure();
63  $this->setName('troubleshooting:check-magento-admin')
64  ->setDescription('Check that app_backend_url is correct and admin can log in to Admin.');
65  }
66 
75  protected function execute(InputInterface $input, OutputInterface $output)
76  {
77  \PHPUnit\Util\Configuration::getInstance(MTF_PHPUNIT_FILE)->handlePHPConfiguration();
78  $this->output = $this->objectManager->create(
79  \Magento\Mtf\Console\Output::class,
80  ['output' => $output]
81  );
82  $this->output->writeln("Verifying Magento Admin...");
83  $adminUrlAnalyzerMessages = $this->runAdminUrlAnalyzer();
84  if (isset($adminUrlAnalyzerMessages['error']) === false) {
85  $this->output->outputMessages($this->urlAnalyzer->checkDomain($_ENV['app_backend_url']));
86  } else {
87  $this->output->outputMessages($adminUrlAnalyzerMessages);
88  }
89  $this->output->writeln("Admin verification finished.");
90  }
91 
97  public function runAdminUrlAnalyzer()
98  {
99  if (!isset($_ENV['app_backend_url'])) {
100  $messages['error'][] = 'app_backend_url parameter is absent in the phpunit.xml file. '
101  . 'Please, copy parameter from phpunit.xml.dist.';
102  return $messages;
103  }
104  $this->output->outputMessages($this->urlAnalyzer->fixLastSlash('app_backend_url'));
105  $url1 = $_ENV['app_backend_url'];
106  if (strpos($url1, '/index.php') !== false) {
107  $url2 = str_replace('/index.php', '', $url1);
108  } else {
109  $pattern = '/(\/\w+\/)$/';
110  $replacement = '/index.php$1';
111  $url2 = str_replace($url1, preg_replace($pattern, $replacement, $url1), $url1);
112  }
113  $urls = [$url1, $url2];
114  $isUrlValid = false;
115  foreach ($urls as $url) {
116  $_ENV['app_backend_url'] = $url;
117  try {
118  $config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->create(
119  \Magento\Mtf\Config\DataInterface::class
120  );
121  $curl = new BackendDecorator(new CurlTransport(), $config);
122  $response = $curl->read();
123  if (strpos($response, '404') !== false) {
124  break;
125  }
126  $curl->close();
127  $isUrlValid = true;
128  break;
129  } catch (\Exception $e) {
130  continue;
131  }
132  }
133  if ($isUrlValid == false) {
134  $messages['error'][] = 'Check correctness of app_backend_url in phpunit.xml.';
135  return $messages;
136  } elseif ($url1 != $_ENV['app_backend_url']) {
137  return $this->urlAnalyzer->resolveIndexPhpProblem($_ENV['app_backend_url']);
138  }
139  }
140 }
output($string, $level=INFO, $label='')
execute(InputInterface $input, OutputInterface $output)
$response
Definition: 404.php:11
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$objectManager
Definition: bootstrap.php:17
$pattern
Definition: website.php:22
$config
Definition: fraud_order.php:17
$replacement
Definition: website.php:23
__construct(ObjectManagerInterface $objectManager, UrlAnalyzer $urlAnalyzer)