Changeset 329
- Timestamp:
- May 6, 2008 9:11:59 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Currency.inc.php
r328 r329 22 22 // Configuration parameters for this object. 23 23 var $_params = array( 24 'cache_result' => false,24 'cache_result' => true, 25 25 'cache_dir' => '', 26 26 'cache_age' => 28800, // 8 hours. … … 47 47 48 48 // Setup cache directory. 49 if ('' == $this->getParam('cache_dir')) { 50 // Use a sane default cache directory. 51 $this->setParam(array('cache_dir' => '/tmp/' . md5(COMMON_BASE))); 52 } 53 if (!is_dir($this->getParam('cache_dir'))) { 54 $app->logMsg(sprintf('Creating cache_dir: %s', $this->getParam('cache_dir')), LOG_INFO, __FILE__, __LINE__); 55 if (!mkdir($this->getParam('cache_dir'))) { 56 $app->logMsg(sprintf('Could not create cache_dir: %s', $this->getParam('cache_dir')), LOG_WARNING, __FILE__, __LINE__); 49 if ($this->getParam('cache_result')) { 50 if ('' == $this->getParam('cache_dir')) { 51 // Use a sane default cache directory. 52 $this->setParam(array('cache_dir' => '/tmp/xcache_' . md5(COMMON_BASE))); 53 } 54 if (!is_dir($this->getParam('cache_dir'))) { 55 $app->logMsg(sprintf('Creating cache_dir: %s', $this->getParam('cache_dir')), LOG_INFO, __FILE__, __LINE__); 56 if (!mkdir($this->getParam('cache_dir'))) { 57 $app->logMsg(sprintf('Could not create cache_dir: %s', $this->getParam('cache_dir')), LOG_WARNING, __FILE__, __LINE__); 58 } 57 59 } 58 60 } … … 98 100 * 99 101 * @access public 100 * @param 101 * @return 102 * @param float Base amount to convert from. 103 * @param string 3-letter currency code to convert from. 104 * @param string 3-letter currency code to convert to. 105 * @return mixed Float exchange rate value, or false on error. 102 106 * @author Quinn Comendant <quinn@strangecode.com> 103 107 * @version 1.0 … … 112 116 if (!$this->getParam('cache_result') || !$cache_file_mtime || $cache_file_mtime < time() - $this->getParam('cache_age')) { 113 117 // Get fresh data and create cached file if missing or expired. 118 $app->logMsg(sprintf('Getting fresh currency exchange rates: %s-to-%s', $base, $target), LOG_DEBUG, __FILE__, __LINE__); 114 119 $value = $this->_performAPICall('getValue', array( 115 120 'amount' => $amount, … … 117 122 'target' => $target 118 123 )); 119 if (false !== $value) {124 if (false === $value || !is_numeric($value)) { 120 125 // Failed retreiving SOAP value. Use cached copy for now. 121 $app->logMsg(sprintf('Failed getting SOAP currency value: %s-to-%s', $base, $target), LOG_NOTICE, __FILE__, __LINE__);126 $app->logMsg(sprintf('Failed getting SOAP currency exchange rates: %s-to-%s, using cached copy', $base, $target), LOG_NOTICE, __FILE__, __LINE__); 122 127 if (!$value = file_get_contents($cache_file_path)) { 123 128 $app->logMsg(sprintf('Failed reading target rate file: %s', $cache_file_path), LOG_ERR, __FILE__, __LINE__); 129 return false; 124 130 } 125 131 } else if ($this->getParam('cache_result') && !file_put_contents($cache_file_path, $value, LOCK_EX)) { 126 132 $app->logMsg(sprintf('Failed writing to target rate file: %s', $cache_file_path), LOG_ERR, __FILE__, __LINE__); 133 return false; 127 134 } 128 135 } else { 136 $app->logMsg(sprintf('Getting cached currency exchange rates: %s-to-%s', $base, $target), LOG_DEBUG, __FILE__, __LINE__); 129 137 if (!$value = file_get_contents($cache_file_path)) { 130 138 $app->logMsg(sprintf('Failed reading target rate file: %s', $cache_file_path), LOG_ERR, __FILE__, __LINE__); 139 return false; 131 140 } 132 141 }
Note: See TracChangeset
for help on using the changeset viewer.