<commit_before><?php
/**
 * Activity model.
 *
 * This handles adding and retrieving activity
 * @author <NAME> <<EMAIL>>
 */
class Activity extends BaseModel
{
  /*
   * Constructor
   */
  public function __construct($params = null)
  {
    parent::__construct();
    if(isset($params['user']))
      $this->user = $params['user'];
    else
      $this->user = new User;
  }

  public function create($elementId, $attributes)
  {
    $attributes = array_merge($this->getDefaultAttributes(), $attributes);
    $attributes = $this->whitelistParams($attributes);
    if(!$this->validateParams($attributes))
    {
      $this->logger->warn('Not all required paramaters were passed to create an activity');
      return false;
    }

    $id = $this->user->getNextId('activity');
    if($id === false)
    {
      $this->logger->warn('Could not fetch the next activity id');
      return false;
    }

    $attributes['owner'] = $this->owner;
    $attributes['actor'] = $this->getActor();
    return $this->db->putActivity($id, $elementId, $attributes);<commit_msg>Check for valid parameters before creating an activity. #1156<commit_after><?php
/**
 * Activity model.
 *
 * This handles adding and retrieving activity
 * @author <NAME> <<EMAIL>>
 */
class Activity extends BaseModel
{
  /*
   * Constructor
   */
  public function __construct($params = null)
  {
    parent::__construct();
    if(isset($params['user']))
      $this->user = $params['user'];
    else
      $this->user = new User;
  }

  public function create($elementId, $attributes)
  {
    if(empty($elementId) || empty($attributes))
    {
      $this->logger->warn('When creating an activity one of the following attributes were not passed, elementId or attributes');
      return false;
    }

    $attributes = array_merge($this->getDefaultAttributes(), $attributes);
    $attributes = $this->whitelistParams($attributes);
    if(!$this->validateParams($attributes))
    {
      $this->logger->warn('Not all required paramaters were passed to create an activity');
      return false;
    }

    $id = $this->user->getNextId('activity');
    if($id === false)
    {
      $this->logger->warn('Could not fetch the next activity id');
      return false;
    }

    $attributes['owner'] = $this->owner;
    $attributes['actor'] = $this->getActor();
    return $this->db->putActivity($id, $elementId, $attributes);
{'fraction_non_alphanumeric': 0.16036943744752308, 'fraction_numerical': 0.0016792611251049538, 'mean_word_length': 3.4376163873370578, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '2470981', 'n_tokens_mistral': 689, 'n_tokens_neox': 681, 'n_words': 170}