feat: move stream liquisoap status to pref table
This commit is contained in:
parent
6c59ff588b
commit
2b533d4724
|
@ -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,
|
||||
)
|
||||
)
|
||||
]
|
|
@ -1 +1 @@
|
|||
LEGACY_SCHEMA_VERSION = "3.0.0-alpha.14.1"
|
||||
LEGACY_SCHEMA_VERSION = "3.0.0-alpha.14.2"
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue