Merge branch '2.0.x' of dev.sourcefabric.org:airtime into 2.0.x

This commit is contained in:
James 2012-01-25 14:12:42 -05:00
commit 192c30bacc
5 changed files with 166 additions and 32 deletions

View File

@ -5,7 +5,7 @@
/**
* Skeleton subclass for representing a row from the 'cc_show_instances' table.
*
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
@ -15,4 +15,25 @@
*/
class CcShowInstances extends BaseCcShowInstances {
public function computeDbTimeFilled(PropelPDO $con)
{
$stmt = $con->prepare('SELECT SUM(clip_length) FROM "cc_schedule" WHERE cc_schedule.INSTANCE_ID = :p1');
$stmt->bindValue(':p1', $this->getDbId());
$stmt->execute();
$result = $stmt->fetchColumn();
//$result is in the form H:i:s.u
//patch fix for the current problem of > 23:59:59.99 for a show content
//which causes problems with a time without timezone column type
try {
$dt = new DateTime($result);
}
catch(Exception $e) {
$result = "23:59:59";
}
return $result;
}
} // CcShowInstances

View File

@ -234,4 +234,16 @@ class UpgradeCommon{
}
fclose($fp);
}
public static function queryDb($p_sql){
global $CC_DBC;
$result = $CC_DBC->query($p_sql);
if (PEAR::isError($result)) {
echo "Error executing $sql. Exiting.";
exit(1);
}
return $result;
}
}

View File

@ -32,8 +32,10 @@ class AirtimeDatabaseUpgrade{
public static function start(){
self::doDbMigration();
self::SetDefaultTimezone();
self::setPhpDefaultTimeZoneToSystemTimezone();
self::SetDefaultTimezone();
echo "* Converting database to store all schedule times in UTC. This may take a a while...".PHP_EOL;
self::convert_cc_playlist();
self::convert_cc_schedule();
self::convert_cc_show_days();
@ -69,7 +71,29 @@ class AirtimeDatabaseUpgrade{
}
private static function convert_cc_playlist(){
/* cc_playlist has a field that keeps track of when the playlist was last modified. */
echo " * Converting playlists to UTC".PHP_EOL;
$sql = "SELECT * FROM cc_playlist";
$result = UpgradeCommon::queryDb($sql);
while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)){
$dt = new DateTime($row['mtime'], new DateTimeZone(date_default_timezone_get()));
$dt->setTimezone(new DateTimeZone("UTC"));
$id = $row['id'];
$mtime = $dt->format("Y-m-d H:i:s");
$sql = "UPDATE cc_playlist SET mtime = '$mtime' WHERE id = $id";
UpgradeCommon::queryDb($sql);
//echo ".";
//flush();
//usleep(100000);
}
/*
echo " * Converting playlists to UTC".PHP_EOL;
// cc_playlist has a field that keeps track of when the playlist was last modified.
$playlists = CcPlaylistQuery::create()->find();
foreach ($playlists as $pl){
@ -78,11 +102,39 @@ class AirtimeDatabaseUpgrade{
$pl->setDbMtime($dt);
$pl->save();
}
*/
}
private static function convert_cc_schedule(){
/* cc_schedule has start and end fields that need to be changed to UTC. */
echo " * Converting schedule to UTC".PHP_EOL;
$sql = "SELECT * FROM cc_schedule";
$result = UpgradeCommon::queryDb($sql);
while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)){
$dtStarts = new DateTime($row['starts'], new DateTimeZone(date_default_timezone_get()));
$dtStarts->setTimezone(new DateTimeZone("UTC"));
$dtEnds = new DateTime($row['ends'], new DateTimeZone(date_default_timezone_get()));
$dtEnds->setTimezone(new DateTimeZone("UTC"));
$id = $row['id'];
$starts = $dtStarts->format("Y-m-d H:i:s");
$ends = $dtEnds->format("Y-m-d H:i:s");
$sql = "UPDATE cc_schedule SET starts = '$starts', ends = '$ends' WHERE id = $id";
UpgradeCommon::queryDb($sql);
//echo ".";
//flush();
//usleep(100000);
}
/*
echo " * Converting schedule to UTC".PHP_EOL;
//cc_schedule has start and end fields that need to be changed to UTC.
$schedules = CcScheduleQuery::create()->find();
foreach ($schedules as $s){
@ -95,35 +147,69 @@ class AirtimeDatabaseUpgrade{
$s->setDbEnds($dt);
$s->save();
echo ".";
}
* */
}
private static function convert_cc_show_days(){
/* cc_show_days has first_show, last_show and start_time fields that need to be changed to UTC. */
echo " * Converting show days to UTC".PHP_EOL;
$sql = "SELECT * FROM cc_show_days";
$result = UpgradeCommon::queryDb($sql);
while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)){
$id = $row['id'];
$timezone = date_default_timezone_get();
$sql = "UPDATE cc_show_days SET timezone = '$timezone' WHERE id = $id";
UpgradeCommon::queryDb($sql);
//echo ".";
//flush();
//usleep(100000);
}
/*
// cc_show_days has first_show, last_show and start_time fields that need to be changed to UTC.
$showDays = CcShowDaysQuery::create()->find();
foreach ($showDays as $sd){
/*
$dt = new DateTime($sd->getDbFirstShow()." ".$sd->getDbStartTime(), new DateTimeZone(date_default_timezone_get()));
$dt->setTimezone(new DateTimeZone("UTC"));
$sd->setDbFirstShow($dt->format("Y-m-d"));
$sd->setDbStartTime($dt->format("H:i:s"));
$dt = new DateTime($sd->getDbLastShow()." ".$sd->getDbStartTime(), new DateTimeZone(date_default_timezone_get()));
$dt->setTimezone(new DateTimeZone("UTC"));
$sd->setDbLastShow($dt->format("Y-m-d"));
$sd->save();
* */
foreach ($showDays as $sd){
$sd->setDbTimezone(date_default_timezone_get())->save();
echo ".";
}
*/
}
private static function convert_cc_show_instances(){
/* convert_cc_show_instances has starts and ends fields that need to be changed to UTC. */
echo " * Converting show instances to UTC".PHP_EOL;
// convert_cc_show_instances has starts and ends fields that need to be changed to UTC.
$sql = "SELECT * FROM cc_show_instances";
$result = UpgradeCommon::queryDb($sql);
while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)){
$dtStarts = new DateTime($row['starts'], new DateTimeZone(date_default_timezone_get()));
$dtStarts->setTimezone(new DateTimeZone("UTC"));
$dtEnds = new DateTime($row['ends'], new DateTimeZone(date_default_timezone_get()));
$dtEnds->setTimezone(new DateTimeZone("UTC"));
$id = $row['id'];
$starts = $dtStarts->format("Y-m-d H:i:s");
$ends = $dtEnds->format("Y-m-d H:i:s");
$sql = "UPDATE cc_show_instances SET starts = '$starts', ends = '$ends' WHERE id = $id";
UpgradeCommon::queryDb($sql);
//echo ".";
//flush();
//usleep(100000);
}
/*
$showInstances = CcShowInstancesQuery::create()->find();
foreach ($showInstances as $si){
@ -136,7 +222,10 @@ class AirtimeDatabaseUpgrade{
$si->setDbEnds($dt);
$si->save();
echo ".";
}
* */
}
private static function doDbMigration(){
@ -356,9 +445,17 @@ class AirtimeMiscUpgrade{
}
}
echo "Pausing Pypo".PHP_EOL;
exec("/etc/init.d/airtime-playout stop");
while (@ob_end_flush());
UpgradeCommon::connectToDatabase();
AirtimeDatabaseUpgrade::start();
AirtimeStorWatchedDirsUpgrade::start();
AirtimeConfigFileUpgrade::start();
AirtimeMiscUpgrade::start();
//echo "Resuming Pypo".PHP_EOL;
//exec("/etc/init.d/airtime-playout start");

View File

@ -106,13 +106,13 @@ try:
print "* Waiting for pypo processes to start..."
if os.environ["liquidsoap_keep_alive"] == "f":
print " * Restarting any previous Liquidsoap instances"
p = Popen("/etc/init.d/airtime-playout stop", shell=True)
p = Popen("/etc/init.d/airtime-playout stop > /dev/null 2>&1", shell=True)
sts = os.waitpid(p.pid, 0)[1]
else:
print " * Keeping any previous Liquidsoap instances running"
p = Popen("/etc/init.d/airtime-playout pypo-stop", shell=True)
p = Popen("/etc/init.d/airtime-playout pypo-stop > /dev/null 2>&1", shell=True)
sts = os.waitpid(p.pid, 0)[1]
p = Popen("/etc/init.d/airtime-playout start-no-monit", shell=True)
p = Popen("/etc/init.d/airtime-playout start-no-monit > /dev/null 2>&1", shell=True)
sts = os.waitpid(p.pid, 0)[1]
except Exception, e:

View File

@ -2,7 +2,7 @@
The purpose of this script is to consolidate into one location where
we need to update database host, dbname, username and password.
This script reads from airtime.conf.
This script reads from /etc/airtime/airtime.conf.
"""
import os
import sys
@ -14,9 +14,11 @@ if os.geteuid() != 0:
print "Please run this as root."
sys.exit(1)
airtime_conf = '/etc/airtime/airtime.conf'
#Read the universal values
parser = ConfigParser.SafeConfigParser()
parser.read('/etc/airtime/airtime.conf')
parser.read(airtime_conf)
host = 'resources.db.params.host'
dbname = 'resources.db.params.dbname'
@ -24,7 +26,11 @@ username = 'resources.db.params.username'
password = 'resources.db.params.password'
airtime_dir = parser.get('general', 'airtime_dir')
print 'Airtime root folder found at %s' % airtime_dir
if os.path.exists(airtime_dir):
print 'Airtime root folder found at %s' % airtime_dir
else:
print 'Could not find Airtime root folder specified by "airtime_dir" in %s' % airtime_conf
sys.exit(1)
print ("Updating %s/application/configs/application.ini" % airtime_dir)
f = file('%s/application/configs/application.ini' % airtime_dir,'r')
@ -47,7 +53,7 @@ f.writelines(file_lines)
f.close()
print ("Updating %s/build.properties" % airtime_dir)
print ("Updating %s/build/build.properties" % airtime_dir)
f = file('%s/build/build.properties' % airtime_dir, 'r')
file_lines = []
@ -66,7 +72,7 @@ f = file('%s/build/build.properties' % airtime_dir, 'w')
f.writelines(file_lines)
f.close()
print ("Updating %s/runtime-conf.xml" % airtime_dir)
print ("Updating %s/build/runtime-conf.xml" % airtime_dir)
doc = xml.dom.minidom.parse('%s/build/runtime-conf.xml' % airtime_dir)
@ -78,6 +84,4 @@ xml_file = open('%s/build/runtime-conf.xml' % airtime_dir, "w")
xml_file.writelines(doc.toxml('utf-8'))
xml_file.close()
print 'Regenerating propel-config.php'
os.system('cd %s/build && %s/library/propel/generator/bin/propel-gen' % (airtime_dir, airtime_dir))
print "Success!"