<commit_before><?php

class Log extends OlogAppModel {

  /**
   * The name of this model
   *
   * @var name
   */
  public $name ='Log';
  
  /**
   * The custom find types available on the model
   * 
   * @var array
   */
  public $_findMethods = array(
    'logs' => true,
    'log' => true
  );

  /**
   * Finds logs matching the given criteria.
   *
   * Calls the Olog web service
   *
   * Called using Model::find('logs', $options)
   *
   *
   * Conditions can include
   * - logbook : String logbook name to search for
   * - tag : String tag name to search for
   * - search : String regex to search on
   * - {key} : {key} value to search on
   *
   * @param string $state 'before' or 'after'
   * @param array $query The query options passed to the Model::find() call
   * @param array $results The results from the call
   * @return array Either the modified query params or results depending on the
   *  value of the state parameter.
   */
  protected function _findLogs($state, $query = array(), $results = array()) {

    if ($state == 'before') {

      $this->request['uri']['path'] = 'logs';
  
      $this->request['uri']['query'] = $query['conditions'];

      return $query;
      
    } else {

      return $results;
      
    }
    
  }

  /**
   * Finds log matching the given id.
   *
   * Calls the Olog web service
   *
   * Called using Model::find('log', $options)
   *
   * $options can include the usual keys for 'conditions'
   *
   * Conditions can include
   * - id : an integer corresponding to the log id
   *
   * @param string $state 'before' or 'after'
   * @param array $query The query options passed to the Model::find() call
   * @param array $results The results from the call
   * @return array Either the modified query params or results depending on the
   *  value of the state parameter.
   */
  protected function _findLog($state, $query = array(), $results = array()) {

    if ($state == 'before') {

      if (!isset($query['conditions']['id'])) {
        return false;
      }

      $this->request['uri']['path'] = 'logs/' . $query['conditions']['id'];

      return $query;

    } else {

      return $results;

    }

  }
  public function merge($data = null, $validate = true, $fieldList = array()) {
    foreach($data['log'] as $field=>$value){
      list($fields[], $values[]) = array($field, $value);
    }
    
    $db =& ConnectionManager::getDataSource($this->useDbConfig);
    if (!empty($data['log']['id'])) {
       return (bool)$db->create($this, $fields, $values);
    }
    if (!$db->create($this, $fields, $values)) {
      $success = false;
    } else {
      $success = true;
    }
    return $success;
  }
  
  public function save($data = null, $validate = true, $fieldList = array()) {
    foreach($data['log'] as $field=>$value){
      list($fields[], $values[]) = array($field, $value);
    }
    
    $db =& ConnectionManager::getDataSource($this->useDbConfig);
    if (!empty($data['log']['id'])) {
       return (bool)$db->update($this, $fields, $values);
    }
    if (!$db->create($this, $fields, $values)) {
      $success = false;
    } else {
      $success = true;
    }
    return $success;
  }

}
?><commit_msg>log model - refactor and reformat<commit_after><?php

class Log extends OlogAppModel {

    /**
     * The name of this model
     *
     * @var name
     */
    public $name = 'Log';

    /**
     * The custom find types available on the model
     * 
     * @var array
     */
    public $_findMethods = array(
        'logs' => true,
        'log' => true
    );

    /**
     * Finds logs matching the given criteria.
     *
     * Calls the Olog web service
     *
     * Called using Model::find('logs', $options)
     *
     *
     * Conditions can include
     * - logbook : String logbook name to search for
     * - tag : String tag name to search for
     * - search : String regex to search on
     * - {key} : {key} value to search on
     *
     * @param string $state 'before' or 'after'
     * @param array $query The query options passed to the Model::find() call
     * @param array $results The results from the call
     * @return array Either the modified query params or results depending on the
     *  value of the state parameter.
     */
    protected function _findLogs($state, $query = array(), $results = array()) {

        if ($state == 'before') {

            $this->request['uri']['path'] = 'logs';

            $this->request['uri']['query'] = $query['conditions'];

            return $query;
        } else {

            return $results;
        }
    }

    /**
     * Finds log matching the given id.
     *
     * Calls the Olog web service
     *
     * Called using Model::find('log', $options)
     *
     * $options can include the usual keys for 'conditions'
     *
     * Conditions can include
     * - id : an integer corresponding to the log id
     *
     * @param string $state 'before' or 'after'
     * @param array $query The query options passed to the Model::find() call
     * @param array $results The results from the call
     * @return array Either the modified query params or results depending on the
     *  value of the state parameter.
     */
    protected function _findLog($state, $query = array(), $results = array()) {

        if ($state == 'before') {

            if (!isset($query['conditions']['id'])) {
                return false;
            }

            $this->request['uri']['path'] = 'logs/' . $query['conditions']['id'];

            return $query;
        } else {

            return $results;
        }
    }

    /**
     * 
     *
     * @param $data
     * @param $validate
     * @param $fieldList
     * 
     * @return $success
     */
    public function merge($data = null, $validate = true, $fieldList = array()) {
        foreach ($data['log'] as $field => $value) {
            list($fields[], $values[]) = array($field, $value);
        }

        $db = & ConnectionManager::getDataSource($this->useDbConfig);
        if (!empty($data['log']['id'])) {
            return (bool) $db->create($this, $fields, $values);
        }
        if (!$db->create($this, $fields, $values)) {
            $success = false;
        } else {
            $success = true;
        }
        return $success;
    }

    /**
     * 
     *
     * @param $data
     * @param $validate
     * @param $fieldList
     * 
     * @return $success
     */
    public function save($data = null, $validate = true, $fieldList = array()) {
        foreach ($data['log'] as $field => $value) {
            list($fields[], $values[]) = array($field, $value);
        }

        $db = & ConnectionManager::getDataSource($this->useDbConfig);
        if (!empty($data['log']['id'])) {
            return (bool) $db->update($this, $fields, $values);
        }
        if (!$db->create($this, $fields, $values)) {
            $success = false;
        } else {
            $success = true;
        }
        return $success;
    }

}

?>
{'fraction_non_alphanumeric': 0.15104835258878904, 'fraction_numerical': 0.0, 'mean_word_length': 2.1585585585585587, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '6331010', 'n_tokens_mistral': 2079, 'n_tokens_neox': 2038, 'n_words': 632}