<commit_before><?php

class sfMapFishRecord extends sfDoctrineRecord
{

  /**
   * List of properties to export (all by default)
   *
   */
  private $__exportedProperties = null;

  /**
   * return current record geometry column
   *
   * @return string
   *
   */
  public function getGeometryColumn()
  {
    $t = Doctrine::getTable($this->_table)->getGeometryColumn();
  }

  /**
   * update current record geometry
   *
   * @param string $geometry
   * @param int $epsg
   */
  public function updateGeometry(Geometry $geometry, $epsg=null)
  {
    try
    {
      $t = $this->getTable();

      list($db_col, $db_epsg) = $t->getGeometryColumn();
      $epsg = (is_null($epsg))?$db_epsg:$epsg;

      $geometry = WKT::dump($geometry);

      $t->createQuery('a')
        ->update()
        ->set($db_col, 'GEOMETRYFROMTEXT(?, ?)', array($geometry, $epsg))
        ->where($t->getIdentifier().' = ?', $this->getPrimaryKey())
        ->execute();

      return true;
    }
    catch (Exception $e)
    {
      return false;
    }
  }

  /**
   * Sets properties which will be exported with toArray method
   *
   * @param array $fields An array of keys
   */
  public function setExportedProperties($fields)
  {
    foreach ($fields as $key => &$value)
    {
      // in case of Doctrine_Record or Doctrine_Collection objects,
      // setExportedProperties is called recursively for each record.
      if (is_array($value))
      {
        if ($this->$key instanceof Doctrine_Collection)
        {
          foreach ($this->$key as $record)
          {
            $record->setExportedProperties($value);
          }
        }
        else
        {
          $this->$key->setExportedProperties($value);
        }
        $value = $key;
      }
    }
    $this->__exportedProperties = $fields;
  }

  /**
   * Overrides toArray
   *
   * @param boolean $deep
   * @param string $prefixkey
   *
   * @return array The filtered array
   */
  public function toArray($deep = true, $prefixKey = false)
  {
    $original = parent::toArray($deep, $prefixKey);
    if (is_null($this->__exportedProperties))
    {
      return $original;
    }

    $filtered = array();
    foreach ($original as $key => $value)
    {
      if (in_array($key, $this->__exportedProperties))
      {
        $filtered[$key] = $value;
      }
    }
    return $filtered;
  }

}
<commit_msg>bug fixing: sfMapFishRecord::toArray should return false if entering recursively the same doctrine record<commit_after><?php

class sfMapFishRecord extends sfDoctrineRecord
{

  /**
   * List of properties to export (all by default)
   *
   */
  private $__exportedProperties = null;

  /**
   * return current record geometry column
   *
   * @return string
   *
   */
  public function getGeometryColumn()
  {
    $t = Doctrine::getTable($this->_table)->getGeometryColumn();
  }

  /**
   * update current record geometry
   *
   * @param string $geometry
   * @param int $epsg
   */
  public function updateGeometry(Geometry $geometry, $epsg=null)
  {
    try
    {
      $t = $this->getTable();

      list($db_col, $db_epsg) = $t->getGeometryColumn();
      $epsg = (is_null($epsg))?$db_epsg:$epsg;

      $geometry = WKT::dump($geometry);

      $t->createQuery('a')
        ->update()
        ->set($db_col, 'GEOMETRYFROMTEXT(?, ?)', array($geometry, $epsg))
        ->where($t->getIdentifier().' = ?', $this->getPrimaryKey())
        ->execute();

      return true;
    }
    catch (Exception $e)
    {
      return false;
    }
  }

  /**
   * Sets properties which will be exported with toArray method
   *
   * @param array $fields An array of keys
   */
  public function setExportedProperties($fields)
  {
    foreach ($fields as $key => &$value)
    {
      // in case of Doctrine_Record or Doctrine_Collection objects,
      // setExportedProperties is called recursively for each record.
      if (is_array($value))
      {
        if ($this->$key instanceof Doctrine_Collection)
        {
          foreach ($this->$key as $record)
          {
            $record->setExportedProperties($value);
          }
        }
        else
        {
          $this->$key->setExportedProperties($value);
        }
        $value = $key;
      }
    }
    $this->__exportedProperties = $fields;
  }

  /**
   * Overrides toArray
   *
   * @param boolean $deep
   * @param string $prefixkey
   *
   * @return array The filtered array
   */
  public function toArray($deep = true, $prefixKey = false)
  {
    if (!$original = parent::toArray($deep, $prefixKey))
    {
      return false;
    }
    if (is_null($this->__exportedProperties))
    {
      return $original;
    }

    $filtered = array();
    foreach ($original as $key => $value)
    {
      if (in_array($key, $this->__exportedProperties))
      {
        $filtered[$key] = $value;
      }
    }
    return $filtered;
  }

}

{'fraction_non_alphanumeric': 0.13983137980670368, 'fraction_numerical': 0.0, 'mean_word_length': 2.2953929539295395, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '110391', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1505, 'n_words': 343}