Exemple #1
0
 public function makeQuery($functionToInvoke, $args)
 {
     if (!$this->isAuthenticated()) {
         drupal_set_message('TIP: <a href="/drupal/user/logout">Logout</a> and <a href="/drupal/user/login">log back in</a></a>');
         throw new \Exception('Not authenticated in MdwsDao instance ' . $this->instanceTimestamp . '(previous authentication was ' . $this->authenticationTimestamp . ')' . ": Must authenticate before requesting data>>>" . Context::debugGetCallerInfo(2, 10));
     }
     error_log('TODO:makeQuery  --- about to do stuff in makeQuery for ' . $functionToInvoke . '...');
     try {
         // use the DAO factory to obtain the correct SOAP client
         // use the previous SOAP request/response headers to set the ASP.NET_SessionID header if the facde has changed
         error_log('About to get getFacadeNameByFunction ' . microtime());
         $wsdlForFunction = MdwsDaoFactory::getFacadeNameByFunction($functionToInvoke);
         error_log('Done getting getFacadeNameByFunction ' . microtime());
         //if ($wsdlForFunction != $this->currentFacade) {   //Serialization issue with PHP SOAP will try to get new one eacvh time
         error_log('About got set properties of MDWS SOAP CLIENT ' . microtime());
         $this->currentFacade = $wsdlForFunction;
         $cookie = $this->mdwsClient->_cookies["ASP.NET_SessionId"][0];
         $this->mdwsClient = MdwsDaoFactory::getSoapClientByFunction($functionToInvoke);
         $this->mdwsClient->__setCookie("ASP.NET_SessionId", $cookie);
         //error_log(print_r($this->mdwsClient, true));
         error_log('Done setting properties of MDWS SOAP CLIENT ' . microtime());
         //}
         // functionToInvoke is the name of the SOAP call, args is the list of arguments
         // PHP seems to like this format (using the functionToInvoke string as the SOAP name) just fine!
         error_log('TODO:makeQuery  --- soap client looks like this>>>' . print_r($this->mdwsClient, TRUE));
         $soapResult = $this->mdwsClient->{$functionToInvoke}($args);
         // TO object is always stored in "soapCallResult". e.g. select result stored in 'selectResult'
         $resultVarName = strval($functionToInvoke) . "Result";
         // this block of code before the return $soapResult statement is error checking/auto-re-authentication
         if (isset($soapResult->{$resultVarName})) {
             $TOResult = $soapResult->{$resultVarName};
             error_log('TODO:makeQuery  --- soapResult in makeQuery okay?>>>' . isset($TOResult->fault));
             if (isset($TOResult->fault)) {
                 // TODO:makeQuery  - haven't tested this auto-reconnect code atl all. need to write tests
                 // we received a fault - might be a session timeout in which case we want to handle gracefully
                 error_log('TODO:makeQuery  --- deal with a fault?>>>' . $TOResult->fault->message);
                 if (strpos($TOResult->fault->message, MDWS_CXN_TIMEOUT_ERROR_MSG_1) === FALSE || strpos($TOResult->fault->message, MDWS_CXN_TIMEOUT_ERROR_MSG_2) === FALSE || strpos($TOResult->fault->message, MDWS_CXN_TIMEOUT_ERROR_MSG_3) === FALSE) {
                     // TODO:makeQuery  - determine where the creds will be stored - these vars are undefined
                     $this->initClient();
                     error_log('TODO:makeQuery  --- get the credentials now???>>>' . $TOResult->fault->message);
                     $this->connectAndLogin($this->userSiteId, $this->userAccessCode, $this->userVerifyCode);
                     return $this->makeQuery($functionToInvoke, $args);
                 } else {
                     error_log('TODO:makeQuery  --- about to throw exception in makeQuery>>>' . print_r($TOResult, TRUE));
                     throw new \Exception('MdwsDao->makeQuery unhandled exception: ' . $TOResult->fault->message);
                 }
                 //return NULL;    //20140707 - JAM: why is this returning null??
             } else {
                 error_log('TODO:makeQuery Good news --- no fault in makeQuery>>>' . $functionToInvoke);
             }
         }
         /*  Removed 20140815
             // check if call was "select" - cache selected patient ID, if so
             if ($functionToInvoke == 'select') {
                 error_log('Setting selected patient ID>>>[' . $soapResult->selectResult->localPid . ']');
                 $this->selectedPatient = $soapResult->selectResult->localPid;
                 error_log('Check result of setting selected patient ID>>>[' . $this->selectedPatient . ']');
             }
              */
         return $soapResult;
     } catch (\Exception $ex) {
         if (strpos($ex->getMessage(), "connection was forcibly closed")) {
             error_log('TODO:makeQuery  --- 2222 connection was closed makeQuery>>>' . $ex);
             $this->initClient();
             $this->connectAndLogin($this->userSiteId, $this->userAccessCode, $this->userVerifyCode);
             return $this->makeQuery($functionToInvoke, $args);
         } else {
             error_log('TODO:makeQuery  --- 2222 about to throw exception in makeQuery>>>' . print_r($TOResult, TRUE));
             throw $ex;
         }
     }
 }