summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Exception/Bulk')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/Response/ActionException.php66
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/ResponseException.php103
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/UdpException.php9
3 files changed, 178 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/Response/ActionException.php b/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/Response/ActionException.php
new file mode 100644
index 00000000..6500e040
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/Response/ActionException.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Elastica\Exception\Bulk\Response;
+
+use Elastica\Exception\BulkException;
+use Elastica\Bulk\Action;
+use Elastica\Bulk\Response;
+
+class ActionException extends BulkException
+{
+ /**
+ * @var \Elastica\Response
+ */
+ protected $_response;
+
+ /**
+ * @param \Elastica\Bulk\Response $response
+ */
+ public function __construct(Response $response)
+ {
+ $this->_response = $response;
+
+ parent::__construct($this->getErrorMessage($response));
+ }
+
+ /**
+ * @return \Elastica\Bulk\Action
+ */
+ public function getAction()
+ {
+ return $this->getResponse()->getAction();
+ }
+
+ /**
+ * @return \Elastica\Bulk\Response
+ */
+ public function getResponse()
+ {
+ return $this->_response;
+ }
+
+ /**
+ * @param \Elastica\Bulk\Response $response
+ * @return string
+ */
+ public function getErrorMessage(Response $response)
+ {
+ $error = $response->getError();
+ $opType = $response->getOpType();
+ $data = $response->getData();
+
+ $path = '';
+ if (isset($data['_index'])) {
+ $path.= '/' . $data['_index'];
+ }
+ if (isset($data['_type'])) {
+ $path.= '/' . $data['_type'];
+ }
+ if (isset($data['_id'])) {
+ $path.= '/' . $data['_id'];
+ }
+ $message = "$opType: $path caused $error";
+
+ return $message;
+ }
+}
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..9df1b3e8
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/ResponseException.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace Elastica\Exception\Bulk;
+
+use Elastica\Bulk\ResponseSet;
+use Elastica\Exception\Bulk\Response\ActionException;
+use Elastica\Exception\BulkException;
+
+/**
+ * Bulk Response exception
+ *
+ * @category Xodoa
+ * @package Elastica
+ */
+class ResponseException extends BulkException
+{
+ /**
+ * Response
+ *
+ * @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;
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/UdpException.php b/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/UdpException.php
new file mode 100644
index 00000000..0b2d4d2e
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Exception/Bulk/UdpException.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Elastica\Exception\Bulk;
+
+use Elastica\Exception\BulkException;
+
+class UdpException extends BulkException
+{
+}