<commit_before><?php
class Message extends AppModel {
	
	public $hasMany = array(
		'Action' => array(
			'className' 	=> 'Action',
			'foreignKey'	=> 'message_id',
			'order'			=> 'Action.created ASC',
			'dependent'		=> true,
		),
		'Reply' => array(
			'className' 	=> 'Message',
			'foreignKey'	=> 'parent_id',
		)
	);
	public $belongsTo = array(
		'Status' => array(
			'className' 	=> 'Status',
			'foreignKey'	=> 'status',
			'fields'		=> 'name'
		),
		'Lockkeeper' => array(
			'className' 	=> 'User',
			'foreignKey'	=> 'owner_id',
			'fields'		=> 'username'
		),
		'Source' => array(
			'className' 	=> 'MessageSource',
			'foreignKey'	=> 'source_id',
			'fields'		=> array('name', 'url')
		),
		'Parent' => array(
			'className' 	=> 'Message',
			'foreignKey'	=> 'parent_id',
			'fields'		=> array('from_address', 'message', 'is_outbound')
		),
	);
	public $actsAs = array('Tree');
	
	public $validate = array(
		// note MSISD is now also used for outgoing messages, e.g. username
		// In future may also be used for, e.g, twitter status: later, refactor by changing name?
		'from_address' => array(
			'rule'    => 'notEmpty',
			'message' => 'Address of sender may not be empty',
			'on'      => 'create'
		),
		'message' => array(
			'rule'    => 'notEmpty',
			'message' => 'Message text may not be empty',
			'on'      => 'create'
		),
		'source_id' => array(
			'rule'    => 'source_exists',
			'message' => 'Message source (source_id) provided did not match any known to Message Manager',
			'on'      => 'create'
		),
		'external_id' => array(
			'rule'    =>  'unique_id_by_source',
			'message' => 'A message from this source with this external ID already exists',
			'on'      => 'create'
		),
		'parent_id' => array(
			'rule'    => 'parent_exists_if_specified',
			'required' => false,
			'allowEmpty' => true,
			'message' => 'The parent_id must be the ID for an existing message (and not the message itself)',
			'on'      => 'edit'
		)
	);
	
	public $order = "Message.created DESC";
	
	// beforeSave:
	// * generate sender_token:
	//   Save a unique-per-from_address token (sender_token) so FMS users can tell when two messages
	//   are from the same sender without knowing their phone numbers, etc.
	//   In anticipation of from_address being non-numeric (twitter handles, etc) this is done case-insensitively.
	//   Note that outbound messages (that is, message sent from Message Manager (i.e.., replies via FMS)) do
	//   not strip/hide the from-address, which is the username of the MM user).
	//
	// * extract tag
	//   Scans the (presumably) incoming message for tags, possibly stripping them
	//   and storing in the record
	//   For example, incoming messages like "LUZ Hole in the road..." becomes
	//   tag: LUZ, message: "Hole in the road..."
	
	public function beforeSave() {
		if (!empty($this->data['Message']['from_address'])) {
			if ($this->data['Message']['is_outbound']) {
				$this->data['Message']['sender_token'] = $this->data['Message']['from_address'];
			} else {
				$this->data['Message']['sender_token'] = hash('md5', strtolower(trim($this->data['Message']['from_address'])));
			}
		}
		if (!empty($this->data['Message']['message'])) {
			$message_text = $this->data['Message']['message'];
			if (!empty($message_text)) {
				$tag_data = Message::separate_out_tags($message_text);<commit_msg>suppress message order (for now?) because it breaks in shell command (netcast)<commit_after><?php
class Message extends AppModel {
	
	public $hasMany = array(
		'Action' => array(
			'className' 	=> 'Action',
			'foreignKey'	=> 'message_id',
			'order'			=> 'Action.created ASC',
			'dependent'		=> true,
		),
		'Reply' => array(
			'className' 	=> 'Message',
			'foreignKey'	=> 'parent_id',
		)
	);
	public $belongsTo = array(
		'Status' => array(
			'className' 	=> 'Status',
			'foreignKey'	=> 'status',
			'fields'		=> 'name'
		),
		'Lockkeeper' => array(
			'className' 	=> 'User',
			'foreignKey'	=> 'owner_id',
			'fields'		=> 'username'
		),
		'Source' => array(
			'className' 	=> 'MessageSource',
			'foreignKey'	=> 'source_id',
			'fields'		=> array('name', 'url')
		),
		'Parent' => array(
			'className' 	=> 'Message',
			'foreignKey'	=> 'parent_id',
			'fields'		=> array('from_address', 'message', 'is_outbound')
		),
	);
	public $actsAs = array('Tree');
	
	public $validate = array(
		// note MSISD is now also used for outgoing messages, e.g. username
		// In future may also be used for, e.g, twitter status: later, refactor by changing name?
		'from_address' => array(
			'rule'    => 'notEmpty',
			'message' => 'Address of sender may not be empty',
			'on'      => 'create'
		),
		'message' => array(
			'rule'    => 'notEmpty',
			'message' => 'Message text may not be empty',
			'on'      => 'create'
		),
		'source_id' => array(
			'rule'    => 'source_exists',
			'message' => 'Message source (source_id) provided did not match any known to Message Manager',
			'on'      => 'create'
		),
		'external_id' => array(
			'rule'    =>  'unique_id_by_source',
			'message' => 'A message from this source with this external ID already exists',
			'on'      => 'create'
		),
		'parent_id' => array(
			'rule'    => 'parent_exists_if_specified',
			'required' => false,
			'allowEmpty' => true,
			'message' => 'The parent_id must be the ID for an existing message (and not the message itself)',
			'on'      => 'edit'
		)
	);
	
	// public $order = "Message.created DESC";
	
	// beforeSave:
	// * generate sender_token:
	//   Save a unique-per-from_address token (sender_token) so FMS users can tell when two messages
	//   are from the same sender without knowing their phone numbers, etc.
	//   In anticipation of from_address being non-numeric (twitter handles, etc) this is done case-insensitively.
	//   Note that outbound messages (that is, message sent from Message Manager (i.e.., replies via FMS)) do
	//   not strip/hide the from-address, which is the username of the MM user).
	//
	// * extract tag
	//   Scans the (presumably) incoming message for tags, possibly stripping them
	//   and storing in the record
	//   For example, incoming messages like "LUZ Hole in the road..." becomes
	//   tag: LUZ, message: "Hole in the road..."
	
	public function beforeSave() {
		if (!empty($this->data['Message']['from_address'])) {
			if ($this->data['Message']['is_outbound']) {
				$this->data['Message']['sender_token'] = $this->data['Message']['from_address'];
			} else {
				$this->data['Message']['sender_token'] = hash('md5', strtolower(trim($this->data['Message']['from_address'])));
			}
		}
		if (!empty($this->data['Message']['message'])) {
			$message_text = $this->data['Message']['message'];
			if (!empty($message_text)) {
				$tag_data = Message::separate_out_tags($message_text);
{'fraction_non_alphanumeric': 0.17366242979603902, 'fraction_numerical': 0.0002955956251847473, 'mean_word_length': 3.4142204827136333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 111, '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': '770637', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2221, 'n_words': 636}