From 4f58937636514ece7dd0025bab9a678adb258743 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 13 Feb 2013 09:52:06 +1300 Subject: [PATCH] Logging Solr communication exceptions as warnings Before we didn't catch exceptions, the CMS would break when communication errors with Solr occurred, this change will log those exceptions as warnings so that creating new and publishing pages will continue gracefully. --- code/solr/SolrIndex.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/code/solr/SolrIndex.php b/code/solr/SolrIndex.php index daa0375..1a89e6b 100644 --- a/code/solr/SolrIndex.php +++ b/code/solr/SolrIndex.php @@ -167,7 +167,12 @@ abstract class SolrIndex extends SearchIndex { if ($field['base'] == $base) $this->_addField($doc, $object, $field); } - $this->getService()->addDocument($doc); + try { + $this->getService()->addDocument($doc); + } catch (Exception $e) { + SS_Log::log($e, SS_Log::WARN); + return false; + } return $doc; } @@ -195,11 +200,22 @@ abstract class SolrIndex extends SearchIndex { function delete($base, $id, $state) { $documentID = $this->getDocumentIDForState($base, $id, $state); - $this->getService()->deleteById($documentID); + + try { + $this->getService()->deleteById($documentID); + } catch (Exception $e) { + SS_Log::log($e, SS_Log::WARN); + return false; + } } function commit() { - $this->getService()->commit(false, false, false); + try { + $this->getService()->commit(false, false, false); + } catch (Exception $e) { + SS_Log::log($e, SS_Log::WARN); + return false; + } } /**