From da953d463678613e1da83bd23a9ca117a8a3289d Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Thu, 30 Sep 2021 04:50:48 +0000 Subject: * Song: Transition to file-based storage for text field --- laravel/app/Song.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'laravel/app') diff --git a/laravel/app/Song.php b/laravel/app/Song.php index 41fbea0..f31c7ce 100644 --- a/laravel/app/Song.php +++ b/laravel/app/Song.php @@ -36,6 +36,17 @@ class Song extends Model // TODO: Validate that this is plain. return trim($this->key, "m"); } + public function getTextAttribute($text) + { + return $text ?: file_get_contents("public/text/{$this->id}.txt"); + } + public function setTextAttribute($text) + { + // Watch out, this saves immediately! + if ($text && file_put_contents("public/text/{$this->id}.txt", $text)) { + $this->attributes['text'] = null; + } + } public function getChordsAttribute($txt = null) { $txt = $txt ?? $this->text; -- cgit 1.4.1