From 4e12de40f87725c842ba1e987047edf79006525c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Aug 2014 07:19:37 +0200 Subject: [PATCH 1/4] Fix 'PHP Notice: unserialize(): Error at offset ...' errors These kind of errors are caused most of the time by: - unescaped quotes/slashes etc - miscounted unicode characters The change in this commit fixes this, though it does mean the cache directory has to be cleared completely (once - on upgrade to the version which includes this fix) for the fix to take effect. --- includes/Wpup/FileCache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Wpup/FileCache.php b/includes/Wpup/FileCache.php index aa76b2c..57c166e 100644 --- a/includes/Wpup/FileCache.php +++ b/includes/Wpup/FileCache.php @@ -18,7 +18,7 @@ public function __construct($cacheDirectory) { public function get($key) { $filename = $this->getCacheFilename($key); if ( is_file($filename) && is_readable($filename) ) { - $cache = unserialize(file_get_contents($filename)); + $cache = unserialize(base64_decode(file_get_contents($filename))); if ( $cache['expiration_time'] < time() ) { return null; //Cache expired. } else { @@ -41,7 +41,7 @@ public function set($key, $value, $expiration = 0) { 'expiration_time' => time() + $expiration, 'value' => $value, ); - file_put_contents($this->getCacheFilename($key), serialize($cache)); + file_put_contents($this->getCacheFilename($key), base64_encode(serialize($cache))); } /** From df7a39d88008f5fc962855f3b3ba55ebd93cc9cc Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 31 Aug 2014 08:47:28 +0200 Subject: [PATCH 2/4] Make cache files identifiable again as with the base64 encoding, there was no way to determine which package the cache referred to which makes selective (manual) deletion difficult. --- includes/Wpup/Package.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Wpup/Package.php b/includes/Wpup/Package.php index 082a928..36c5840 100644 --- a/includes/Wpup/Package.php +++ b/includes/Wpup/Package.php @@ -68,7 +68,7 @@ public function getMetadata() { */ public static function fromArchive($filename, $slug = null, Wpup_Cache $cache = null) { $modified = filemtime($filename); - $cacheKey = 'metadata-' . md5($filename . '|' . filesize($filename) . '|' . $modified); + $cacheKey = 'metadata-' . $slug . '-' . md5($filename . '|' . filesize($filename) . '|' . $modified); $metadata = null; //Try the cache first. From 2584169052dd1fa6b50c94a9ed77caa55477f5cc Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 28 Sep 2014 18:45:51 +0200 Subject: [PATCH 3/4] Added documentation about the use of base64 encoding --- includes/Wpup/FileCache.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/Wpup/FileCache.php b/includes/Wpup/FileCache.php index 57c166e..11bd33f 100644 --- a/includes/Wpup/FileCache.php +++ b/includes/Wpup/FileCache.php @@ -1,6 +1,14 @@ Date: Sun, 28 Sep 2014 18:46:17 +0200 Subject: [PATCH 4/4] Added 'b64' indicator to cache file name --- includes/Wpup/Package.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Wpup/Package.php b/includes/Wpup/Package.php index 36c5840..8d4617c 100644 --- a/includes/Wpup/Package.php +++ b/includes/Wpup/Package.php @@ -68,7 +68,7 @@ public function getMetadata() { */ public static function fromArchive($filename, $slug = null, Wpup_Cache $cache = null) { $modified = filemtime($filename); - $cacheKey = 'metadata-' . $slug . '-' . md5($filename . '|' . filesize($filename) . '|' . $modified); + $cacheKey = 'metadata-b64-' . $slug . '-' . md5($filename . '|' . filesize($filename) . '|' . $modified); $metadata = null; //Try the cache first.