From d7779dc3361b18f71bc6f4f386d060154e30292e Mon Sep 17 00:00:00 2001 From: Vaidas Bagdonas Date: Mon, 6 Jul 2020 14:39:23 +0200 Subject: [PATCH 1/2] update RefreshWsdlCommand to work again --- composer.json | 3 +- src/Command/RefreshWsdlCommand.php | 64 ++++++++++++++++-------------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index b89c129..f6d83c3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ }, "require": { "php": ">=7.2", - "comsave/soap-client": "0.1.13" + "comsave/soap-client": "0.1.13", + "guzzlehttp/guzzle": "^6.0" }, "require-dev": { "phpunit/php-code-coverage": "^6.0", diff --git a/src/Command/RefreshWsdlCommand.php b/src/Command/RefreshWsdlCommand.php index e602c02..a322259 100644 --- a/src/Command/RefreshWsdlCommand.php +++ b/src/Command/RefreshWsdlCommand.php @@ -6,7 +6,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\ArrayInput; -use Guzzle\Http\Client; +use GuzzleHttp\Client; /** * Fetch latest WSDL from Salesforce and store it locally @@ -43,45 +43,49 @@ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Updating the WSDL file'); + $this->downloadWsdl(); + + if (!$input->getOption('no-cache-clear')) { + $command = $this->getApplication()->find('cache:clear'); + + $arguments = array( + 'command' => 'cache:clear', + ); + $input = new ArrayInput($arguments); + $command->run($input, $output); + } + } + + public function downloadWsdl(): void + { + /** @var \Phpforce\SoapClient\Client $client */ $client = $this->getContainer()->get('phpforce.soap_client'); // Get current session id $loginResult = $client->getLoginResult(); $sessionId = $loginResult->getSessionId(); - $instance = $loginResult->getServerInstance(); - - $url = sprintf('https://%s.salesforce.com', $instance); - $guzzle = new Client( - $url, - array( - 'curl.CURLOPT_SSL_VERIFYHOST' => false, - 'curl.CURLOPT_SSL_VERIFYPEER' => false, - 'curl.CURLOPT_SSLVERSION' => 6, - ) - ); // type=* for enterprise WSDL - $request = $guzzle->get('/soap/wsdl.jsp?type=*'); - $request->addCookie('sid', $sessionId); - $response = $request->send(); - - $wsdl = $response->getBody(); - $wsdlFile = $this->getContainer() - ->getParameter('phpforce.soap_client.wsdl'); + $response = (new Client())->request('GET', vsprintf('https://%s.my.salesforce.com/soap/wsdl.jsp?type=*', [ + $loginResult->getServerInstance() + ]), [ + 'headers' => [ + 'Cookie' => sprintf('sid=%s', $sessionId), + ], + 'curl' => [ + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_SSLVERSION => 6, + ] + ]); - // Write WSDL - file_put_contents($wsdlFile, $wsdl); - - // Run clear cache command - if (!$input->getOption('no-cache-clear')) { - $command = $this->getApplication()->find('cache:clear'); + $wsdlFile = $this->getContainer()->getParameter('phpforce.soap_client.wsdl'); - $arguments = array( - 'command' => 'cache:clear' - ); - $input = new ArrayInput($arguments); - $command->run($input, $output); + if(!simplexml_load_string((string)$response->getBody())) { + throw new \Exception('The downloaded WSDL is invalid. ' . sprintf('`%s`', (string)$response->getBody())); } + + file_put_contents($wsdlFile, (string)$response->getBody()); } } From 14c9902df9649de8eb3dadbf7619d18515aa22da Mon Sep 17 00:00:00 2001 From: Vaidas Bagdonas Date: Mon, 6 Jul 2020 15:01:12 +0200 Subject: [PATCH 2/2] update soap-client --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f6d83c3..13b26c8 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }, "require": { "php": ">=7.2", - "comsave/soap-client": "0.1.13", + "comsave/soap-client": "^0.2.1", "guzzlehttp/guzzle": "^6.0" }, "require-dev": {