<commit_before><?php

class PhotoUploadForm extends CFormModel
{
	public $photo;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			array('photo', 'required'),
			array('photo', 'file', 'types' => 'jpg, png', 'maxSize' => 100 * 1024),
		);
	}

	/**
	 * Declares attribute labels.
	 */
	public function attributeLabels()
	{
		return array(
			'photo' => 'Ganti Foto',
		);
	}

	/**
	 * Saves the uploaded photo and store its information in DB.
	 */
	public function savePhoto()
	{
		// delete old photo
		$student = Student::model()->findByPk(Yii::app()->user->id);
		if ($student->photo !== NULL)
		{
			unlink('photos/' . $student->photo);
		}

		// generate random filename
		$fileName = $this->randomString() . '.' . $this->photo->extensionName;
		$student = Student::model()->findByAttributes(array('photo' => $fileName));
		while ($student !== NULL)
		{
			$fileName = $this->randomString() . '.' . $this->photo->extensionName;
			$student = Student::model()->findByAttributes(array('photo' => $fileName));
		}

		$this->photo->saveAs('photos/' . $fileName);

		$student = Student::model()->updateByPk(Yii::app()->user->id, array('photo' => $fileName));
	}

	/**
	 * Generates random string for filename.
	 * @return string the random string
	 */
	private function randomString()
	{
		$length = 32;
		$chars = array_merge(range(0,9), range('a','z'), range('A','Z'));
		shuffle($chars);
		$randomString = implode(array_slice($chars, 0, $length));

		return $randomString;
	}
}<commit_msg>Mengubah random string generator buatan sendiri menjadi menggunakan extension Randomness<commit_after><?php

/**
 * This model represents the input form for uploading a photo.
 */
class PhotoUploadForm extends CFormModel
{
	public $photo;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			array('photo', 'required'),
			array('photo', 'file', 'types' => 'jpg, png', 'maxSize' => 100 * 1024),
		);
	}

	/**
	 * Declares attribute labels.
	 */
	public function attributeLabels()
	{
		return array(
			'photo' => 'Ganti Foto',
		);
	}

	/**
	 * Saves the uploaded photo and store its information in DB.
	 */
	public function savePhoto()
	{
		// delete old photo
		$student = Student::model()->findByPk(Yii::app()->user->id);
		if ($student->photo !== NULL)
		{
			unlink('photos/' . $student->photo);
		}

		// generate random filename
		Yii::import('ext.randomness.*');
		$length = 32;
		$fileName = Randomness::randomString($length) . '.' . $this->photo->extensionName;
		$student = Student::model()->findByAttributes(array('photo' => $fileName));
		while ($student !== NULL)
		{
			$fileName = Randomness::randomString($length) . '.' . $this->photo->extensionName;
			$student = Student::model()->findByAttributes(array('photo' => $fileName));
		}

		// save photo
		$this->photo->saveAs('photos/' . $fileName);

		$student = Student::model()->updateByPk(Yii::app()->user->id, array('photo' => $fileName));
	}
}
{'fraction_non_alphanumeric': 0.1924364123159304, 'fraction_numerical': 0.007028112449799197, 'mean_word_length': 3.8601626016260164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '7469865', 'n_tokens_mistral': 1070, 'n_tokens_neox': 958, 'n_words': 218}