From 2b533d47249bb45cf7b2cc9d6a1d02db17459ab8 Mon Sep 17 00:00:00 2001 From: jo Date: Sat, 6 Aug 2022 19:57:13 +0200 Subject: [PATCH] feat: move stream liquisoap status to pref table --- .../migrations/0038_3_0_0_alpha_14_2.py | 29 ++++++++ .../legacy/migrations/__init__.py | 2 +- .../application/controllers/ApiController.php | 2 +- .../controllers/PreferenceController.php | 4 +- legacy/application/models/Preference.php | 21 ++++++ legacy/application/models/StreamSetting.php | 71 ------------------- 6 files changed, 54 insertions(+), 75 deletions(-) create mode 100644 api/libretime_api/legacy/migrations/0038_3_0_0_alpha_14_2.py diff --git a/api/libretime_api/legacy/migrations/0038_3_0_0_alpha_14_2.py b/api/libretime_api/legacy/migrations/0038_3_0_0_alpha_14_2.py new file mode 100644 index 000000000..4c6f8df00 --- /dev/null +++ b/api/libretime_api/legacy/migrations/0038_3_0_0_alpha_14_2.py @@ -0,0 +1,29 @@ +# pylint: disable=invalid-name + +from django.db import migrations + +from ._migrations import legacy_migration_factory + +UP = """ +delete from cc_stream_setting +where "keyname" like '%_liquidsoap_error'; +""" + +DOWN = """ +delete from cc_pref +where "keystr" like 'stream_liquidsoap_status:%'; +""" + + +class Migration(migrations.Migration): + dependencies = [ + ("legacy", "0037_3_0_0_alpha_14_1"), + ] + operations = [ + migrations.RunPython( + code=legacy_migration_factory( + target="3.0.0-alpha.14.2", + sql=UP, + ) + ) + ] diff --git a/api/libretime_api/legacy/migrations/__init__.py b/api/libretime_api/legacy/migrations/__init__.py index a0fe2c890..d3d94c745 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.14.1" +LEGACY_SCHEMA_VERSION = "3.0.0-alpha.14.2" diff --git a/legacy/application/controllers/ApiController.php b/legacy/application/controllers/ApiController.php index 5efa1b245..b519e5e5d 100644 --- a/legacy/application/controllers/ApiController.php +++ b/legacy/application/controllers/ApiController.php @@ -1100,7 +1100,7 @@ class ApiController extends Zend_Controller_Action $stream_id = $request->getParam('stream_id'); $boot_time = $request->getParam('boot_time'); - Application_Model_StreamSetting::setLiquidsoapError($stream_id, $msg, $boot_time); + Application_Model_Preference::setLiquidsoapError($stream_id, $msg, $boot_time); } public function updateSourceStatusAction() diff --git a/legacy/application/controllers/PreferenceController.php b/legacy/application/controllers/PreferenceController.php index 83103afa8..11a7d62ac 100644 --- a/legacy/application/controllers/PreferenceController.php +++ b/legacy/application/controllers/PreferenceController.php @@ -301,7 +301,7 @@ class PreferenceController extends Zend_Controller_Action $info = Application_Model_StreamSetting::getStreamSetting(); $data['setting'] = $info; for ($i = 1; $i <= $num_of_stream; ++$i) { - Application_Model_StreamSetting::setLiquidsoapError($i, 'waiting'); + Application_Model_Preference::setLiquidsoapError($i, 'waiting'); } Application_Model_RabbitMq::SendMessageToPypo('update_stream_setting', $data); @@ -395,7 +395,7 @@ class PreferenceController extends Zend_Controller_Action $out = []; $num_of_stream = intval(Application_Model_Preference::GetNumOfStreams()); for ($i = 1; $i <= $num_of_stream; ++$i) { - $status = Application_Model_StreamSetting::getLiquidsoapError($i); + $status = Application_Model_Preference::getLiquidsoapError($i); $status = $status == null ? _('Problem with Liquidsoap...') : $status; if (!Application_Model_StreamSetting::getStreamEnabled($i)) { $status = 'N/A'; diff --git a/legacy/application/models/Preference.php b/legacy/application/models/Preference.php index 046095d8a..9b78a9e41 100644 --- a/legacy/application/models/Preference.php +++ b/legacy/application/models/Preference.php @@ -1656,4 +1656,25 @@ class Application_Model_Preference { return self::setValue('feature_preview_mode', $value); } + + /* + * Stores liquidsoap status if $boot_time > save time. + * save time is the time that user clicked save on stream setting page + */ + public static function setLiquidsoapError($stream_id, $msg, $boot_time = null) + { + $update_time = Application_Model_Preference::GetStreamUpdateTimestemp(); + + if ($boot_time == null || $boot_time > $update_time) { + $stream_id = trim($stream_id, 's'); + self::setValue("stream_liquidsoap_status:{$stream_id}", $msg); + } + } + + public static function getLiquidsoapError($stream_id) + { + $result = self::getValue("stream_liquidsoap_status:{$stream_id}"); + + return ($result !== false) ? $result : null; + } } diff --git a/legacy/application/models/StreamSetting.php b/legacy/application/models/StreamSetting.php index 7dbbf5580..6ed30f486 100644 --- a/legacy/application/models/StreamSetting.php +++ b/legacy/application/models/StreamSetting.php @@ -314,77 +314,6 @@ class Application_Model_StreamSetting } } - /* - * Stores liquidsoap status if $boot_time > save time. - * save time is the time that user clicked save on stream setting page - */ - public static function setLiquidsoapError($stream_id, $msg, $boot_time = null) - { - $con = Propel::getConnection(); - - $update_time = Application_Model_Preference::GetStreamUpdateTimestemp(); - - if ($boot_time == null || $boot_time > $update_time) { - $keyname = 's' . $stream_id . '_liquidsoap_error'; - $sql = 'SELECT COUNT(*) FROM cc_stream_setting' - . ' WHERE keyname = :keyname'; - - $stmt = $con->prepare($sql); - $stmt->bindParam(':keyname', $keyname); - - if ($stmt->execute()) { - $result = $stmt->fetchColumn(0); - } else { - $msg = implode(',', $stmt->errorInfo()); - - throw new Exception("Error: {$msg}"); - } - - if ($result == 1) { - $sql = 'UPDATE cc_stream_setting' - . ' SET value = :msg' - . ' WHERE keyname = :keyname'; - } else { - $sql = 'INSERT INTO cc_stream_setting (keyname, value, type)' - . " VALUES (:keyname, :msg, 'string')"; - } - - $stmt = $con->prepare($sql); - $stmt->bindParam(':keyname', $keyname); - $stmt->bindParam(':msg', $msg); - - if ($stmt->execute()) { - // do nothing - } else { - $msg = implode(',', $stmt->errorInfo()); - - throw new Exception("Error: {$msg}"); - } - } - } - - public static function getLiquidsoapError($stream_id) - { - $con = Propel::getConnection(); - - $keyname = 's' . $stream_id . '_liquidsoap_error'; - $sql = 'SELECT value FROM cc_stream_setting' - . ' WHERE keyname = :keyname'; - - $stmt = $con->prepare($sql); - $stmt->bindParam(':keyname', $keyname); - - if ($stmt->execute()) { - $result = $stmt->fetchColumn(0); - } else { - $msg = implode(',', $stmt->errorInfo()); - - throw new Exception("Error: {$msg}"); - } - - return ($result !== false) ? $result : null; - } - public static function getStreamEnabled($stream_id) { $con = Propel::getConnection();