Skip to content

Commit

Permalink
Merge pull request #1 from picur/master
Browse files Browse the repository at this point in the history
Fixed issue adding same value twice if value was not initially an array on Document::setMultiValue call
  • Loading branch information
Yehuda Daniel committed Jun 18, 2012
2 parents 9436603 + 2290676 commit 5366994
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions root_folder/classes/kosolr/document.php
Expand Up @@ -9,7 +9,7 @@
class KoSolr_Document
{

private $_data=array();
private $_data = array();

/**
* Magic Getter
Expand All @@ -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];
}
}
Expand Down Expand Up @@ -62,6 +61,8 @@ public function getArrayData()
public function setField($name, $value)
{
$this->__set($name, $value);

return $this;
}
/**
* Set multiple value always addes
Expand All @@ -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.