Esempio n. 1
0
 /**
  * Generate WSDL content and save it to cache.
  *
  * @param array $requestedResources
  * @param string $endpointUrl
  * @return string
  * @throws Mage_Webapi_Exception
  */
 public function handle($requestedResources, $endpointUrl)
 {
     /** Sort requested resources by names to prevent caching of the same wsdl file more than once. */
     ksort($requestedResources);
     $cacheId = self::WSDL_CACHE_ID . hash('md5', serialize($requestedResources));
     if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) {
         $cachedWsdlContent = $this->_cache->load($cacheId);
         if ($cachedWsdlContent !== false) {
             return $cachedWsdlContent;
         }
     }
     $resources = array();
     try {
         foreach ($requestedResources as $resourceName => $resourceVersion) {
             $resources[$resourceName] = $this->_apiConfig->getResourceDataMerged($resourceName, $resourceVersion);
         }
     } catch (Exception $e) {
         throw new Mage_Webapi_Exception($e->getMessage(), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     }
     $wsdlContent = $this->generate($resources, $endpointUrl);
     if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) {
         $this->_cache->save($wsdlContent, $cacheId, array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG));
     }
     return $wsdlContent;
 }
Esempio n. 2
0
 /**
  * Validate nonce and timestamp pair.
  * Write nonce to storage if it's valid.
  *
  * @param string $nonce
  * @param int $timestamp
  * @throws Mage_Webapi_Model_Soap_Security_UsernameToken_TimestampRefusedException
  * @throws Mage_Webapi_Model_Soap_Security_UsernameToken_NonceUsedException
  */
 public function validateNonce($nonce, $timestamp)
 {
     $timestamp = (int) $timestamp;
     $isNonceUsed = $timestamp <= time() - self::NONCE_TTL;
     $isNonceFromFuture = $timestamp > time() + self::NONCE_FROM_FUTURE_ACCEPTABLE_RANGE;
     if ($timestamp <= 0 || $isNonceUsed || $isNonceFromFuture) {
         throw new Mage_Webapi_Model_Soap_Security_UsernameToken_TimestampRefusedException();
     }
     if ($this->_cacheInstance->load($this->getNonceCacheId($nonce)) == $timestamp) {
         throw new Mage_Webapi_Model_Soap_Security_UsernameToken_NonceUsedException();
     }
     $nonceCacheTtl = self::NONCE_TTL + self::NONCE_FROM_FUTURE_ACCEPTABLE_RANGE;
     $this->_cacheInstance->save($timestamp, $this->getNonceCacheId($nonce), array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG), $nonceCacheTtl);
 }
Esempio n. 3
0
 /**
  * Load system configuration
  *
  * @return Mage_Backend_Model_Config_Structure
  */
 public function getConfiguration()
 {
     if ($this->_cache->canUse('config')) {
         $cache = $this->_cache->load(self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE);
         if ($cache) {
             return unserialize($cache);
         }
     }
     $fileNames = $this->_appConfig->getModuleConfigurationFiles('adminhtml' . DIRECTORY_SEPARATOR . 'system.xml');
     $config = $this->_appConfig->getModelInstance('Mage_Backend_Model_Config_Structure', array('sourceFiles' => $fileNames));
     if ($this->_cache->canUse('config')) {
         $this->_cache->save(serialize($config), self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE, array(Mage_Core_Model_Config::CACHE_TAG));
     }
     return $config;
 }
Esempio n. 4
0
 /**
  * @param Mage_Core_Model_Config $config
  * @param Mage_Core_Model_Cache $cache
  * @param Mage_Backend_Model_Config_Structure_Converter $structureConverter
  * @param bool $runtimeValidation
  */
 public function __construct(Mage_Core_Model_Config $config, Mage_Core_Model_Cache $cache, Mage_Backend_Model_Config_Structure_Converter $structureConverter, $runtimeValidation = true)
 {
     $this->_runtimeValidation = $runtimeValidation;
     $this->_converter = $structureConverter;
     $this->_config = $config;
     if ($cache->canUse('config') && ($cachedData = $cache->load(self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE))) {
         $this->_data = unserialize($cachedData);
     } else {
         $fileNames = $this->_config->getModuleConfigurationFiles('adminhtml' . DIRECTORY_SEPARATOR . 'system.xml');
         parent::__construct($fileNames);
         if ($cache->canUse('config')) {
             $cache->save(serialize($this->_data), self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE, array(Mage_Core_Model_Config::CACHE_TAG));
         }
     }
 }
Esempio n. 5
0
 protected function _saveCache($xml)
 {
     if ($this->_cache->canUse('config')) {
         $this->_cache->save($xml, self::CACHE_ID, array(Mage_Core_Model_Config::CACHE_TAG));
     }
     return $this;
 }
Esempio n. 6
0
 public function clean($tags = array())
 {
     $start = microtime(true) * 1000;
     $res = parent::clean($tags);
     $this->appendLog(self::TYPE_CLEAN, implode(';', $tags), round(microtime(true) * 1000 - $start));
     return $res;
 }
Esempio n. 7
0
 /**
  * Save ACL resources into the cache
  *
  * @param $data
  * @return Mage_Backend_Model_Acl_Config
  */
 private function _saveAclResourcesToCache($data)
 {
     if ($this->_cache->canUse('config')) {
         $this->_cache->save($data, self::CACHE_ID, array(Mage_Core_Model_Config::CACHE_TAG));
     }
     return $this;
 }
Esempio n. 8
0
 /**
  * Disable some cache types in VDE mode
  */
 protected function _disableCache()
 {
     foreach ($this->_dataHelper->getDisabledCacheTypes() as $cacheCode) {
         if ($this->_cacheManager->canUse($cacheCode)) {
             $this->_cacheManager->banUse($cacheCode);
         }
     }
 }
Esempio n. 9
0
 public function testProcessRequestTrue()
 {
     $response = new Zend_Controller_Response_Http();
     $response->setBody('Initial response body.');
     $this->_requestProcessor->expects($this->any())->method('extractContent')->will($this->returnValue('Additional response text.'));
     $this->assertTrue($this->_model->processRequest($response));
     $this->assertEquals('Initial response body.Additional response text.', $response->getBody());
 }
Esempio n. 10
0
 protected function _setAdditionalExpectations()
 {
     $this->_dataHelper->expects($this->once())->method('getDisabledCacheTypes')->will($this->returnValue($this->_cacheTypes));
     $this->_cacheManager->expects($this->at(0))->method('canUse')->with('type1')->will($this->returnValue(true));
     $this->_cacheManager->expects($this->at(1))->method('banUse')->with('type1')->will($this->returnSelf());
     $this->_cacheManager->expects($this->at(2))->method('canUse')->with('type2')->will($this->returnValue(true));
     $this->_cacheManager->expects($this->at(3))->method('banUse')->with('type2')->will($this->returnSelf());
 }
Esempio n. 11
0
 public function __construct()
 {
     $node = Mage::getConfig()->getNode('global/fpc2');
     $options = array();
     if ($node) {
         $options = $node->asArray();
     }
     parent::__construct($options);
 }
Esempio n. 12
0
 /**
  * Clear request path cache by tag
  * (used for redirects invalidation)
  *
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function clearRequestCacheByTag(Varien_Event_Observer $observer)
 {
     if (!$this->isCacheEnabled()) {
         return $this;
     }
     $redirect = $observer->getEvent()->getRedirect();
     $this->_cacheInstance->clean(array(Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect->getData('identifier')), Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect->getData('target_path')), Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect->getOrigData('identifier')), Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect->getOrigData('target_path'))));
     return $this;
 }
Esempio n. 13
0
 /**
  * Test handle method with exception.
  */
 public function testHandleWithException()
 {
     /** Mock cache canUse method to return false. */
     $this->_cacheMock->expects($this->once())->method('canUse')->will($this->returnValue(false));
     $requestedResources = array('res1' => 'v1');
     $exception = new LogicException('getResourceDataMerged Exception');
     $this->_resourceConfigMock->expects($this->once())->method('getResourceDataMerged')->will($this->throwException($exception));
     $this->setExpectedException('Mage_Webapi_Exception', 'getResourceDataMerged Exception', Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     $this->_autoDiscover->handle($requestedResources, 'http://magento.host');
 }
Esempio n. 14
0
 /**
  * @covers Mage_Backend_Model_Menu_Config::getMenu
  */
 public function testGetMenuWhenCacheEnabledAndCleaned()
 {
     $xmlString = '<?xml version="1.0" encoding="utf-8"?><config><menu></menu></config>';
     $this->_appConfigMock->expects($this->any())->method('getModelInstance')->will($this->returnCallback(array($this, 'getModelInstance')));
     $this->_cacheInstanceMock->expects($this->any())->method('canUse')->will($this->returnValue(true));
     $this->_cacheInstanceMock->expects($this->exactly(1))->method('load')->will($this->returnValue(null));
     $this->_domDocumentMock->expects($this->exactly(1))->method('saveXML')->will($this->returnValue('<?xml version="1.0" encoding="utf-8"?><config><menu></menu></config>'));
     $this->_configMenuMock->expects($this->exactly(1))->method('getMergedConfig')->will($this->returnValue($this->_domDocumentMock));
     $this->_cacheInstanceMock->expects($this->exactly(1))->method('save')->with($this->equalTo($xmlString));
     $this->_model->getMenu();
 }
Esempio n. 15
0
 /**
  *
  */
 public function __construct()
 {
     /*
      * If the version of Zend Framework is older than 1.12, fallback to the
      * legacy cache settings.
      * See http://framework.zend.com/issues/browse/ZF-12047
      */
     if (Zend_Version::compareVersion('1.12.0') > 0) {
         $this->_defaultBackendOptions = $this->_legacyDefaultBackendOptions;
     }
     $node = Mage::getConfig()->getNode('global/fpc');
     $options = array();
     if ($node) {
         $options = $node->asArray();
     }
     parent::__construct($options);
 }
Esempio n. 16
0
 /**
  * @param string $id
  * @return string
  */
 public function load($id)
 {
     $data = parent::load($id);
     $compressLevel = Mage::getStoreConfig(self::GZCOMPRESS_LEVEL_XML_PATH);
     if ($data !== false && $compressLevel != -2) {
         $data = gzuncompress($data);
     }
     return $data;
 }
Esempio n. 17
0
 /**
  * Save cache usage settings
  *
  * @param array $data
  * @return Mage_Core_Model_App
  */
 public function saveUseCache($data)
 {
     $this->_cache->saveOptions($data);
     return $this;
 }
Esempio n. 18
0
 /**
  * Remove model onject related cache
  *
  * @return Mage_Core_Model_Abstract
  */
 public function cleanModelCache()
 {
     $tags = $this->getCacheTags();
     if ($tags !== false) {
         $this->_cacheManager->clean($tags);
     }
     return $this;
 }
Esempio n. 19
0
 /**
  * Save data to cache if it is enabled.
  */
 protected function _saveDataToCache()
 {
     if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) {
         $this->_cache->save(serialize($this->_data), $this->getCacheId(), array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG));
     }
 }
Esempio n. 20
0
 /**
  * @param string $id
  * @return boolean|\Lesti_Fpc_Model_Fpc_CacheItem
  */
 public function load($id)
 {
     $data = parent::load($id);
     if ($data === false) {
         return false;
     }
     $compressLevel = Mage::getStoreConfig(self::GZCOMPRESS_LEVEL_XML_PATH);
     if ($data !== false && $compressLevel != -2) {
         $data = gzuncompress($data);
     }
     $data = unserialize($data);
     return new Lesti_Fpc_Model_Fpc_CacheItem($data[0], $data[1], $data[2]);
 }
Esempio n. 21
0
 public function testGetDbAdapter()
 {
     $this->assertInstanceOf('Zend_Db_Adapter_Abstract', $this->_model->getDbAdapter());
 }
Esempio n. 22
0
 public function testProcessRequestTrue()
 {
     /**
     if (!Magento_Test_Bootstrap::canTestHeaders()) {
         $this->markTestSkipped('Test requires to send headers.');
     }
     */
     $model = new Mage_Core_Model_Cache(array('request_processors' => array('Mage_Core_Model_CacheTestRequestProcessor')));
     Mage_Core_Model_CacheTestRequestProcessor::$isEnabled = true;
     $this->assertTrue($model->processRequest());
 }
Esempio n. 23
0
 public function load($id)
 {
     $content = parent::load($id);
     if ($content) {
         $prefixLen = strlen(self::COMPRESSION_PREFIX);
         if (substr($content, 0, $prefixLen) == self::COMPRESSION_PREFIX) {
             $content = gzuncompress(base64_decode(substr($content, $prefixLen)));
         }
     }
     return $content;
 }