From 8448618f60756bcdc22952f93b6600c3c83b3f31 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 17 Jan 2017 09:22:41 +0100 Subject: [PATCH] FIX: Catch deletion of non existing documents * Catch exception raised during deletion of documents that are not already indexed. * Log failed deletion tries. * Add new necessary Exceptions. --- .../NoConfigurationException.php | 25 +++++++++++++++++++ Classes/Connection/Elasticsearch.php | 16 +++++++----- .../Domain/Index/NoRecordFoundException.php | 25 +++++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100755 Classes/Configuration/NoConfigurationException.php create mode 100755 Classes/Domain/Index/NoRecordFoundException.php diff --git a/Classes/Configuration/NoConfigurationException.php b/Classes/Configuration/NoConfigurationException.php new file mode 100755 index 0000000..bc6c1ba --- /dev/null +++ b/Classes/Configuration/NoConfigurationException.php @@ -0,0 +1,25 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +class NoConfigurationException extends \InvalidArgumentException +{ +} diff --git a/Classes/Connection/Elasticsearch.php b/Classes/Connection/Elasticsearch.php index 4cce11b..560ca07 100644 --- a/Classes/Connection/Elasticsearch.php +++ b/Classes/Connection/Elasticsearch.php @@ -92,12 +92,16 @@ class Elasticsearch implements Singleton, ConnectionInterface public function deleteDocument($documentType, $identifier) { - $this->withType( - $documentType, - function ($type) use ($identifier) { - $type->deleteById($identifier); - } - ); + try { + $this->withType( + $documentType, + function ($type) use ($identifier) { + $type->deleteById($identifier); + } + ); + } catch (\Elastica\Exception\NotFoundException $exception) { + $this->logger->debug('Tried to delete document in index, which does not exist.', [$documentType, $identifier]); + } } public function updateDocument($documentType, array $document) diff --git a/Classes/Domain/Index/NoRecordFoundException.php b/Classes/Domain/Index/NoRecordFoundException.php new file mode 100755 index 0000000..8a92408 --- /dev/null +++ b/Classes/Domain/Index/NoRecordFoundException.php @@ -0,0 +1,25 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +class NoRecordFoundException extends IndexingException +{ +}