Skip to content
Browse files

Merge pull request #1 from picur/master

Fixed issue adding same value twice if value was not initially an array on Document::setMultiValue call
  • Loading branch information...
2 parents 9436603 + 2290676 commit 5366994e89f6d646ae53fccb11392fb09e201e4a Yehuda Daniel committed
Showing with 14 additions and 11 deletions.
  1. +14 −11 root_folder/classes/kosolr/document.php
View
25 root_folder/classes/kosolr/document.php
@@ -9,7 +9,7 @@
class KoSolr_Document
{
- private $_data=array();
+ private $_data = array();
/**
* Magic Getter
@@ -18,8 +18,7 @@ class KoSolr_Document
*/
public function __get($name)
{
- if (array_key_exists($name, $this->_data))
- {
+ if (array_key_exists($name, $this->_data)) {
return $this->_data[$name];
}
}
@@ -62,6 +61,8 @@ public function getArrayData()
public function setField($name, $value)
{
$this->__set($name, $value);
+
+ return $this;
}
/**
* Set multiple value always addes
@@ -70,15 +71,17 @@ public function setField($name, $value)
*/
public function setMultiValue($name, $value)
{
- if(!$this->__isset($name))
- $this->setField($name, $value);
-
- if(!is_array($this->_data[$name]))
- {
- $old = $this->__get($name);
- $this->setField($name, array($value));
+ if (!$this->__isset($name)) {
+ $this->setField($name, !is_array($value) ? array($value) : $value);
+ return $this;
+ }
+
+ if (!is_array($this->_data[$name])) {
+ $this->__set($name, array($this->_data[$name]));
}
-
+
$this->_data[$name][] = $value;
+
+ return $this;
}
}

0 comments on commit 5366994

Please sign in to comment.
Something went wrong with that request. Please try again.