<commit_before><?php

class Pending extends Eloquent {
	
	use SlackTrait;

	protected $table = "pending";
	protected $timestamps = false;

	public function deleteFile() {
		unlink(Config::get("radio.paths.pending") . "/" . $this->path);
	}

	public function moveFile() {
		rename(Config::get("radio.paths.pending") . "/" . $this->path, Config::get("radio.paths.music") . "/" . $this->path);
	}

	public function getFilesizeAttribute() {
		try {
			$filesize = filesize(Config::get("radio.paths.pending") . "/" . $p["path"]);
		} catch (Exception $e) {
			$filesize = "N/A";
		}

		return $filesize;
	}

	public function getTitleAttribute() {
		return $this->track;
	}

	public function getFilenameAttribute() {
		return $this->origname;
	}

	public function getMetaAttribute() {
		return $this->title ? $this->artist . " - " . $this->title : $this->original;
	}

	public function decline($reason) {
		DB::table("postpending")
			->insert([
				"reason" => $reason,
				"ip" => $this->submitter,
				"accepted" => 0,
				"meta" => $this->meta,
			]);

		$this->slack("pending.declined", ["reason" => $reason]);
		$this->deleteFile();
		$this->delete();
	}

	public function accept($artist, $title, $album, $tags, $good) {
		try {
			Track::create([
				"track" => $title,
				"artist" => $artist,
				"album" => $album,
				"tags" => $tags,
				"path" => $this->path,
				"accepter" => Auth::user()->username,
			]);

			DB::table("postpending")
				->insert([
					"ip" => $this->submitter,
					"accepted" => 1,
					"meta" => "$artist - $title",
					"good_upload" => $good ? 1 : 0,
				]);

			$this->moveFile();
			$this->delete();
		}  catch (Exception $e) {
			// hash already exists
		}
	}

	public function save(array $options = array()) {
		if ($this->id) {
			//$this->slack("track.update");
		} else {
			$this->slack("pending.uploaded");
		}
		return parent::save($options);
	}

}<commit_msg>Correctly check a model exists<commit_after><?php

class Pending extends Eloquent {
	
	use SlackTrait;

	protected $table = "pending";
	public $timestamps = false;

	public function deleteFile() {
		unlink(Config::get("radio.paths.pending") . "/" . $this->path);
	}

	public function moveFile() {
		rename(Config::get("radio.paths.pending") . "/" . $this->path, Config::get("radio.paths.music") . "/" . $this->path);
	}

	public function getFilesizeAttribute() {
		try {
			$filesize = filesize(Config::get("radio.paths.pending") . "/" . $p["path"]);
		} catch (Exception $e) {
			$filesize = "N/A";
		}

		return $filesize;
	}

	public function getTitleAttribute() {
		return $this->track;
	}

	public function getFilenameAttribute() {
		return $this->origname;
	}

	public function getMetaAttribute() {
		return $this->title ? $this->artist . " - " . $this->title : $this->original;
	}

	public function decline($reason) {
		DB::table("postpending")
			->insert([
				"reason" => $reason,
				"ip" => $this->submitter,
				"accepted" => 0,
				"meta" => $this->meta,
			]);

		$this->slack("pending.declined", ["reason" => $reason]);
		$this->deleteFile();
		$this->delete();
	}

	public function accept($artist, $title, $album, $tags, $good) {
		try {
			Track::create([
				"track" => $title,
				"artist" => $artist,
				"album" => $album,
				"tags" => $tags,
				"path" => $this->path,
				"accepter" => Auth::user()->username,
			]);

			DB::table("postpending")
				->insert([
					"ip" => $this->submitter,
					"accepted" => 1,
					"meta" => "$artist - $title",
					"good_upload" => $good ? 1 : 0,
				]);

			$this->moveFile();
			$this->delete();
		}  catch (Exception $e) {
			// hash already exists
		}
	}

	public function replace(Track $track) {
		if (is_null($track)) return;




	}

	public function save(array $options = array()) {
		if ($this->exists) {
			//$this->slack("track.update");
		} else {
			$this->slack("pending.uploaded");
		}
		return parent::save($options);
	}

}
{'fraction_non_alphanumeric': 0.2107014848950333, 'fraction_numerical': 0.002048131080389145, 'mean_word_length': 3.2699453551912567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '4701268', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1376, 'n_words': 269}