<commit_before><?php
class GatewayMessage extends PaymentMessage{

	private static $db = array(
		"Gateway" => "Varchar",
		"Identifier" => "Varchar", //local id
		"Reference" => "Varchar", //remote id
		"Code" => "Varchar"
	);

	private static $summary_fields = array(
		'Type','Identifier','Reference','Message','Code'
	);

	private static $indexes = array(
		'Identifier' => true,
	);

	/**
	 * Only allow setting identifier, if one doesn't exist yet.
	 * @param string $id identifier
	 */
	public function setIdentifier($id) {
		if (!$this->Identifier) {
			$this->setField('Identifier', $id);
		}
	}

	/**
	 * Generate a unique url-friendly identifier, if one doesn't exist yet.
	 * @return string|null the new identifier, if created.
	 */
	public function generateIdentifier() {
		if (!$this->Identifier) {
			$id = $this->PaymentID.uniqid();
			while (self::get()->filter('Identifier', $id)->exists()) {
				$id = $this->PaymentID.uniqid();
			}
			$this->Identifier = $id;
			return $id;
		}
		return null;
	}

}<commit_msg>More secure uids in GatewayMessage->generateIdentifier()<commit_after><?php
class GatewayMessage extends PaymentMessage{

	private static $db = array(
		"Gateway" => "Varchar",
		"Identifier" => "Varchar", //local id
		"Reference" => "Varchar", //remote id
		"Code" => "Varchar"
	);

	private static $summary_fields = array(
		'Type','Identifier','Reference','Message','Code'
	);

	private static $indexes = array(
		'Identifier' => true,
	);

	/**
	 * Only allow setting identifier, if one doesn't exist yet.
	 * @param string $id identifier
	 */
	public function setIdentifier($id) {
		if (!$this->Identifier) {
			$this->setField('Identifier', $id);
		}
	}

	/**
	 * Generate a unique url-friendly identifier, if one doesn't exist yet.
	 * @return string|null the new identifier, if created.
	 */
	public function generateIdentifier() {
		$generator = Injector::inst()->create('RandomGenerator');
		if (!$this->Identifier) {
			$id = $this->PaymentID . '-' . substr($generator->randomToken(), 0, 30);
			while (self::get()->filter('Identifier', $id)->exists()) {
				$id = $this->PaymentID . '-' . substr($generator->randomToken(), 0, 30);
			}
			$this->Identifier = $id;
			return $id;
		}
		return null;
	}

}
{'fraction_non_alphanumeric': 0.17846016911437473, 'fraction_numerical': 0.0026702269692923898, 'mean_word_length': 3.8869565217391306, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '5886127', 'n_tokens_mistral': 787, 'n_tokens_neox': 705, 'n_words': 186}