Skip to content

Commit

Permalink
Merge pull request #1 from comsave/staging
Browse files Browse the repository at this point in the history
update RefreshWsdlCommand to work again
  • Loading branch information
Gyvastis authored Jul 6, 2020
2 parents 595d077 + 14c9902 commit 12b9cc3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"require": {
"php": ">=7.2",
"comsave/soap-client": "0.1.13"
"comsave/soap-client": "^0.2.1",
"guzzlehttp/guzzle": "^6.0"
},
"require-dev": {
"phpunit/php-code-coverage": "^6.0",
Expand Down
64 changes: 34 additions & 30 deletions src/Command/RefreshWsdlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 12b9cc3

Please sign in to comment.