summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/UpdateDocument.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Bulk/Action/UpdateDocument.php')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Bulk/Action/UpdateDocument.php65
1 files changed, 65 insertions, 0 deletions
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..2b133acb
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Bulk/Action/UpdateDocument.php
@@ -0,0 +1,65 @@
+<?php
+namespace Elastica\Bulk\Action;
+
+use Elastica\Document;
+use Elastica\Script;
+
+class UpdateDocument extends IndexDocument
+{
+ /**
+ * @var string
+ */
+ protected $_opType = self::OP_TYPE_UPDATE;
+
+ /**
+ * Set the document for this bulk update action.
+ *
+ * @param \Elastica\Document $document
+ *
+ * @return $this
+ */
+ public function setDocument(Document $document)
+ {
+ parent::setDocument($document);
+
+ $source = array('doc' => $document->getData());
+
+ if ($document->getDocAsUpsert()) {
+ $source['doc_as_upsert'] = true;
+ } elseif ($document->hasUpsert()) {
+ $upsert = $document->getUpsert()->getData();
+
+ if (!empty($upsert)) {
+ $source['upsert'] = $upsert;
+ }
+ }
+
+ $this->setSource($source);
+
+ return $this;
+ }
+
+ /**
+ * @param \Elastica\Script $script
+ *
+ * @return $this
+ */
+ 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;
+ }
+}