From 71cfab79ef4763c3acf8bde39fbbf5417ddf972e Mon Sep 17 00:00:00 2001
From: jo <ljonas@riseup.net>
Date: Thu, 9 Jun 2022 18:05:35 +0200
Subject: [PATCH] feat: rename default stream mount point to main

This will not change the default mount point if you are upgrading.

BREAKING: The default stream mount point changed from `airtime_128` to `main`. Be sure to updates your clients accordingly.
---
 .../migrations/0031_3_0_0_alpha_13_5.py       | 25 +++++++++++++++++++
 .../legacy/migrations/__init__.py             |  2 +-
 .../legacy/migrations/sql/data.sql            |  4 ++-
 docs/admin-manual/icecast.md                  | 10 ++++----
 docs/developer-manual/legacy-api.md           |  2 +-
 legacy/application/models/Preference.php      | 10 ++++++++
 legacy/application/models/StreamSetting.php   |  2 +-
 7 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100644 api/libretime_api/legacy/migrations/0031_3_0_0_alpha_13_5.py

diff --git a/api/libretime_api/legacy/migrations/0031_3_0_0_alpha_13_5.py b/api/libretime_api/legacy/migrations/0031_3_0_0_alpha_13_5.py
new file mode 100644
index 000000000..74faf2600
--- /dev/null
+++ b/api/libretime_api/legacy/migrations/0031_3_0_0_alpha_13_5.py
@@ -0,0 +1,25 @@
+from django.db import migrations
+
+from ._migrations import legacy_migration_factory
+
+UP = """
+INSERT INTO "cc_pref" ("keystr", "valstr") VALUES ('default_stream_mount_point', 'airtime_128');
+"""
+
+DOWN = """
+DELETE FROM "cc_pref" WHERE "keystr" = 'default_stream_mount_point';
+"""
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("legacy", "0030_3_0_0_alpha_13_4"),
+    ]
+    operations = [
+        migrations.RunPython(
+            code=legacy_migration_factory(
+                target="3.0.0-alpha.13.5",
+                sql=UP,
+            )
+        )
+    ]
diff --git a/api/libretime_api/legacy/migrations/__init__.py b/api/libretime_api/legacy/migrations/__init__.py
index 9ee9df2a6..772e6e7fd 100644
--- a/api/libretime_api/legacy/migrations/__init__.py
+++ b/api/libretime_api/legacy/migrations/__init__.py
@@ -1 +1 @@
-LEGACY_SCHEMA_VERSION = "3.0.0-alpha.13.4"
+LEGACY_SCHEMA_VERSION = "3.0.0-alpha.13.5"
diff --git a/api/libretime_api/legacy/migrations/sql/data.sql b/api/libretime_api/legacy/migrations/sql/data.sql
index 9e75a1710..654f3c96b 100644
--- a/api/libretime_api/legacy/migrations/sql/data.sql
+++ b/api/libretime_api/legacy/migrations/sql/data.sql
@@ -31,7 +31,7 @@ INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_user', ''
 INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_pass', 'hackme', 'string');
 INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_admin_user', 'admin', 'string');
 INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_admin_pass', '', 'string');
-INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_mount', 'airtime_128', 'string');
+INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_mount', 'main', 'string');
 INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_url', 'https://libretime.org', 'string');
 INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_description', 'LibreTime Radio! Stream #1', 'string');
 INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_genre', 'genre', 'string');
@@ -370,3 +370,5 @@ INSERT INTO cc_pref("keystr", "valstr") VALUES('whats_new_dialog_viewed', 1);
 INSERT INTO cc_pref("keystr", "valstr") VALUES('podcast_album_override', 1);
 INSERT INTO cc_pref("keystr", "valstr") VALUES('podcast_auto_smartblock', 0);
 -- end
+
+INSERT INTO cc_pref("keystr", "valstr") VALUES('default_stream_mount_point', 'main');
diff --git a/docs/admin-manual/icecast.md b/docs/admin-manual/icecast.md
index bb86d5d48..bb8c769c4 100644
--- a/docs/admin-manual/icecast.md
+++ b/docs/admin-manual/icecast.md
@@ -46,17 +46,17 @@ The Icecast server has a _fallback-mount_ feature which can be used to move clie
 
 To enable fallback mounts, edit the main Icecast configuration file (`/etc/icecast2/icecast.xml`) to define the mount points you will use, and the relationship between them.
 
-The example mount section provided in the `icecast.xml` file is commented out by default. Before or after the commented section, add three mount point definitions. The default mount point used by LibreTime is `/airtime_128` which is shown in the `/etc/libretime/liquidsoap.cfg` file. You must also define a mount point for the live source (ex. `/live.ogg`) and a mount point for the public to connect to (ex. `/stream.ogg`).
+The example mount section provided in the `icecast.xml` file is commented out by default. Before or after the commented section, add three mount point definitions. The default mount point used by LibreTime is `/main` which is shown in the `/etc/libretime/liquidsoap.cfg` file. You must also define a mount point for the live source (ex. `/live.ogg`) and a mount point for the public to connect to (ex. `/stream.ogg`).
 
 ```xml title="/etc/icecast2/icecast.xml"
 <mount>
-     <mount-name>/airtime_128</mount-name>
+     <mount-name>/main</mount-name>
      <hidden>0</hidden>
 </mount>
 
 <mount>
      <mount-name>/live.ogg</mount-name>
-     <fallback-mount>/airtime_128</fallback-mount>
+     <fallback-mount>/main</fallback-mount>
      <fallback-override>1</fallback-override>
      <hidden>0</hidden>
 </mount>
@@ -69,9 +69,9 @@ The example mount section provided in the `icecast.xml` file is commented out by
 </mount>
 ```
 
-These mount point definitions mean that a client connecting to a URL such as *http://icecast.example.com:8000/stream.ogg* will first fall back to the `/live.ogg` mount point if it is available. If not, the client will fall back in turn to the `/airtime_128` mount point for LibreTime playout.
+These mount point definitions mean that a client connecting to a URL such as *http://icecast.example.com:8000/stream.ogg* will first fall back to the `/live.ogg` mount point if it is available. If not, the client will fall back in turn to the `/main` mount point for LibreTime playout.
 
-Setting the value of _fallback-override_ to 1 (enabled) means that when the `/live.ogg` mount point becomes available again, the client will be re-connected to it. If you wish to hide the `/airtime_128` and `/live.ogg` mount points from the public Icecast web interface, set the value of _hidden_ in each of these definitions to 1.
+Setting the value of _fallback-override_ to 1 (enabled) means that when the `/live.ogg` mount point becomes available again, the client will be re-connected to it. If you wish to hide the `/main` and `/live.ogg` mount points from the public Icecast web interface, set the value of _hidden_ in each of these definitions to 1.
 
 ## Source configuration
 
diff --git a/docs/developer-manual/legacy-api.md b/docs/developer-manual/legacy-api.md
index a687e2ad8..cc57f02ad 100644
--- a/docs/developer-manual/legacy-api.md
+++ b/docs/developer-manual/legacy-api.md
@@ -36,7 +36,7 @@ For example, using the action _get-stream-setting_ returns the following output
 
 {"keyname":"s1_port","value":"8000","type":"integer"},
 
-{"keyname":"s1_mount","value":"airtime_128","type":"string"},
+{"keyname":"s1_mount","value":"main","type":"string"},
 
 {"keyname":"s1_url","value":"http:\/\/airtime.sourcefabric.org","type":"string"},
 
diff --git a/legacy/application/models/Preference.php b/legacy/application/models/Preference.php
index 82af5caef..a646b6e53 100644
--- a/legacy/application/models/Preference.php
+++ b/legacy/application/models/Preference.php
@@ -1452,6 +1452,16 @@ class Application_Model_Preference
         self::setValue('default_icecast_password', $value);
     }
 
+    public static function getDefaultStreamMountPoint()
+    {
+        return self::getValue('default_stream_mount_point');
+    }
+
+    public static function setDefaultStreamMountPoint($value)
+    {
+        self::setValue('default_stream_mount_point', $value);
+    }
+
     public static function getRadioPageDisplayLoginButton()
     {
         return self::getValue('radio_page_display_login_button');
diff --git a/legacy/application/models/StreamSetting.php b/legacy/application/models/StreamSetting.php
index 6546cb101..f1392c671 100644
--- a/legacy/application/models/StreamSetting.php
+++ b/legacy/application/models/StreamSetting.php
@@ -289,7 +289,7 @@ class Application_Model_StreamSetting
             'user' => $config['stationId'],
             'pass' => Application_Model_Preference::getDefaultIcecastPassword(),
             // Manually setting default mountpoint
-            'mount' => 'airtime_128',
+            'mount' => Application_Model_Preference::getDefaultStreamMountpoint(),
         ];
     }