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.
This commit is contained in:
Daniel Siepmann 2017-01-17 09:22:41 +01:00
parent d358714d0d
commit 8448618f60
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 60 additions and 6 deletions

View file

@ -0,0 +1,25 @@
<?php
namespace Leonmrni\SearchCore\Configuration;
/*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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
{
}

View file

@ -92,12 +92,16 @@ class Elasticsearch implements Singleton, ConnectionInterface
public function deleteDocument($documentType, $identifier) public function deleteDocument($documentType, $identifier)
{ {
$this->withType( try {
$documentType, $this->withType(
function ($type) use ($identifier) { $documentType,
$type->deleteById($identifier); 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) public function updateDocument($documentType, array $document)

View file

@ -0,0 +1,25 @@
<?php
namespace Leonmrni\SearchCore\Domain\Index;
/*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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
{
}