switch to better option handling

This commit is contained in:
John Bintz 2009-06-24 17:50:49 -04:00
parent cb4c7cd68e
commit 33ba3f3a42
2 changed files with 13 additions and 17 deletions

View File

@ -260,11 +260,8 @@ class DailyImageWidget {
* @return array|boolean The cached data or false upon failure. * @return array|boolean The cached data or false upon failure.
*/ */
function _get_cached_data() { function _get_cached_data() {
$result = get_option('hubblesite-daily-image-cache'); if (($result = get_option('hubblesite-daily-image-cache')) !== false) {
list($timestamp, $cached_data) = $result;
if (is_string($result)) {
if (($data = @unserialize($result)) !== false) {
list($timestamp, $cached_data) = $data;
if (($timestamp + $this->_cache_time) > time()) { if (($timestamp + $this->_cache_time) > time()) {
$is_valid = true; $is_valid = true;
@ -278,7 +275,6 @@ class DailyImageWidget {
} }
} }
} }
}
return false; return false;
} }

View File

@ -256,11 +256,11 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
function testGetCachedData() { function testGetCachedData() {
$test_time = time() + 86500; $test_time = time() + 86500;
update_option('hubblesite-daily-image-cache', serialize(array($test_time, $this->sample_data))); update_option('hubblesite-daily-image-cache', array($test_time, $this->sample_data));
$this->assertEquals($this->sample_data, $this->diw->_get_cached_data()); $this->assertEquals($this->sample_data, $this->diw->_get_cached_data());
$test_time = time() - 86500; $test_time = time() - 86500;
update_option('hubblesite-daily-image-cache', serialize(array($test_time, $this->sample_data))); update_option('hubblesite-daily-image-cache', array($test_time, $this->sample_data));
$this->assertEquals(false, $this->diw->_get_cached_data()); $this->assertEquals(false, $this->diw->_get_cached_data());
update_option('hubblesite-daily-image-cache', null); update_option('hubblesite-daily-image-cache', null);