Merge branch 'master' of dev.sourcefabric.org:airtime

This commit is contained in:
denise 2013-05-08 12:06:00 -04:00
commit b4dc17f7e8
5 changed files with 86 additions and 8 deletions

View File

@ -2,9 +2,11 @@
class Application_Common_Database
{
public static function prepareAndExecute($sql, array $paramValueMap,
$type='all', $fetchType=PDO::FETCH_ASSOC)
$type='all', $fetchType=PDO::FETCH_ASSOC, $con=null)
{
if (is_null($con)) {
$con = Propel::getConnection();
}
$stmt = $con->prepare($sql);
foreach ($paramValueMap as $param => $v) {
$stmt->bindValue($param, $v);

View File

@ -33,6 +33,7 @@ class Application_Model_Block implements Application_Model_LibraryEditable
"cueout" => "00:00:00",
"fadein" => "0.0",
"fadeout" => "0.0",
"crossfadeDuration" => 0
);
//using propel's phpNames.
@ -101,6 +102,7 @@ class Application_Model_Block implements Application_Model_LibraryEditable
$this->blockItem["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
$this->blockItem["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
$this->blockItem["crossfadeDuration"] = Application_Model_Preference::GetDefaultCrossfadeDuration();
$this->con = isset($con) ? $con : Propel::getConnection(CcBlockPeer::DATABASE_NAME);
$this->id = $this->block->getDbId();
@ -390,6 +392,7 @@ SQL;
$row->setDbCueout($info["cueout"]);
$row->setDbFadein(Application_Common_DateHelper::secondsToPlaylistTime($info["fadein"]));
$row->setDbFadeout(Application_Common_DateHelper::secondsToPlaylistTime($info["fadeout"]));
$row->setDbTrackOffset($info["crossfadeDuration"]);
$row->save($this->con);
// above save result update on cc_block table on length column.
// but $this->block doesn't get updated automatically

View File

@ -11,6 +11,9 @@ class Application_Model_Preference
private static function setValue($key, $value, $isUserValue = false, $userId = null)
{
try {
$con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
$con->beginTransaction();
//called from a daemon process
if (!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
$id = NULL;
@ -35,7 +38,11 @@ class Application_Model_Preference
$paramMap[':id'] = $userId;
}
$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, 'column');
$result = Application_Common_Database::prepareAndExecute($sql,
$paramMap,
'column',
PDO::FETCH_ASSOC,
$con);
$paramMap = array();
if ($result > 1) {
@ -80,9 +87,15 @@ class Application_Model_Preference
$paramMap[':key'] = $key;
$paramMap[':value'] = $value;
Application_Common_Database::prepareAndExecute($sql, $paramMap, 'execute');
Application_Common_Database::prepareAndExecute($sql,
$paramMap,
'execute',
PDO::FETCH_ASSOC,
$con);
$con->commit();
} catch (Exception $e) {
$con->rollback();
header('HTTP/1.0 503 Service Unavailable');
Logging::info("Database error: ".$e->getMessage());
exit;

View File

@ -82,7 +82,9 @@ AudioPlayout.prototype.loadData = function (audioData, cb) {
that.buffer = buffer;
cb(buffer);
},
Error
function(err) {
console.log("err(decodeAudioData): "+err);
}
);
};

View File

@ -214,6 +214,57 @@ class AirtimeIni
fclose($fp);
}
//stupid hack found on http://stackoverflow.com/a/1268642/276949
//with some modifications: 1) Spaces are inserted in between sections and
//2) numeric values are not quoted.
public static function write_ini_file($assoc_arr, $path, $has_sections = false) {
$content = "";
if ($has_sections) {
$first_line = true;
foreach ($assoc_arr as $key=>$elem) {
if ($first_line) {
$content .= "[".$key."]\n";
$first_line = false;
} else {
$content .= "\n[".$key."]\n";
}
foreach ($elem as $key2=>$elem2) {
if(is_array($elem2))
{
for($i=0;$i<count($elem2);$i++)
{
$content .= $key2."[] = \"".$elem2[$i]."\"\n";
}
}
else if($elem2=="") $content .= $key2." = \n";
else $content .= $key2." = ".$elem2."\n";
}
}
} else {
foreach ($assoc_arr as $key=>$elem) {
if(is_array($elem))
{
for($i=0;$i<count($elem);$i++)
{
$content .= $key."[] = \"".$elem[$i]."\"\n";
}
}
else if($elem=="") $content .= $key." = \n";
else $content .= $key." = ".$elem."\n";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
if (!fwrite($handle, $content)) {
return false;
}
fclose($handle);
return true;
}
/**
* After the configuration files have been copied to /etc/airtime,
* this function will update them to values unique to this
@ -223,10 +274,17 @@ class AirtimeIni
{
$api_key = AirtimeIni::GenerateRandomString();
if (getenv("web") == "t"){
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_AIRTIME, 'api_key', $api_key);
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_AIRTIME, 'airtime_dir', AirtimeInstall::CONF_DIR_WWW);
$ini = parse_ini_file(AirtimeIni::CONF_FILE_AIRTIME, true);
$ini['general']['api_key'] = $api_key;
$ini['general']['airtime_dir'] = AirtimeInstall::CONF_DIR_WWW;
AirtimeIni::write_ini_file($ini, AirtimeIni::CONF_FILE_AIRTIME, true);
}
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_API_CLIENT, 'api_key', "'$api_key'");
$ini = parse_ini_file(AirtimeIni::CONF_FILE_API_CLIENT);
$ini['api_key'] = "'$api_key'";
AirtimeIni::write_ini_file($ini, AirtimeIni::CONF_FILE_API_CLIENT, false);
}
public static function ReadPythonConfig($p_filename)