<commit_before><?php
namespace models;

/**
 * ChannelMessage
 *
 * @uses Collection
 * @author <NAME> <<EMAIL>>
 */
class ChannelMessage extends DynamicModel {
	const EVENT_CONNECT = 'connected';

	protected $table = 'channel_messages';

	public function app() {
		return $this->belongsTo('models\App');
	}

	public function beforeSave() {
		// Check if a CONNECT message is being created, to
		// generate a unique client_id.
		if (!$this->_id && $this->getAttribute('event') && $this->event == self::EVENT_CONNECT) {
			$this->setAttribute('client_id', uniqid());
		}

		// Fill auth_id on message if there is a user authenticated.
		$auth = AuthToken::current();
		if ($auth) {
			$this->setAttribute('auth_id', $auth->auth_id);
		}

		parent::beforeSave();
	}


}
<commit_msg>fix ChannelMessage events to support create/update transformations<commit_after><?php
namespace models;

/**
 * ChannelMessage
 *
 * @uses Collection
 * @author <NAME> <<EMAIL>>
 */
class ChannelMessage extends DynamicModel {
	const EVENT_CONNECTED = 'connected';

	protected $table = 'channel_messages';

	public static function boot() {
		parent::boot();
		static::creating(function($model) { $model->beforeCreate(); });
	}

	public function app() {
		return $this->belongsTo('models\App');
	}

	public function beforeCreate() {
		// Check if a CONNECT message is being created, to
		// generate a unique client_id.
		if ($this->getAttribute('event') && $this->event == self::EVENT_CONNECTED) {
			$this->setAttribute('client_id', uniqid());
			$this->beforeSave();
		}
	}

	public function beforeSave() {
		//
		// Fill auth_id on message if there is a user authenticated.
		//
		$auth_token = AuthToken::current();
		if ($auth_token) {
			$this->setAttribute('auth_id', $auth_token->auth_id);
		}

		parent::beforeSave();
	}

}

{'fraction_non_alphanumeric': 0.1577495863210149, 'fraction_numerical': 0.0, 'mean_word_length': 4.197707736389685, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, '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': '6064339', 'n_tokens_mistral': 607, 'n_tokens_neox': 566, 'n_words': 144}