From 33ba3f3a421782ab057793fdf7556563f10196d7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 24 Jun 2009 17:50:49 -0400 Subject: [PATCH] switch to better option handling --- classes/DailyImageWidget.php | 26 +++++++++++--------------- test/DailyImageWidgetTest.php | 4 ++-- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/classes/DailyImageWidget.php b/classes/DailyImageWidget.php index f5fc529..1ebfda1 100644 --- a/classes/DailyImageWidget.php +++ b/classes/DailyImageWidget.php @@ -260,22 +260,18 @@ class DailyImageWidget { * @return array|boolean The cached data or false upon failure. */ function _get_cached_data() { - $result = get_option('hubblesite-daily-image-cache'); - - if (is_string($result)) { - if (($data = @unserialize($result)) !== false) { - list($timestamp, $cached_data) = $data; + if (($result = get_option('hubblesite-daily-image-cache')) !== false) { + list($timestamp, $cached_data) = $result; + + if (($timestamp + $this->_cache_time) > time()) { + $is_valid = true; + foreach ($this->_valid_column_names as $field) { + if (!isset($cached_data[$field])) { $is_valid = false; break; } + } - if (($timestamp + $this->_cache_time) > time()) { - $is_valid = true; - foreach ($this->_valid_column_names as $field) { - if (!isset($cached_data[$field])) { $is_valid = false; break; } - } - - if ($is_valid) { - $this->data = $cached_data; - return $cached_data; - } + if ($is_valid) { + $this->data = $cached_data; + return $cached_data; } } } diff --git a/test/DailyImageWidgetTest.php b/test/DailyImageWidgetTest.php index 3cbed05..2f503cb 100644 --- a/test/DailyImageWidgetTest.php +++ b/test/DailyImageWidgetTest.php @@ -256,11 +256,11 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase { function testGetCachedData() { $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()); $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()); update_option('hubblesite-daily-image-cache', null);