From 43f0fc93b7f5f226d6f63b62659ac224ef6218fa 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 594343d3..f2e0dbb7 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 30dee333..3c3d6780 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; @@ -273,10 +278,7 @@ $formats = Format::searchInformation(); ?> - diff --git a/lib/Exceptions.php b/lib/Exceptions.php index 202060f6..74124eaa 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 d2952806..5e0824ff 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -39,4 +39,4 @@ require_once $vendorLibSimpleHtmlDom; )) ->display(); -*/ \ No newline at end of file +*/