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 --- .../lib/Elastica/Bulk/Action/AbstractDocument.php | 162 +++++++++++++++++++++ .../lib/Elastica/Bulk/Action/CreateDocument.php | 11 ++ .../lib/Elastica/Bulk/Action/DeleteDocument.php | 33 +++++ .../lib/Elastica/Bulk/Action/IndexDocument.php | 52 +++++++ .../lib/Elastica/Bulk/Action/UpdateDocument.php | 69 +++++++++ 5 files changed, 327 insertions(+) create mode 100644 vendor/ruflin/elastica/lib/Elastica/Bulk/Action/AbstractDocument.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Bulk/Action/CreateDocument.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Bulk/Action/DeleteDocument.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Bulk/Action/IndexDocument.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Bulk/Action/UpdateDocument.php (limited to 'vendor/ruflin/elastica/lib/Elastica/Bulk/Action') diff --git a/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/AbstractDocument.php b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/AbstractDocument.php new file mode 100644 index 00000000..545e695c --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/AbstractDocument.php @@ -0,0 +1,162 @@ +setData($document); + } + + /** + * @param \Elastica\Document $document + * @return \Elastica\Bulk\Action\AbstractDocument + */ + public function setDocument(Document $document) + { + $this->_data = $document; + + $metadata = $this->_getMetadata($document); + + $this->setMetadata($metadata); + + return $this; + } + + /** + * @param \Elastica\Script $script + * @return \Elastica\Bulk\Action\AbstractDocument + */ + public function setScript(Script $script) + { + if (!($this instanceof UpdateDocument)) { + throw new \BadMethodCallException("setScript() can only be used for UpdateDocument"); + } + + $this->_data = $script; + + $metadata = $this->_getMetadata($script); + $this->setMetadata($metadata); + + return $this; + } + + /** + * @param \Elastica\Script|\Elastica\Document $data + * @throws \InvalidArgumentException + * @return \Elastica\Bulk\Action\AbstractDocument + */ + public function setData($data) + { + if ($data instanceof Script) { + + $this->setScript($data); + + }else if ($data instanceof Document) { + + $this->setDocument($data); + + }else{ + throw new \InvalidArgumentException("Data should be a Document or a Script."); + } + + return $this; + } + + /** + * Note: This is for backwards compatibility. + * @return \Elastica\Document + */ + public function getDocument() + { + if ($this->_data instanceof Document) { + return $this->_data; + } + + return null; + } + + /** + * Note: This is for backwards compatibility. + * @return \Elastica\Script + */ + public function getScript() + { + if ($this->_data instanceof Script) { + return $this->_data; + } + + return null; + } + + /** + * @return \Elastica\Document|\Elastica\Script + */ + public function getData() + { + return $this->_data; + } + + /** + * @param \Elastica\AbstractUpdateAction $source + * @return array + */ + abstract protected function _getMetadata(AbstractUpdateAction $source); + + /** + * @param \Elastica\Document|\Elastica\Script $data + * @param string $opType + * @return \Elastica\Bulk\Action\AbstractDocument + */ + public static function create($data, $opType = null) + { + //Check type + if (!($data instanceof Document) && !($data instanceof Script)) { + throw new \InvalidArgumentException("The data needs to be a Document or a Script."); + } + + if (null === $opType && $data->hasOpType()) { + $opType = $data->getOpType(); + } + + //Check that scripts can only be used for updates + if ($data instanceof Script) { + if ($opType === null) { + $opType = self::OP_TYPE_UPDATE; + } else if ($opType != self::OP_TYPE_UPDATE) { + throw new \InvalidArgumentException("Scripts can only be used with the update operation type."); + } + } + + switch ($opType) { + case self::OP_TYPE_DELETE: + $action = new DeleteDocument($data); + break; + case self::OP_TYPE_CREATE: + $action = new CreateDocument($data); + break; + case self::OP_TYPE_UPDATE: + $action = new UpdateDocument($data); + break; + case self::OP_TYPE_INDEX: + default: + $action = new IndexDocument($data); + break; + } + return $action; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/CreateDocument.php b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/CreateDocument.php new file mode 100644 index 00000000..ae868b49 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/CreateDocument.php @@ -0,0 +1,11 @@ +getOptions($params, true); + + return $metadata; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/IndexDocument.php b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/IndexDocument.php new file mode 100644 index 00000000..d405563e --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/IndexDocument.php @@ -0,0 +1,52 @@ +setSource($document->getData()); + + return $this; + } + + /** + * @param \Elastica\AbstractUpdateAction $source + * @return array + */ + protected function _getMetadata(AbstractUpdateAction $action) + { + $params = array( + 'index', + 'type', + 'id', + 'version', + 'version_type', + 'routing', + 'percolate', + 'parent', + 'ttl', + 'timestamp', + 'retry_on_conflict', + ); + $metadata = $action->getOptions($params, true); + + return $metadata; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/UpdateDocument.php b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/UpdateDocument.php new file mode 100644 index 00000000..4c1dbaa4 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/UpdateDocument.php @@ -0,0 +1,69 @@ + $document->getData()); + + if ($document->getDocAsUpsert()) { + $source['doc_as_upsert'] = true; + + }else if ($document->hasUpsert()) { + + $upsert = $document->getUpsert()->getData(); + + if (!empty($upsert)) { + $source['upsert'] = $upsert; + } + } + + $this->setSource($source); + + return $this; + } + + /** + * @param \Elastica\Script $script + * @return \Elastica\Bulk\Action\AbstractDocument + */ + public function setScript(Script $script) + { + parent::setScript($script); + + $source = $script->toArray(); + + if ($script->hasUpsert()) { + $upsert = $script->getUpsert()->getData(); + + if (!empty($upsert)) { + $source['upsert'] = $upsert; + } + } + + $this->setSource($source); + + return $this; + } +} -- cgit v1.2.3