From 15e69f7b20b6596b9148030acce5b59993b95a45 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Dec 2015 06:00:00 +0100 Subject: Update to MediaWiki 1.25.4 --- .../ruflin/elastica/lib/Elastica/Bulk/Action.php | 219 +++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 vendor/ruflin/elastica/lib/Elastica/Bulk/Action.php (limited to 'vendor/ruflin/elastica/lib/Elastica/Bulk/Action.php') diff --git a/vendor/ruflin/elastica/lib/Elastica/Bulk/Action.php b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action.php new file mode 100644 index 00000000..7922ec13 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action.php @@ -0,0 +1,219 @@ +setOpType($opType); + $this->setMetadata($metadata); + $this->setSource($source); + } + + /** + * @param string $type + * @return \Elastica\Bulk\Action + */ + public function setOpType($type) + { + $this->_opType = $type; + + return $this; + } + + /** + * @return string + */ + public function getOpType() + { + return $this->_opType; + } + + /** + * @param array $metadata + * @return \Elastica\Bulk\Action + */ + public function setMetadata(array $metadata) + { + $this->_metadata = $metadata; + + return $this; + } + + /** + * @return array + */ + public function getMetadata() + { + return $this->_metadata; + } + + /** + * @return array + */ + public function getActionMetadata() + { + return array($this->_opType => $this->getMetadata()); + } + + /** + * @param array $source + * @return \Elastica\Bulk\Action + */ + public function setSource($source) + { + $this->_source = $source; + + return $this; + } + + /** + * @return array + */ + public function getSource() + { + return $this->_source; + } + + /** + * @return bool + */ + public function hasSource() + { + return !empty($this->_source); + } + + /** + * @param string|\Elastica\Index $index + * @return \Elastica\Bulk\Action + */ + public function setIndex($index) + { + if ($index instanceof Index) { + $index = $index->getName(); + } + $this->_metadata['_index'] = $index; + + return $this; + } + + /** + * @param string|\Elastica\Type $type + * @return \Elastica\Bulk\Action + */ + public function setType($type) + { + if ($type instanceof Type) { + $this->setIndex($type->getIndex()->getName()); + $type = $type->getName(); + } + $this->_metadata['_type'] = $type; + + return $this; + } + + /** + * @param string $id + * @return \Elastica\Bulk\Action + */ + public function setId($id) + { + $this->_metadata['_id'] = $id; + + return $this; + } + + /** + * @param string $routing + * @return \Elastica\Bulk\Action + */ + public function setRouting($routing) + { + $this->_metadata['_routing'] = $routing; + + return $this; + } + + /** + * @return array + */ + public function toArray() + { + $data[] = $this->getActionMetadata(); + if ($this->hasSource()) { + $data[] = $this->getSource(); + } + return $data; + } + + /** + * @return string + */ + public function toString() + { + $string = JSON::stringify($this->getActionMetadata(), JSON_FORCE_OBJECT) . Bulk::DELIMITER; + if ($this->hasSource()) { + $source = $this->getSource(); + if (is_string($source)) { + $string.= $source; + } elseif (is_array($source) && array_key_exists('doc', $source) && is_string($source['doc'])) { + $docAsUpsert = (isset($source['doc_as_upsert'])) ? ', "doc_as_upsert": '.$source['doc_as_upsert'] : ''; + $string.= '{"doc": '.$source['doc'].$docAsUpsert.'}'; + } else { + $string.= JSON::stringify($source, 'JSON_ELASTICSEARCH'); + } + $string.= Bulk::DELIMITER; + } + return $string; + } + + /** + * @param string $opType + * @return bool + */ + public static function isValidOpType($opType) + { + return in_array($opType, self::$opTypes); + } +} -- cgit v1.2.2