From 2e4e89aff872b786e2fbd61365ec9bf269cc7924 Mon Sep 17 00:00:00 2001 From: teromene Date: Thu, 5 Nov 2015 10:12:58 +0000 Subject: [PATCH] Correction of few bugs. Warn if RSS-Bridge cannot write to disk. Try/Catch the bridge RSS generation. Signed-off-by: teromene --- caches/FileCache.php | 10 ++++++++-- index.php | 30 ++++++++++++++++-------------- lib/Exceptions.php | 2 +- lib/RssBridge.php | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/caches/FileCache.php b/caches/FileCache.php index 594343d..f2e0dbb 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -24,7 +24,13 @@ class FileCache extends CacheAbstract{ public function saveData($datas){ $this->isPrepareCache(); - file_put_contents($this->getCacheFile(), json_encode($datas)); + $writeStream = file_put_contents($this->getCacheFile(), json_encode($datas)); + + if(!$writeStream) { + + throw new \Exception("Cannot write the cache... Do you have the right permissions ?"); + + } return $this; } @@ -89,4 +95,4 @@ class FileCache extends CacheAbstract{ $stringToEncode = $_SERVER['REQUEST_URI'] . http_build_query($this->param); return hash('sha1', $stringToEncode) . '.cache'; } -} \ No newline at end of file +} diff --git a/index.php b/index.php index c460148..89ebf18 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,4 @@ setDatas($_REQUEST); $bridge->loadMetadatas(); // Data transformation - $format = Format::create($format); - $format - ->setDatas($bridge->getDatas()) - ->setExtraInfos(array( - 'name' => $bridge->getName(), - 'uri' => $bridge->getURI(), - )) - ->display(); + try { + $format = Format::create($format); + $format + ->setDatas($bridge->getDatas()) + ->setExtraInfos(array( + 'name' => $bridge->getName(), + 'uri' => $bridge->getURI(), + )) + ->display(); + } catch(Exception $e) { + + echo "The brige has crashed. You should report this to the bridges maintainer"; + + } die; } break; @@ -291,10 +296,7 @@ $formats = Format::searchInformation(); ?> - diff --git a/lib/Exceptions.php b/lib/Exceptions.php index 202060f..74124ea 100644 --- a/lib/Exceptions.php +++ b/lib/Exceptions.php @@ -58,4 +58,4 @@ class Http{ 508 => 'Loop detected', ); } -} \ No newline at end of file +} diff --git a/lib/RssBridge.php b/lib/RssBridge.php index d295280..5e0824f 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -39,4 +39,4 @@ require_once $vendorLibSimpleHtmlDom; )) ->display(); -*/ \ No newline at end of file +*/