feat: move stream liquisoap status to pref table

This commit is contained in:
jo 2022-08-06 19:57:13 +02:00 committed by Kyle Robbertze
parent 6c59ff588b
commit 2b533d4724
6 changed files with 54 additions and 75 deletions

View file

@ -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;
}
}

View file

@ -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();