Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

Conflicts:
	airtime_mvc/application/controllers/PlaylistController.php
This commit is contained in:
James 2012-08-23 10:43:28 -04:00
commit c2d475e6d8
57 changed files with 1304 additions and 703 deletions

View file

@ -8,7 +8,7 @@ require_once 'formatters/LengthFormatter.php';
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
*/
class Application_Model_Block
class Application_Model_Block implements Application_Model_LibraryEditable
{
/**
* propel connection object.
@ -188,11 +188,11 @@ class Application_Model_Block
*/
public function getContents($filterFiles=false)
{
Logging::log("Getting contents for block {$this->id}");
Logging::info("Getting contents for block {$this->id}");
$files = array();
$sql = <<<"EOT"
SELECT pc.id as id, pc.position, pc.cliplength as length, pc.cuein, pc.cueout, pc.fadein, pc.fadeout, bl.type,
SELECT pc.id as id, pc.position, pc.cliplength as length, pc.cuein, pc.cueout, pc.fadein, pc.fadeout, bl.type, f.length as orig_length,
f.id as item_id, f.track_title, f.artist_name as creator, f.file_exists as exists, f.filepath as path FROM cc_blockcontents AS pc
LEFT JOIN cc_files AS f ON pc.file_id=f.id
LEFT JOIN cc_block AS bl ON pc.block_id = bl.id
@ -220,6 +220,10 @@ EOT;
$fades = $this->getFadeInfo($row['position']);
$row['fadein'] = $fades[0];
$row['fadeout'] = $fades[1];
//format original length
$formatter = new LengthFormatter($row['orig_length']);
$row['orig_length'] = $formatter->format();
}
return $rows;
@ -383,11 +387,11 @@ EOT;
try {
if (is_numeric($p_afterItem)) {
Logging::log("Finding block content item {$p_afterItem}");
Logging::info("Finding block content item {$p_afterItem}");
$afterItem = CcBlockcontentsQuery::create()->findPK($p_afterItem);
$index = $afterItem->getDbPosition();
Logging::log("index is {$index}");
Logging::info("index is {$index}");
$pos = ($addType == 'after') ? $index + 1 : $index;
$contentsToUpdate = CcBlockcontentsQuery::create()
@ -396,8 +400,8 @@ EOT;
->orderByDbPosition()
->find($this->con);
Logging::log("Adding to block");
Logging::log("at position {$pos}");
Logging::info("Adding to block");
Logging::info("at position {$pos}");
} else {
//add to the end of the block
@ -420,12 +424,12 @@ EOT;
->orderByDbPosition()
->find($this->con);
Logging::log("Adding to block");
Logging::log("at position {$pos}");
Logging::info("Adding to block");
Logging::info("at position {$pos}");
}
foreach ($p_items as $ac) {
Logging::log("Adding audio file {$ac}");
Logging::info("Adding audio file {$ac}");
if (is_array($ac) && $ac[1] == 'audioclip') {
$res = $this->insertBlockElement($this->buildEntry($ac[0], $pos));
@ -481,32 +485,32 @@ EOT;
$pos = 0;
//moving items to beginning of the block.
if (is_null($p_afterItem)) {
Logging::log("moving items to beginning of block");
Logging::info("moving items to beginning of block");
foreach ($contentsToMove as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
Logging::info("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
}
foreach ($otherContent as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
Logging::info("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
}
} else {
Logging::log("moving items after {$p_afterItem}");
Logging::info("moving items after {$p_afterItem}");
foreach ($otherContent as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
Logging::info("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
if ($item->getDbId() == $p_afterItem) {
foreach ($contentsToMove as $move) {
Logging::log("item {$move->getDbId()} to pos {$pos}");
Logging::info("item {$move->getDbId()} to pos {$pos}");
$move->setDbPosition($pos);
$move->save($this->con);
$pos = $pos + 1;
@ -566,7 +570,7 @@ EOT;
public function getFadeInfo($pos)
{
Logging::log("Getting fade info for pos {$pos}");
Logging::info("Getting fade info for pos {$pos}");
$row = CcBlockcontentsQuery::create()
->joinWith(CcFilesPeer::OM_CLASS)
@ -651,7 +655,7 @@ EOT;
public function setfades($fadein, $fadeout)
{
if (isset($fadein)) {
Logging::log("Setting block fade in {$fadein}");
Logging::info("Setting block fade in {$fadein}");
$row = CcBlockcontentsQuery::create()
->filterByDbBlockId($this->id)
->filterByDbPosition(0)
@ -661,7 +665,7 @@ EOT;
}
if (isset($fadeout)) {
Logging::log("Setting block fade out {$fadeout}");
Logging::info("Setting block fade out {$fadeout}");
$row = CcBlockcontentsQuery::create()
->filterByDbBlockId($this->id)
->filterByDbPosition($this->getSize()-1)
@ -839,7 +843,7 @@ EOT;
return $this->$method();
}
public function setMetaData($category, $value)
public function setMetadata($category, $value)
{
$cat = $this->categories[$category];
@ -871,11 +875,20 @@ EOT;
*/
public static function deleteBlocks($p_ids, $p_userId)
{
$leftOver = self::blocksNotOwnedByUser($p_ids, $p_userId);
if (count($leftOver) == 0) {
CcBlockQuery::create()->findPKs($p_ids)->delete();
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id);
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
if (!$isAdminOrPM) {
$leftOver = self::blocksNotOwnedByUser($p_ids, $p_userId);
if (count($leftOver) == 0) {
CcBlockQuery::create()->findPKs($p_ids)->delete();
} else {
throw new BlockNoPermissionException;
}
} else {
throw new BlockNoPermissionException;
CcBlockQuery::create()->findPKs($p_ids)->delete();
}
}
@ -979,7 +992,7 @@ EOT;
public function storeCriteriaIntoDb($p_criteriaData){
// delete criteria under $p_blockId
CcBlockcriteriaQuery::create()->findByDbBlockId($this->id)->delete();
Logging::log($p_criteriaData);
Logging::info($p_criteriaData);
//insert modifier rows
if (isset($p_criteriaData['criteria'])) {
$critKeys = array_keys($p_criteriaData['criteria']);
@ -1141,10 +1154,21 @@ EOT;
// if the column is timestamp, convert it into UTC
if ($column->getType() == PropelColumnTypes::TIMESTAMP) {
$spCriteriaValue = Application_Common_DateHelper::ConvertToUtcDateTimeString($criteria['value']);
} else if($spCriteria == "bit_rate") {
/* Check if only a date was supplied and trim
* the time after it is converted to UTC time
*/
if (strlen($criteria['value']) <= 10) {
//extract date only from timestamp in db
$spCriteria = 'date('.$spCriteria.')';
$spCriteriaValue = substr($spCriteriaValue, 0, 10);
}
} else if($spCriteria == "bit_rate" || $spCriteria == 'sample_rate') {
// multiply 1000 because we store only number value
// e.g 192kps is stored as 192000
$spCriteriaValue = $criteria['value']*1000;
if (isset($criteria['extra'])) {
$criteria['extra'] *= 1000;
}
} else {
$spCriteriaValue = addslashes($criteria['value']);
}
@ -1156,7 +1180,7 @@ EOT;
} else if ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") {
$spCriteriaValue = "%$spCriteriaValue%";
} else if ($spCriteriaModifier == "is in the range") {
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria <= '$criteria[extra]'";
$spCriteriaValue = "$spCriteria >= '$spCriteriaValue' AND $spCriteria <= '$criteria[extra]'";
}
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
@ -1167,7 +1191,7 @@ EOT;
$qry->add($spCriteria, $spCriteriaValue, $spCriteriaModifier);
}
}catch (Exception $e){
Logging::log($e);
Logging::info($e);
}
$i++;
}
@ -1189,7 +1213,7 @@ EOT;
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
return array("files"=>$out, "limit"=>$limits, "count"=>$out->count());
}catch(Exception $e){
Logging::log($e);
Logging::info($e);
}
}

View file

@ -152,17 +152,21 @@ class Application_Model_Datatables
// we need to go over all items and fix length for playlist
// in case the playlist contains dynamic block
foreach ($results as &$r) {
if ($r['ftype'] == 'playlist') {
$pl = new Application_Model_Playlist($r['id']);
$r['length'] = $pl->getLength();
} else if ($r['ftype'] == "block") {
$bl = new Application_Model_Block($r['id']);
if ($bl->isStatic()) {
$r['bl_type'] = 'static';
} else {
$r['bl_type'] = 'dynamic';
//this function is also called for Manage Users so in
//this case there will be no 'ftype'
if (isset($r['ftype'])) {
if ($r['ftype'] == 'playlist') {
$pl = new Application_Model_Playlist($r['id']);
$r['length'] = $pl->getLength();
} else if ($r['ftype'] == "block") {
$bl = new Application_Model_Block($r['id']);
if ($bl->isStatic()) {
$r['bl_type'] = 'static';
} else {
$r['bl_type'] = 'dynamic';
}
$r['length'] = $bl->getLength();
}
$r['length'] = $bl->getLength();
}
}
} catch (Exception $e) {

View file

@ -0,0 +1,36 @@
<?php
class Application_Model_Library
{
public static function getObjInfo($p_type)
{
$info = array();
if (strcmp($p_type, 'playlist')==0) {
$info['className'] = 'Application_Model_Playlist';
} else if (strcmp($p_type, 'block')==0) {
$info['className'] = 'Application_Model_Block';
} else if (strcmp($p_type, 'stream')==0) {
$info['className'] = 'Application_Model_Webstream';
} else {
throw new Exception("Unknown object type: '$p_type'");
}
return $info;
}
public static function changePlaylist($p_id, $p_type)
{
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
if (is_null($p_id) || is_null($p_type)) {
unset($obj_sess->id);
unset($obj_sess->type);
} else {
$obj_sess->id = intval($p_id);
$obj_sess->type = $p_type;
}
}
}

View file

@ -0,0 +1,10 @@
<?php
interface Application_Model_LibraryEditable
{
public function setMetadata($key, $val);
public function setName($name);
public function getLength();
public function getId();
}

View file

@ -96,7 +96,7 @@ class Application_Model_LiveLog
return $minutes;
} catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable');
Logging::log("GetLiveShowDuration - Could not connect to database.");
Logging::info("GetLiveShowDuration - Could not connect to database.");
exit;
}
}
@ -254,7 +254,7 @@ class Application_Model_LiveLog
return $minutes;
} catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable');
Logging::log("GetScheduledDuration - Could not connect to database.");
Logging::info("GetScheduledDuration - Could not connect to database.");
exit;
}
}
@ -301,7 +301,7 @@ class Application_Model_LiveLog
} catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable');
Logging::log("SetNewLogTime - Could not connect to database.");
Logging::info("SetNewLogTime - Could not connect to database.");
exit;
}
}
@ -338,7 +338,7 @@ class Application_Model_LiveLog
} catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable');
Logging::log("SetEndTime - Could not connect to database.");
Logging::info("SetEndTime - Could not connect to database.");
exit;
}
}

View file

@ -8,7 +8,7 @@ require_once 'formatters/LengthFormatter.php';
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
*/
class Application_Model_Playlist
class Application_Model_Playlist implements Application_Model_LibraryEditable
{
/**
* propel connection object.
@ -135,8 +135,8 @@ class Application_Model_Playlist
public function getLastModified($format = null)
{
//Logging::log($this->pl->getDbMtime($format));
//Logging::log($this->pl);
//Logging::info($this->pl->getDbMtime($format));
//Logging::info($this->pl);
return $this->pl->getDbMtime($format);
}
@ -153,7 +153,7 @@ class Application_Model_Playlist
*/
public function getContents($filterFiles=false)
{
Logging::log("Getting contents for playlist {$this->id}");
Logging::info("Getting contents for playlist {$this->id}");
$files = array();
$sql = <<<SQL
@ -171,7 +171,8 @@ class Application_Model_Playlist
f.track_title,
f.artist_name AS creator,
f.file_exists AS EXISTS,
f.filepath AS path
f.filepath AS path,
f.length AS orig_length
FROM cc_playlistcontents AS pc
JOIN cc_files AS f ON pc.file_id=f.id
WHERE pc.playlist_id = {$this->id}
@ -188,7 +189,8 @@ class Application_Model_Playlist
(ws.name || ': ' || ws.url) AS title,
sub.login AS creator,
't'::boolean AS EXISTS,
ws.url AS path
ws.url AS path,
ws.length AS orig_length
FROM cc_playlistcontents AS pc
JOIN cc_webstream AS ws ON pc.stream_id=ws.id
LEFT JOIN cc_subjs AS sub ON sub.id = ws.creator_id
@ -206,7 +208,8 @@ class Application_Model_Playlist
bl.name AS title,
sbj.login AS creator,
't'::boolean AS EXISTS,
NULL::text AS path
NULL::text AS path,
bl.length AS orig_length
FROM cc_playlistcontents AS pc
JOIN cc_block AS bl ON pc.block_id=bl.id
JOIN cc_subjs AS sbj ON bl.creator_id=sbj.id
@ -240,6 +243,10 @@ SQL;
$fades = $this->getFadeInfo($row['position']);
$row['fadein'] = $fades[0];
$row['fadeout'] = $fades[1];
//format original length
$formatter = new LengthFormatter($row['orig_length']);
$row['orig_length'] = $formatter->format();
}
return $rows;
@ -270,8 +277,8 @@ SQL;
}
// returns true/false and ids of dynamic blocks
public function hasDynamicBlock(){
$ids = $this->getIdsOfDynamicBlocks();
public function hasDynamicBlock(){
$ids = $this->getIdsOfDynamicBlocks();
if (count($ids) > 0) {
return true;
} else {
@ -280,10 +287,10 @@ SQL;
}
public function getIdsOfDynamicBlocks() {
$sql = "SELECT bl.id FROM cc_playlistcontents as pc
JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic'
WHERE playlist_id={$this->id} AND pc.type=2";
$r = $this->con->query($sql);
$sql = "SELECT bl.id FROM cc_playlistcontents as pc
JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic'
WHERE playlist_id={$this->id} AND pc.type=2";
$r = $this->con->query($sql);
$result = $r->fetchAll(PDO::FETCH_ASSOC);
return $result;
}
@ -384,11 +391,11 @@ SQL;
try {
if (is_numeric($p_afterItem)) {
Logging::log("Finding playlist content item {$p_afterItem}");
Logging::info("Finding playlist content item {$p_afterItem}");
$afterItem = CcPlaylistcontentsQuery::create()->findPK($p_afterItem);
$index = $afterItem->getDbPosition();
Logging::log("index is {$index}");
Logging::info("index is {$index}");
$pos = ($addType == 'after') ? $index + 1 : $index;
$contentsToUpdate = CcPlaylistcontentsQuery::create()
@ -421,13 +428,13 @@ SQL;
}
Logging::log("Adding to playlist");
Logging::log("at position {$pos}");
Logging::info("Adding to playlist");
Logging::info("at position {$pos}");
foreach ($p_items as $ac) {
$res = $this->insertPlaylistElement($this->buildEntry($ac, $pos));
$res = $this->insertPlaylistElement($this->buildEntry($ac, $pos));
$pos = $pos + 1;
Logging::log("Adding $ac[1] $ac[0]");
Logging::info("Adding $ac[1] $ac[0]");
}
@ -476,32 +483,32 @@ SQL;
$pos = 0;
//moving items to beginning of the playlist.
if (is_null($p_afterItem)) {
Logging::log("moving items to beginning of playlist");
Logging::info("moving items to beginning of playlist");
foreach ($contentsToMove as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
Logging::info("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
}
foreach ($otherContent as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
Logging::info("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
}
} else {
Logging::log("moving items after {$p_afterItem}");
Logging::info("moving items after {$p_afterItem}");
foreach ($otherContent as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
Logging::info("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
if ($item->getDbId() == $p_afterItem) {
foreach ($contentsToMove as $move) {
Logging::log("item {$move->getDbId()} to pos {$pos}");
Logging::info("item {$move->getDbId()} to pos {$pos}");
$move->setDbPosition($pos);
$move->save($this->con);
$pos = $pos + 1;
@ -561,7 +568,7 @@ SQL;
public function getFadeInfo($pos)
{
Logging::log("Getting fade info for pos {$pos}");
Logging::info("Getting fade info for pos {$pos}");
$row = CcPlaylistcontentsQuery::create()
->joinWith(CcFilesPeer::OM_CLASS)
@ -647,7 +654,7 @@ SQL;
public function setfades($fadein, $fadeout)
{
if (isset($fadein)) {
Logging::log("Setting playlist fade in {$fadein}");
Logging::info("Setting playlist fade in {$fadein}");
$row = CcPlaylistcontentsQuery::create()
->filterByDbPlaylistId($this->id)
->filterByDbPosition(0)
@ -657,7 +664,7 @@ SQL;
}
if (isset($fadeout)) {
Logging::log("Setting playlist fade out {$fadeout}");
Logging::info("Setting playlist fade out {$fadeout}");
$row = CcPlaylistcontentsQuery::create()
->filterByDbPlaylistId($this->id)
->filterByDbPosition($this->getSize()-1)
@ -835,7 +842,7 @@ SQL;
return $this->$method();
}
public function setMetaData($category, $value)
public function setMetadata($category, $value)
{
$cat = $this->categories[$category];
@ -867,11 +874,19 @@ SQL;
*/
public static function deletePlaylists($p_ids, $p_userId)
{
$leftOver = self::playlistsNotOwnedByUser($p_ids, $p_userId);
if (count($leftOver) == 0) {
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id);
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
if (!$isAdminOrPM) {
$leftOver = self::playlistsNotOwnedByUser($p_ids, $p_userId);
if (count($leftOver) == 0) {
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
} else {
throw new PlaylistNoPermissionException;
}
} else {
throw new PlaylistNoPermissionException;
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
}
}
@ -890,13 +905,13 @@ SQL;
return $leftOvers;
}
/**
* Delete all files from playlist
* @param int $p_playlistId
*/
public function deleteAllFilesFromPlaylist()
/**
* Delete all files from playlist
* @param int $p_playlistId
*/
public function deleteAllFilesFromPlaylist()
{
CcPlaylistcontentsQuery::create()->findByDbPlaylistId($this->id)->delete();
CcPlaylistcontentsQuery::create()->findByDbPlaylistId($this->id)->delete();
}
} // class Playlist

View file

@ -66,7 +66,7 @@ class Application_Model_Preference
} catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable');
Logging::log("Could not connect to database: ".$e->getMessage());
Logging::info("Could not connect to database: ".$e->getMessage());
exit;
}
@ -107,7 +107,7 @@ class Application_Model_Preference
}
} catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable');
Logging::log("Could not connect to database: ".$e->getMessage());
Logging::info("Could not connect to database: ".$e->getMessage());
exit;
}
}

View file

@ -32,7 +32,7 @@ class Application_Model_Schedule
{
if (!is_int($p_prev) || !is_int($p_next)) {
//must enter integers to specify ranges
Logging::log("Invalid range parameters: $p_prev or $p_next");
Logging::info("Invalid range parameters: $p_prev or $p_next");
return array();
}
@ -1065,10 +1065,11 @@ SQL;
if ($update) {
$sql = "SELECT id, starts, ends FROM ".$CC_CONFIG["showInstances"]."
where ends <= '{$show_end->format('Y-m-d H:i:s')}'
and id != ".$instanceId. " order by ends";
and modified_instance = false and id != ".$instanceId. " order by ends";
} else {
$sql = "SELECT id, starts, ends FROM ".$CC_CONFIG["showInstances"]."
where ends <= '{$show_end->format('Y-m-d H:i:s')}' order by ends";
where ends <= '{$show_end->format('Y-m-d H:i:s')}'
and modified_instance = false order by ends";
}
$rows = $con->query($sql);

View file

@ -110,7 +110,7 @@ class Application_Model_Scheduler
$ts = intval($instanceInfo[$id]);
$lastSchedTs = intval($instance->getDbLastScheduled("U")) ? : 0;
if ($ts < $lastSchedTs) {
Logging::log("ts {$ts} last sched {$lastSchedTs}");
Logging::info("ts {$ts} last sched {$lastSchedTs}");
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
}
}
@ -317,7 +317,7 @@ class Application_Model_Scheduler
*/
private function removeGaps($showInstance, $exclude=null)
{
Logging::log("removing gaps from show instance #".$showInstance);
Logging::info("removing gaps from show instance #".$showInstance);
$instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con);
if (is_null($instance)) {
@ -416,7 +416,7 @@ class Application_Model_Scheduler
} else {
$sched = new CcSchedule();
}
Logging::log($file);
Logging::info($file);
$sched->setDbStarts($nextStartDT)
->setDbEnds($endTimeDT)
->setDbCueIn($file['cuein'])

View file

@ -216,8 +216,8 @@ class Application_Model_Show
$con->commit();
} catch (Exception $e) {
$con->rollback();
Logging::log("Couldn't update schedule status.");
Logging::log($e->getMessage());
Logging::info("Couldn't update schedule status.");
Logging::info($e->getMessage());
}
Application_Model_RabbitMq::PushSchedule();
@ -277,27 +277,27 @@ class Application_Model_Show
->filterByDbShowId($this->getId())
->find();
Logging::log("Unchecked days:");
Logging::info("Unchecked days:");
foreach ($p_uncheckedDays as $day) {
Logging::log($day);
Logging::info($day);
}
foreach ($showDays as $showDay) {
//Logging::log("Local show day is: {$showDay->getDbDay()}");
//Logging::log("First show day is: {$showDay->getDbFirstShow()}");
//Logging::log("Id show days is: {$showDay->getDbId()}");
//Logging::info("Local show day is: {$showDay->getDbDay()}");
//Logging::info("First show day is: {$showDay->getDbFirstShow()}");
//Logging::info("Id show days is: {$showDay->getDbId()}");
if (in_array($showDay->getDbDay(), $p_uncheckedDays)) {
$showDay->reload();
//Logging::log("Local show day is: {$showDay->getDbDay()}");
//Logging::log("First show day is: {$showDay->getDbFirstShow()}");
//Logging::log("Id show days is: {$showDay->getDbId()}");
//Logging::info("Local show day is: {$showDay->getDbDay()}");
//Logging::info("First show day is: {$showDay->getDbFirstShow()}");
//Logging::info("Id show days is: {$showDay->getDbId()}");
$startDay = new DateTime("{$showDay->getDbFirstShow()} {$showDay->getDbStartTime()}", new DateTimeZone($showDay->getDbTimezone()));
//Logging::log("Show start day: {$startDay->format('Y-m-d H:i:s')}");
//Logging::info("Show start day: {$startDay->format('Y-m-d H:i:s')}");
$startDay->setTimezone(new DateTimeZone("UTC"));
//Logging::log("Show start day UTC: {$startDay->format('Y-m-d H:i:s')}");
//Logging::info("Show start day UTC: {$startDay->format('Y-m-d H:i:s')}");
$daysRemovedUTC[] = $startDay->format('w');
//Logging::log("UTC show day is: {$startDay->format('w')}");
//Logging::info("UTC show day is: {$startDay->format('w')}");
}
}
@ -368,7 +368,7 @@ class Application_Model_Show
."WHERE instance_id = (SELECT id FROM cc_show_instances WHERE show_id = $showId ORDER BY starts LIMIT 1) AND rebroadcast = 1 "
."ORDER BY starts";
//Logging::log($sql);
//Logging::info($sql);
$rebroadcasts = $con->query($sql)->fetchAll();
@ -1160,8 +1160,8 @@ class Application_Model_Show
$con->commit();
} catch (Exception $e) {
$con->rollback();
Logging::log("Couldn't update schedule status.");
Logging::log($e->getMessage());
Logging::info("Couldn't update schedule status.");
Logging::info($e->getMessage());
}
}
@ -1549,7 +1549,7 @@ class Application_Model_Show
$sql = $sql." AND ({$exclude})";
}
$result = $con->query($sql);
$result = $con->query($sql)->fetchAll();
return $result;
}
@ -1590,7 +1590,7 @@ class Application_Model_Show
WHERE last_show IS NULL
OR first_show < '{$endTimeString}' AND last_show > '{$startTimeString}'";
//Logging::log($sql);
//Logging::info($sql);
$res = $con->query($sql)->fetchAll();
foreach ($res as $row) {
Application_Model_Show::populateShow($row, $p_endTimestamp);
@ -1723,7 +1723,7 @@ class Application_Model_Show
$showDay->setDbFirstShow($dt)->setDbStartTime($dt)
->save();
//Logging::log("setting show's first show.");
//Logging::info("setting show's first show.");
}
/* Takes in a UTC DateTime object

View file

@ -571,9 +571,9 @@ class Application_Model_ShowInstance
$rebroad = new Application_Model_ShowInstance($rebroadcast->getDbId());
$rebroad->addFileToShow($file_id, false);
} catch (Exception $e) {
Logging::log("{$e->getFile()}");
Logging::log("{$e->getLine()}");
Logging::log("{$e->getMessage()}");
Logging::info("{$e->getFile()}");
Logging::info("{$e->getLine()}");
Logging::info("{$e->getMessage()}");
}
}
}

View file

@ -96,7 +96,7 @@ class Application_Model_StoredFile
*/
public function setMetadata($p_md=null)
{
Logging::log("entered setMetadata");
Logging::info("entered setMetadata");
if (is_null($p_md)) {
$this->setDbColMetadata();
} else {
@ -153,7 +153,7 @@ class Application_Model_StoredFile
if (isset($this->_dbMD[$dbColumn])) {
$propelColumn = $this->_dbMD[$dbColumn];
$method = "set$propelColumn";
Logging::log($method);
Logging::info($method);
$this->_file->$method($mdValue);
}
}
@ -446,7 +446,7 @@ class Application_Model_StoredFile
*/
public function getRelativeFileUrl($baseUrl)
{
Logging::log("getting media!");
Logging::info("getting media!");
return $baseUrl."/api/get-media/file/".$this->getId().".".$this->getFileExtension();
}
@ -760,7 +760,7 @@ class Application_Model_StoredFile
$chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
$chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
Logging::log(__FILE__.":uploadFile(): filename=$fileName to $p_targetDir");
Logging::info(__FILE__.":uploadFile(): filename=$fileName to $p_targetDir");
// Clean the fileName for security reasons
//this needs fixing for songs not in ascii.
//$fileName = preg_replace('/[^\w\._]+/', '', $fileName);
@ -852,59 +852,56 @@ class Application_Model_StoredFile
public static function copyFileToStor($p_targetDir, $fileName, $tempname)
{
$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname;
Logging::log('copyFileToStor: moving file '.$audio_file);
$md5 = md5_file($audio_file);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5, true);
Logging::info('copyFileToStor: moving file '.$audio_file);
$result = null;
if ($duplicate) {
if (file_exists($duplicate->getFilePath())) {
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
$result = array( "code" => 106, "message" => "An identical audioclip named '$duplicateName' already exists on the server.");
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
// check if "organize" dir exists and if not create one
if (!file_exists($stor."/organize")) {
if (!mkdir($stor."/organize", 0777)) {
return array(
"code" => 109,
"message" => "Failed to create 'organize' directory.");
}
}
if (!isset($result)) {//The file has no duplicate, so proceed to copy.
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
// check if "organize" dir exists and if not create one
if (!file_exists($stor."/organize")) {
if (!mkdir($stor."/organize", 0777)) {
$result = array("code" => 109, "message" => "Failed to create 'organize' directory.");
return $result;
}
}
if (chmod($audio_file, 0644) === false) {
Logging::log("Warning: couldn't change permissions of $audio_file to 0644");
}
//check to see if there is enough space in $stor to continue.
if (self::isEnoughDiskSpaceToCopy($stor, $audio_file)) {
$audio_stor = Application_Common_OsPath::join($stor, "organize", $fileName);
if (self::liquidsoapFilePlayabilityTest($audio_file)) {
Logging::log("copyFileToStor: moving file $audio_file to $audio_stor");
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
if (@rename($audio_file, $audio_stor) === false) {
#something went wrong likely there wasn't enough space in the audio_stor to move the file too.
#warn the user that the file wasn't uploaded and they should check if there is enough disk space.
unlink($audio_file);//remove the file after failed rename
$result = array("code" => 108, "message" => "The file was not uploaded, this error can occur if the computer hard drive does not have enough disk space or the stor directory does not have correct write permissions.");
}
} else {
$result = array("code" => 110, "message" => "This file appears to be corrupted and will not be added to media library.");
}
} else {
$result = array("code" => 107, "message" => "The file was not uploaded, there is ".$freeSpace."MB of disk space left and the file you are uploading has a size of ".$fileSize."MB.");
}
if (chmod($audio_file, 0644) === false) {
Logging::info("Warning: couldn't change permissions of $audio_file to 0644");
}
return $result;
// Check if we have enough space before copying
if(!self::isEnoughDiskSpaceToCopy($stor, $audio_file)) {
$freeSpace = disk_free_space($stor);
return array("code" => 107,
"message" => "The file was not uploaded, there is
".$freeSpace."MB of disk space left and the file you are
uploading has a size of ".$fileSize."MB.");
}
// Check if liquidsoap can play this file
if(!self::liquidsoapFilePlayabilityTest($audio_file)) {
return array(
"code" => 110,
"message" => "This file appears to be corrupted and will not
be added to media library.");
}
// Did all the checks for realz, now trying to copy
$audio_stor = Application_Common_OsPath::join($stor, "organize", $fileName);
Logging::info("copyFileToStor: moving file $audio_file to $audio_stor");
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
if (@rename($audio_file, $audio_stor) === false) {
#something went wrong likely there wasn't enough space in the audio_stor to move the file too.
#warn the user that the file wasn't uploaded and they should check if there is enough disk space.
unlink($audio_file);//remove the file after failed rename
return array(
"code" => 108,
"message" => "
The file was not uploaded, this error can occur if the computer
hard drive does not have enough disk space or the stor
directory does not have correct write permissions. ");
}
return null;
}
/*
@ -1004,7 +1001,7 @@ class Application_Model_StoredFile
return count($rows);
} catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable');
Logging::log("Could not connect to database.");
Logging::info("Could not connect to database.");
exit;
}

View file

@ -66,7 +66,7 @@ class Application_Model_StreamSetting
$ids[] = substr($row["keyname"], 0, strpos($row["keyname"], "_"));
}
//Logging::log(print_r($ids, true));
//Logging::info(print_r($ids, true));
return $ids;
}

View file

@ -224,7 +224,7 @@ class Application_Model_Systemstatus
$partitions[$totalSpace]->totalSpace = $totalSpace;
$partitions[$totalSpace]->totalFreeSpace = $totalSpace - $usedSpace;
Logging::log($partitions[$totalSpace]->totalFreeSpace);
Logging::info($partitions[$totalSpace]->totalFreeSpace);
} else {
/* First lets get all the watched directories. Then we can group them
* into the same partitions by comparing the partition sizes. */

View file

@ -32,9 +32,17 @@ class Application_Model_User
return $this->getType() == UTYPE_GUEST;
}
public function isHostOfShow($showId)
{
$userId = $this->_userInstance->getDbId();
return CcShowHostsQuery::create()
->filterByDbShow($showId)
->filterByDbHost($userId)->count() > 0;
}
public function isHost($showId)
{
return $this->isUserType(UTYPE_HOST, $showId);
return $this->isUserType(UTYPE_HOST);
}
public function isPM()
@ -61,7 +69,7 @@ class Application_Model_User
return $result;
}
public function isUserType($type, $showId='')
public function isUserType($type)
{
if (is_array($type)) {
$result = false;
@ -71,10 +79,7 @@ class Application_Model_User
$result = $this->_userInstance->getDbType() === 'A';
break;
case UTYPE_HOST:
$userId = $this->_userInstance->getDbId();
$result = CcShowHostsQuery::create()
->filterByDbShow($showId)
->filterByDbHost($userId)->count() > 0;
$result = $this->_userInstance->getDbType() === 'H';
break;
case UTYPE_PROGRAM_MANAGER:
$result = $this->_userInstance->getDbType() === 'P';
@ -89,9 +94,7 @@ class Application_Model_User
case UTYPE_ADMIN:
return $this->_userInstance->getDbType() === 'A';
case UTYPE_HOST:
$userId = $this->_userInstance->getDbId();
return CcShowHostsQuery::create()->filterByDbShow($showId)->filterByDbHost($userId)->count() > 0;
return $this->_userInstance->getDbId() === 'H';
case UTYPE_PROGRAM_MANAGER:
return $this->_userInstance->getDbType() === 'P';
}

View file

@ -1,12 +1,20 @@
<?php
class Application_Model_Webstream{
class Application_Model_Webstream implements Application_Model_LibraryEditable
{
private $id;
public function __construct($webstream)
{
//TODO: hacky...
if (is_int($webstream)) {
$this->webstream = CcWebstreamQuery::create()->findPK($webstream);
if (is_null($this->webstream)) {
throw new Exception();
}
} else {
$this->webstream = $webstream;
}
}
public function getOrm()
@ -41,6 +49,11 @@ class Application_Model_Webstream{
return "";
}
public function getLength()
{
return $this->getDefaultLength();
}
public function getDescription()
{
return $this->webstream->getDbDescription();
@ -145,15 +158,6 @@ class Application_Model_Webstream{
$id = $parameters["id"];
if (!is_null($id)) {
// user has performed a create stream action instead of edit
// stream action. Check if user has the rights to edit this stream.
Logging::log("CREATE");
} else {
Logging::log("EDIT");
}
return array($valid, $mime, $di);
}
@ -168,6 +172,18 @@ class Application_Model_Webstream{
return true;
}
public function setMetadata($key, $val)
{
}
public function setName($name)
{
}
private static function discoverStreamMime($url)
{
$headers = get_headers($url);