about summary refs log tree commit diff
path: root/laravel/app
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2021-09-30 04:50:48 +0000
committerZach DeCook <zachdecook@librem.one>2021-09-30 04:50:48 +0000
commitda953d463678613e1da83bd23a9ca117a8a3289d (patch)
treead9ce3b401cc45452022b64935c272793b02e2a5 /laravel/app
parent753593fe0d25a5cc58ca84fbbccc24bd9c6e6e1e (diff)
downloadprosongsa-da953d463678613e1da83bd23a9ca117a8a3289d.tar.gz
* Song: Transition to file-based storage for text field
Diffstat (limited to 'laravel/app')
-rw-r--r--laravel/app/Song.php11
1 files changed, 11 insertions, 0 deletions
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;