config = $config; parent::__construct(); } /** * Implementation of FeedsImportBatch::getRaw(). */ public function getRaw() { // code largely taken from soapclient_test_submit() $param_str = preg_replace('/[\s]*=[\s]*/', '=', $this->config['arguments']); $params = split("\n", $param_str); $args = array(); foreach ($params as $param) { list($name, $value) = split('=', $param); if ( isset($value) ) { $args[$name] = trim($value); } else { $args[] = trim($name); } } $options = array(); $options['namespace'] = $this->config['namespace']; $options['use'] = ( $this->config['use'] == 0 ? 'encoded' : 'literal' ); $options['style'] = ( $this->config['style'] == 0 ? 'rpc' : 'document'); $result = soapclient_init_client($this->config['endpoint'], $this->config['wsdl'], $options); if ( $result['#error'] !== FALSE ) { throw new Exception(t('Error initializing SOAP client: !msg', array('!msg' => $result['#error']))); } $result = $result['#return']->call($this->config['function'], $args); if ( $result['#error'] !== FALSE ) { throw new Exception(t('SOAP fetch from @url failed with error: !msg', array('@url' => $this->config['endpoint'], '!msg' => $result['#error']))); } /*$result['#return'] is for me: Object( ${function}Result => Object( schema => LARGE STRING (schema document), any => LARGE STRING (xml document) )) We may be able to do something with the schema later... if Feeds has a possibility for 'mapping on import'. See http://drupal.org/node/651478 */ $key = $this->config['function'] . 'Result'; return $result['#return']->$key->any; } } /** * Fetches data via SOAP. */ class FeedsSOAPFetcher extends FeedsFetcher { /** * Implementation of FeedsFetcher::fetch(). */ public function fetch(FeedsSource $source) { $source_config = $source->getConfigFor($this); return new FeedsSOAPBatch($source_config); } /** * Source form. */ public function sourceForm($source_config) { $form = array(); $form['endpoint'] = array( '#type' => 'textfield', '#title' => t('SOAP server endpoint URL'), '#size' => 60, '#maxlength' => 256, '#description' => t('Enter the absolute endpoint URL of the SOAP Server service. If WSDL is being used (see SOAPFetcher settings), this will be the URL to retrieve the WSDL.'), '#default_value' => isset($source_config['endpoint']) ? $source_config['endpoint'] : '', '#required' => TRUE ); $form['wsdl'] = array( '#type' => 'checkbox', '#title' => t('Use WSDL?'), '#default_value' => $source_config['wsdl'], ); $form['namespace'] = array( '#type' => 'textfield', '#title' => t('Target Namespace'), '#default_value' => $source_config['namespace'], '#size' => 60, '#maxlength' => 256, '#description' => t('If WSDL is not used, enter the target namespace URI here. Otherwise, leave it blank.'), ); $form['use'] = array( '#type' => 'radios', '#title' => 'Use', '#default_value' => $source_config['use'], '#options' => array('encoded', 'literal'), '#description' => t('Specify how the SOAP client serializes the message.'), ); /* This always needs to be 'document', I guess? $form['style'] = array( '#type' => 'radios', '#title' => 'Style', '#default_value' => 0, '#options' => array('rpc', 'document'), '#description' => t('Specify the style of SOAP call.'), );*/ $form['function'] = array( '#type' => 'textfield', '#title' => t('SOAP Function'), '#size' => 60, '#maxlength' => 256, '#description' => t('Enter the function name to be called.'), '#default_value' => isset($source_config['function']) ? $source_config['function'] : '', '#required' => TRUE ); $form['arguments'] = array( '#type' => 'textarea', '#title' => t('Arguments'), '#cols' => 60, '#rows' => 10, '#description' => t('Enter the arguments of the function. One argument per line, '. 'for named arguments, the format of name=value may be used.'), '#default_value' => isset($source_config['arguments']) ? $source_config['arguments'] : '', ); return $form; } }