<commit_before><?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.

See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.
=========================================================================*/

/** global midas model library*/
class MIDASModel
{
  protected $database;
  protected $_name = ''; // I don't like this (should be protected)
  protected $_key = '';
  protected $_mainData = array();
  protected $_components = array();

  /**
   * @method public __construct()
   * Constructor
   */
  public function __construct()
    {
    // We should do the switch here
    $configDatabase = Zend_Registry::get('configDatabase');
    switch($configDatabase->database->type)
      {
      case 'pdo': $this->database = new MIDASDatabasePdo(); break;
      case 'cassandra': $this->database = new MIDASDatabaseCassandra(); break;
      case 'mongo': $this->database = new MIDASDatabaseMongo(); break;
      default: break;
      }
    } // end __construct()

  /** Initializing */
  public function initialize()
    {
    $this->loadElements(); // load the components for the models
    $this->database->initialize($this->_name, $this->_key, $this->_mainData);
    }

  /** Save a Dao */
  public function save($dao)
    {
    $instance = $this->_name."Dao";
    if(isset($this->_daoName) && isset($this->moduleName))
      {
      $instance = ucfirst($this->moduleName).'_'.$this->_daoName;
      }
    if(!$dao instanceof $instance)
      {
      throw new Zend_Exception("Should be an object (".$instance.").");
      }

    $data = array();
    foreach($this->_mainData as $key => $var)
      {
      if(isset($dao->$key))
        {
        $data[$key] = $dao->$key;
        }
      }

    $dataarray = array();
    foreach($data as $key => $d)
      {
      if(isset($this->_mainData[$key]))
        {
        $dataarray[$key] = $d;
        }
      }

    $insertedid = $this->database->save($dataarray);

    if($insertedid !== false)
      {
      if(isset($this->_key) && !empty($this->_key))
        {
        $key = $this->_key;
        $dao->$key = $insertedid;<commit_msg>BUG: refs #0241. Cleaned out redundant save code.<commit_after><?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.

See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.
=========================================================================*/

/** global midas model library*/
class MIDASModel
{
  protected $database;
  protected $_name = ''; // I don't like this (should be protected)
  protected $_key = '';
  protected $_mainData = array();
  protected $_components = array();

  /**
   * @method public __construct()
   * Constructor
   */
  public function __construct()
    {
    // We should do the switch here
    $configDatabase = Zend_Registry::get('configDatabase');
    switch($configDatabase->database->type)
      {
      case 'pdo': $this->database = new MIDASDatabasePdo(); break;
      case 'cassandra': $this->database = new MIDASDatabaseCassandra(); break;
      case 'mongo': $this->database = new MIDASDatabaseMongo(); break;
      default: break;
      }
    } // end __construct()

  /** Initializing */
  public function initialize()
    {
    $this->loadElements(); // load the components for the models
    $this->database->initialize($this->_name, $this->_key, $this->_mainData);
    }

  /** Save a Dao */
  public function save($dao)
    {
    $instance = $this->_name."Dao";
    if(isset($this->_daoName) && isset($this->moduleName))
      {
      $instance = ucfirst($this->moduleName).'_'.$this->_daoName;
      }
    if(!$dao instanceof $instance)
      {
      throw new Zend_Exception("Should be an object (".$instance.").");
      }

    $dataarray = array();
    foreach($this->_mainData as $key => $var)
      {
      if(isset($dao->$key))
        {
        $dataarray[$key] = $dao->$key;
        }
      }

    $insertedid = $this->database->save($dataarray);

    if($insertedid !== false)
      {
      if(isset($this->_key) && !empty($this->_key))
        {
        $key = $this->_key;
        $dao->$key = $insertedid;
{'fraction_non_alphanumeric': 0.20557341907824223, 'fraction_numerical': 0.0038585209003215433, 'mean_word_length': 3.057391304347826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '742748', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1311, 'n_words': 351}