PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/Command/RefreshWsdlCommand.php

https://bitbucket.org/cerilo/salesforce-bundle
PHP | 86 lines | 59 code | 12 blank | 15 comment | 1 complexity | 7e96f385af024021bc44966bcfbf3ada MD5 | raw file
  1. <?php
  2. namespace Phpforce\SalesforceBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputOption;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use Symfony\Component\Console\Input\ArrayInput;
  8. use Guzzle\Http\Client;
  9. /**
  10. * Fetch latest WSDL from Salesforce and store it locally
  11. *
  12. * @author David de Boer <david@ddeboer.nl>
  13. */
  14. class RefreshWsdlCommand extends ContainerAwareCommand
  15. {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. protected function configure()
  20. {
  21. $this
  22. ->setName('phpforce:refresh-wsdl')
  23. ->setDescription('Refresh Salesforce WSDL')
  24. ->setHelp(
  25. 'Refreshing the WSDL itself requires a WSDL, so when using this'
  26. . 'command for the first time, please download the WSDL '
  27. . 'manually from Salesforce'
  28. )
  29. ->addOption(
  30. 'no-cache-clear',
  31. 'c',
  32. InputOption::VALUE_NONE,
  33. 'Do not clear cache after refreshing WSDL'
  34. );
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. protected function execute(InputInterface $input, OutputInterface $output)
  40. {
  41. $output->writeln('Updating the WSDL file');
  42. $client = $this->getContainer()->get('phpforce.soap_client');
  43. // Get current session id
  44. $loginResult = $client->getLoginResult();
  45. $sessionId = $loginResult->getSessionId();
  46. $instance = $loginResult->getServerInstance();
  47. $url = sprintf('https://%s.salesforce.com', $instance);
  48. $guzzle = new Client(
  49. $url,
  50. array(
  51. 'curl.CURLOPT_SSL_VERIFYHOST' => false,
  52. 'curl.CURLOPT_SSL_VERIFYPEER' => false,
  53. )
  54. );
  55. // type=* for enterprise WSDL
  56. $request = $guzzle->get('/soap/wsdl.jsp?type=*');
  57. $request->addCookie('sid', $sessionId);
  58. $response = $request->send();
  59. $wsdl = $response->getBody();
  60. $wsdlFile = $this->getContainer()
  61. ->getParameter('phpforce.soap_client.wsdl');
  62. // Write WSDL
  63. file_put_contents($wsdlFile, $wsdl);
  64. // Run clear cache command
  65. if (!$input->getOption('no-cache-clear')) {
  66. $command = $this->getApplication()->find('cache:clear');
  67. $arguments = array(
  68. 'command' => 'cache:clear'
  69. );
  70. $input = new ArrayInput($arguments);
  71. $command->run($input, $output);
  72. }
  73. }
  74. }