oxonlinemoduleversionnotifier.php

Go to the documentation of this file.
00001 <?php
00002 
00012 class oxOnlineModuleVersionNotifier
00013 {
00014 
00020     protected $_sProtocolversion = '1.0';
00021 
00022 
00028     protected $_sWebServiceUrl = 'https://omvn.oxid-esales.com/check.php';
00029 
00035     protected $_sRawResponseMessage = '';
00036 
00042     protected $_aModules = array();
00043 
00049     protected $_blIsException = false;
00050 
00056     public function setModules($aModules)
00057     {
00058         $this->_aModules = $aModules;
00059     }
00060 
00066     public function getModules()
00067     {
00068         return $this->_aModules;
00069     }
00070 
00076     public function setRawResponseMessage($sRawResponseMessage)
00077     {
00078         $this->_sRawResponseMessage = $sRawResponseMessage;
00079     }
00080 
00086     public function getRawResponseMessage()
00087     {
00088         return $this->_sRawResponseMessage;
00089     }
00090 
00096     public function setWebServiceUrl($sWebServiceUrl)
00097     {
00098         $this->_sWebServiceUrl = $sWebServiceUrl;
00099     }
00100 
00106     public function getWebServiceUrl()
00107     {
00108         return $this->_sWebServiceUrl;
00109     }
00110 
00116     public function isException() {
00117         return $this->_blIsException;
00118     }
00119 
00125     protected function _setIsException($blIsException)
00126     {
00127         $this->_blIsException = $blIsException;
00128     }
00129 
00135     protected function _prepareModulesInformation()
00136     {
00137         $aPreparedModules = array();
00138 
00139         $aModules = oxRegistry::getConfig()->getConfigParam('aModulePaths');
00140         if( !is_array($aModules) ) {
00141             return;
00142         }
00143 
00144         foreach( $aModules as $sModule ) {
00145             $oModule = oxNew('oxModule');
00146             if (!$oModule->load($sModule)) {
00147                 continue;
00148             }
00149 
00150             $oPreparedModule = new stdClass();
00151             $oPreparedModule->id = $oModule->getId();
00152             $oPreparedModule->version = $oModule->getInfo('version');
00153 
00154             $oPreparedModule->activeInShops = new stdClass();
00155             $oPreparedModule->activeInShops->activeInShop = array( ($oModule->isActive() ? oxRegistry::getConfig()->getShopUrl() : null) );
00156 
00157             $aPreparedModules[] = $oPreparedModule;
00158         }
00159 
00160         $this->setModules($aPreparedModules);
00161     }
00162 
00172     protected function _doRequest($oRequestParams)
00173     {
00174         $sOutput = "";
00175 
00176         $oXml = oxNew('oxSimpleXml');
00177         $sXml = $oXml->objectToXml($oRequestParams, 'omvnRequest');
00178 
00179         // send request to web service
00180         try {
00181             $oCurl = oxNew( 'oxCurl' );
00182             $oCurl->setMethod( 'POST' );
00183             $oCurl->setUrl( $this->getWebServiceUrl() );
00184             $oCurl->setParameters( array("xmlRequest" => $sXml) );
00185             $sOutput = $oCurl->execute();
00186         } catch (Exception $oEx) {
00187             throw new oxException('OMVN_ERROR_REQUEST_FAILED');
00188         }
00189         return $sOutput;
00190     }
00191 
00197     protected function _sendRequestMessage()
00198     {
00199         $this->_prepareModulesInformation();
00200 
00201         // build request parameters
00202         $oRequestParams = new stdClass();
00203 
00204         $oRequestParams->modules = new stdClass();
00205         $oRequestParams->modules->module = $this->getModules();
00206 
00207         $oRequestParams->edition = oxRegistry::getConfig()->getEdition();
00208         $oRequestParams->version = oxRegistry::getConfig()->getVersion();
00209         $oRequestParams->shopurl = oxRegistry::getConfig()->getShopUrl();
00210         $oRequestParams->pversion = $this->_sProtocolversion;
00211 
00212 
00213         if ( !$sOutput = $this->_doRequest($oRequestParams) ){
00214             throw new oxException('OMVN_ERROR_REQUEST_FAILED');
00215         }
00216         $this->setRawResponseMessage($sOutput);
00217     }
00218 
00224     public function versionNotify()
00225     {
00226         $this->_setIsException(false);
00227 
00228         try {
00229             $this->_sendRequestMessage();
00230             return true;
00231 
00232         } catch ( oxException $oEx ) {
00233             $this->_setIsException(true);
00234             return false;
00235         }
00236     }
00237 }