diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/ResponseException.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/ResponseException.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/ResponseException.php | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/ResponseException.php b/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/ResponseException.php new file mode 100644 index 00000000..54b5702b --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/ResponseException.php @@ -0,0 +1,98 @@ +<?php +namespace Elastica\Exception\Bulk; + +use Elastica\Bulk\ResponseSet; +use Elastica\Exception\Bulk\Response\ActionException; +use Elastica\Exception\BulkException; + +/** + * Bulk Response exception. + */ +class ResponseException extends BulkException +{ + /** + * @var \Elastica\Bulk\ResponseSet ResponseSet object + */ + protected $_responseSet; + + /** + * @var \Elastica\Exception\Bulk\Response\ActionException[] + */ + protected $_actionExceptions = array(); + + /** + * Construct Exception. + * + * @param \Elastica\Bulk\ResponseSet $responseSet + */ + public function __construct(ResponseSet $responseSet) + { + $this->_init($responseSet); + + $message = 'Error in one or more bulk request actions:'.PHP_EOL.PHP_EOL; + $message .= $this->getActionExceptionsAsString(); + + parent::__construct($message); + } + + /** + * @param \Elastica\Bulk\ResponseSet $responseSet + */ + protected function _init(ResponseSet $responseSet) + { + $this->_responseSet = $responseSet; + + foreach ($responseSet->getBulkResponses() as $bulkResponse) { + if ($bulkResponse->hasError()) { + $this->_actionExceptions[] = new ActionException($bulkResponse); + } + } + } + + /** + * Returns bulk response set object. + * + * @return \Elastica\Bulk\ResponseSet + */ + public function getResponseSet() + { + return $this->_responseSet; + } + + /** + * Returns array of failed actions. + * + * @return array Array of failed actions + */ + public function getFailures() + { + $errors = array(); + + foreach ($this->getActionExceptions() as $actionException) { + $errors[] = $actionException->getMessage(); + } + + return $errors; + } + + /** + * @return \Elastica\Exception\Bulk\Response\ActionException[] + */ + public function getActionExceptions() + { + return $this->_actionExceptions; + } + + /** + * @return string + */ + public function getActionExceptionsAsString() + { + $message = ''; + foreach ($this->getActionExceptions() as $actionException) { + $message .= $actionException->getMessage().PHP_EOL; + } + + return $message; + } +} |