CC-5316 : Playout History: Doesn't support webstream

adding the webstream metadata to the history table.
This commit is contained in:
Naomi 2013-09-30 13:56:27 -04:00
parent 9f38e5a9c6
commit 7d739a0f66
7 changed files with 87 additions and 19 deletions

View File

@ -1042,12 +1042,15 @@ class ApiController extends Zend_Controller_Action
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$data = $request->getParam("data"); $data = $request->getParam("data");
$media_id = $request->getParam("media_id"); $media_id = intval($request->getParam("media_id"));
$data_arr = json_decode($data); $data_arr = json_decode($data);
//$media_id is -1 sometimes when a stream has stopped playing
if (!is_null($media_id) && $media_id > 0) {
if (!is_null($media_id)) { if (isset($data_arr->title)) {
if (isset($data_arr->title) &&
strlen($data_arr->title) < 1024) { $data_title = substr($data_arr->title, 0, 1024);
$previous_metadata = CcWebstreamMetadataQuery::create() $previous_metadata = CcWebstreamMetadataQuery::create()
->orderByDbStartTime('desc') ->orderByDbStartTime('desc')
@ -1056,23 +1059,27 @@ class ApiController extends Zend_Controller_Action
$do_insert = true; $do_insert = true;
if ($previous_metadata) { if ($previous_metadata) {
if ($previous_metadata->getDbLiquidsoapData() == $data_arr->title) { if ($previous_metadata->getDbLiquidsoapData() == $data_title) {
Logging::debug("Duplicate found: ".$data_arr->title); Logging::debug("Duplicate found: ". $data_title);
$do_insert = false; $do_insert = false;
} }
} }
if ($do_insert) { if ($do_insert) {
$startDT = new DateTime("now", new DateTimeZone("UTC"));
$webstream_metadata = new CcWebstreamMetadata(); $webstream_metadata = new CcWebstreamMetadata();
$webstream_metadata->setDbInstanceId($media_id); $webstream_metadata->setDbInstanceId($media_id);
$webstream_metadata->setDbStartTime(new DateTime("now", new DateTimeZone("UTC"))); $webstream_metadata->setDbStartTime($startDT);
$webstream_metadata->setDbLiquidsoapData($data_arr->title); $webstream_metadata->setDbLiquidsoapData($data_title);
$webstream_metadata->save(); $webstream_metadata->save();
$historyService = new Application_Service_HistoryService();
$historyService->insertWebstreamMetadata($media_id, $startDT, $data_arr);
} }
} }
} else { }
throw new Exception("Null value of media_id");
}
$this->view->response = $data; $this->view->response = $data;
$this->view->media_id = $media_id; $this->view->media_id = $media_id;

View File

@ -43,7 +43,7 @@ class Application_Form_EditHistoryItem extends Application_Form_EditHistory
$ends->addFilter('StringTrim'); $ends->addFilter('StringTrim');
$ends->setLabel(_('End Time')); $ends->setLabel(_('End Time'));
$ends->setDecorators(array('ViewHelper')); $ends->setDecorators(array('ViewHelper'));
$ends->setRequired(true); //$ends->setRequired(true);
$this->addElement($ends); $this->addElement($ends);
} }

View File

@ -14,5 +14,21 @@
* @package propel.generator.airtime * @package propel.generator.airtime
*/ */
class CcPlayoutHistoryMetaData extends BaseCcPlayoutHistoryMetaData { class CcPlayoutHistoryMetaData extends BaseCcPlayoutHistoryMetaData {
/**
* Set the value of [value] column.
*
* @param string $v new value
* @return CcPlayoutHistoryMetaData The current object (for fluent API support)
*/
public function setDbValue($v)
{
//make sure the metadata isn't longer than the DB field.
$v = substr($v, 0, 128);
parent::setDbValue($v);
return $this;
} // setDbValue()
} // CcPlayoutHistoryMetaData } // CcPlayoutHistoryMetaData

View File

@ -41,7 +41,7 @@ class CcPlayoutHistoryTableMap extends TableMap {
$this->addPrimaryKey('ID', 'DbId', 'INTEGER', true, null, null); $this->addPrimaryKey('ID', 'DbId', 'INTEGER', true, null, null);
$this->addForeignKey('FILE_ID', 'DbFileId', 'INTEGER', 'cc_files', 'ID', false, null, null); $this->addForeignKey('FILE_ID', 'DbFileId', 'INTEGER', 'cc_files', 'ID', false, null, null);
$this->addColumn('STARTS', 'DbStarts', 'TIMESTAMP', true, null, null); $this->addColumn('STARTS', 'DbStarts', 'TIMESTAMP', true, null, null);
$this->addColumn('ENDS', 'DbEnds', 'TIMESTAMP', true, null, null); $this->addColumn('ENDS', 'DbEnds', 'TIMESTAMP', false, null, null);
$this->addForeignKey('INSTANCE_ID', 'DbInstanceId', 'INTEGER', 'cc_show_instances', 'ID', false, null, null); $this->addForeignKey('INSTANCE_ID', 'DbInstanceId', 'INTEGER', 'cc_show_instances', 'ID', false, null, null);
// validators // validators
} // initialize() } // initialize()

View File

@ -290,9 +290,12 @@ class Application_Service_HistoryService
$dateTime->setTimezone($timezoneLocal); $dateTime->setTimezone($timezoneLocal);
$result["starts"] = $dateTime->format("Y-m-d H:i:s"); $result["starts"] = $dateTime->format("Y-m-d H:i:s");
$dateTime = new DateTime($result["ends"], $timezoneUTC); //if ends is null we don't want it to default to "now"
$dateTime->setTimezone($timezoneLocal); if (isset($result["ends"])) {
$result["ends"] = $dateTime->format("Y-m-d H:i:s"); $dateTime = new DateTime($result["ends"], $timezoneUTC);
$dateTime->setTimezone($timezoneLocal);
$result["ends"] = $dateTime->format("Y-m-d H:i:s");
}
if (isset($result[MDATA_KEY_DURATION])) { if (isset($result[MDATA_KEY_DURATION])) {
$formatter = new LengthFormatter($result[MDATA_KEY_DURATION]); $formatter = new LengthFormatter($result[MDATA_KEY_DURATION]);
@ -505,6 +508,48 @@ class Application_Service_HistoryService
return $filteredShows; return $filteredShows;
} }
public function insertWebstreamMetadata($schedId, $startDT, $data) {
$this->con->beginTransaction();
try {
$item = CcScheduleQuery::create()->findPK($schedId, $this->con);
//TODO figure out how to combine these all into 1 query.
$showInstance = $item->getCcShowInstances($this->con);
$show = $showInstance->getCcShow($this->con);
$webstream = $item->getCcWebstream($this->con);
$metadata = array();
$metadata["showname"] = $show->getDbName();
$metadata[MDATA_KEY_TITLE] = $data->title;
$metadata[MDATA_KEY_CREATOR] = $webstream->getDbName();
$history = new CcPlayoutHistory();
$history->setDbStarts($startDT);
$history->setDbEnds(null);
$history->setDbInstanceId($item->getDbInstanceId());
foreach ($metadata as $key => $val) {
$meta = new CcPlayoutHistoryMetaData();
$meta->setDbKey($key);
$meta->setDbValue($val);
$history->addCcPlayoutHistoryMetaData($meta);
}
$history->save($this->con);
$this->con->commit();
}
catch (Exception $e) {
$this->con->rollback();
throw $e;
}
}
public function insertPlayedItem($schedId) { public function insertPlayedItem($schedId) {
@ -611,7 +656,7 @@ class Application_Service_HistoryService
} }
//need to convert to the station's local time first. //need to convert to the station's local time first.
if ($field["type"] == TEMPLATE_DATETIME) { if ($field["type"] == TEMPLATE_DATETIME && !is_null($value)) {
$timezoneUTC = new DateTimeZone("UTC"); $timezoneUTC = new DateTimeZone("UTC");
$timezoneLocal = new DateTimeZone($this->timezone); $timezoneLocal = new DateTimeZone($this->timezone);

View File

@ -483,7 +483,7 @@
<column name="id" phpName="DbId" primaryKey="true" type="INTEGER" autoIncrement="true" required="true" /> <column name="id" phpName="DbId" primaryKey="true" type="INTEGER" autoIncrement="true" required="true" />
<column name="file_id" phpName="DbFileId" type="INTEGER" required="false" /> <column name="file_id" phpName="DbFileId" type="INTEGER" required="false" />
<column name="starts" phpName="DbStarts" type="TIMESTAMP" required="true"/> <column name="starts" phpName="DbStarts" type="TIMESTAMP" required="true"/>
<column name="ends" phpName="DbEnds" type="TIMESTAMP" required="true"/> <column name="ends" phpName="DbEnds" type="TIMESTAMP" required="false"/>
<column name="instance_id" phpName="DbInstanceId" type="INTEGER" required="false"/> <column name="instance_id" phpName="DbInstanceId" type="INTEGER" required="false"/>
<foreign-key foreignTable="cc_files" name="cc_playout_history_file_tag_fkey" onDelete="CASCADE"> <foreign-key foreignTable="cc_files" name="cc_playout_history_file_tag_fkey" onDelete="CASCADE">
<reference local="file_id" foreign="id"/> <reference local="file_id" foreign="id"/>

View File

@ -765,7 +765,7 @@ CREATE TABLE "cc_playout_history"
"id" serial NOT NULL, "id" serial NOT NULL,
"file_id" INTEGER, "file_id" INTEGER,
"starts" TIMESTAMP NOT NULL, "starts" TIMESTAMP NOT NULL,
"ends" TIMESTAMP NOT NULL, "ends" TIMESTAMP,
"instance_id" INTEGER, "instance_id" INTEGER,
PRIMARY KEY ("id") PRIMARY KEY ("id")
); );