* SAAS-1084 - initial work on publishing API backend

* More work on automatic ingest
* Add automatic_ingest_timestamp column to ImportedPodcast
This commit is contained in:
Duncan Sommerville 2015-10-20 19:03:34 -04:00
parent 3a791ef9b5
commit 0b1df6baf3
27 changed files with 490 additions and 106 deletions

View file

@ -15,4 +15,26 @@
*/
class PodcastEpisodes extends BasePodcastEpisodes
{
/**
* @override
* We need to override this function in order to provide the rotating
* download key for the station podcast.
*
* Get the [download_url] column value.
*
* @return string
*/
public function getDbDownloadUrl() {
$podcastId = $this->getDbPodcastId();
// We may have more station podcasts later, so use this instead of checking the id stored in Preference
$podcast = StationPodcastQuery::create()->findOneByDbPodcastId($podcastId);
if ($podcast) {
$fileId = $this->getDbFileId();
$key = Application_Model_Preference::getStationPodcastDownloadKey();
return Application_Common_HTTPHelper::getStationUrl()."rest/media/$fileId/download?download_key=$key";
}
return parent::getDbDownloadUrl();
}
}

View file

@ -15,4 +15,24 @@
*/
class StationPodcast extends BaseStationPodcast
{
/**
* Utility function to check whether an episode for the file with the given ID
* is contained within the station podcast
*
* @param int $fileId the file ID to check for
*
* @return bool true if the station podcast contains an episode with
* the given file ID, otherwise false
*/
public function hasEpisodeForFile($fileId) {
$episodes = PodcastEpisodesQuery::create()
->filterByDbPodcastId($this->getDbPodcastId())
->find();
foreach ($episodes as $e) {
if ($e->getDbFileId() == $fileId) return true;
}
return false;
}
}

View file

@ -41,6 +41,7 @@ class ImportedPodcastTableMap extends TableMap
// columns
$this->addPrimaryKey('id', 'DbId', 'INTEGER', true, null, null);
$this->addColumn('auto_ingest', 'DbAutoIngest', 'BOOLEAN', true, null, false);
$this->addColumn('auto_ingest_timestamp', 'DbAutoIngestTimestamp', 'TIMESTAMP', false, null, null);
$this->addForeignKey('podcast_id', 'DbPodcastId', 'INTEGER', 'podcast', 'id', true, null, null);
// validators
} // initialize()

View file

@ -42,6 +42,12 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
*/
protected $auto_ingest;
/**
* The value for the auto_ingest_timestamp field.
* @var string
*/
protected $auto_ingest_timestamp;
/**
* The value for the podcast_id field.
* @var int
@ -116,6 +122,41 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
return $this->auto_ingest;
}
/**
* Get the [optionally formatted] temporal [auto_ingest_timestamp] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is null, then the raw DateTime object will be returned.
* @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null
* @throws PropelException - if unable to parse/validate the date/time value.
*/
public function getDbAutoIngestTimestamp($format = 'Y-m-d H:i:s')
{
if ($this->auto_ingest_timestamp === null) {
return null;
}
try {
$dt = new DateTime($this->auto_ingest_timestamp);
} catch (Exception $x) {
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->auto_ingest_timestamp, true), $x);
}
if ($format === null) {
// Because propel.useDateTimeClass is true, we return a DateTime object.
return $dt;
}
if (strpos($format, '%') !== false) {
return strftime($format, $dt->format('U'));
}
return $dt->format($format);
}
/**
* Get the [podcast_id] column value.
*
@ -177,6 +218,29 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
return $this;
} // setDbAutoIngest()
/**
* Sets the value of [auto_ingest_timestamp] column to a normalized version of the date/time value specified.
*
* @param mixed $v string, integer (timestamp), or DateTime value.
* Empty strings are treated as null.
* @return ImportedPodcast The current object (for fluent API support)
*/
public function setDbAutoIngestTimestamp($v)
{
$dt = PropelDateTime::newInstance($v, null, 'DateTime');
if ($this->auto_ingest_timestamp !== null || $dt !== null) {
$currentDateAsString = ($this->auto_ingest_timestamp !== null && $tmpDt = new DateTime($this->auto_ingest_timestamp)) ? $tmpDt->format('Y-m-d H:i:s') : null;
$newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
if ($currentDateAsString !== $newDateAsString) {
$this->auto_ingest_timestamp = $newDateAsString;
$this->modifiedColumns[] = ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP;
}
} // if either are not null
return $this;
} // setDbAutoIngestTimestamp()
/**
* Set the value of [podcast_id] column.
*
@ -240,7 +304,8 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
$this->auto_ingest = ($row[$startcol + 1] !== null) ? (boolean) $row[$startcol + 1] : null;
$this->podcast_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
$this->auto_ingest_timestamp = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
$this->podcast_id = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
$this->resetModified();
$this->setNew(false);
@ -250,7 +315,7 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
}
$this->postHydrate($row, $startcol, $rehydrate);
return $startcol + 3; // 3 = ImportedPodcastPeer::NUM_HYDRATE_COLUMNS.
return $startcol + 4; // 4 = ImportedPodcastPeer::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating ImportedPodcast object", $e);
@ -494,6 +559,9 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
if ($this->isColumnModified(ImportedPodcastPeer::AUTO_INGEST)) {
$modifiedColumns[':p' . $index++] = '"auto_ingest"';
}
if ($this->isColumnModified(ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP)) {
$modifiedColumns[':p' . $index++] = '"auto_ingest_timestamp"';
}
if ($this->isColumnModified(ImportedPodcastPeer::PODCAST_ID)) {
$modifiedColumns[':p' . $index++] = '"podcast_id"';
}
@ -514,6 +582,9 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
case '"auto_ingest"':
$stmt->bindValue($identifier, $this->auto_ingest, PDO::PARAM_BOOL);
break;
case '"auto_ingest_timestamp"':
$stmt->bindValue($identifier, $this->auto_ingest_timestamp, PDO::PARAM_STR);
break;
case '"podcast_id"':
$stmt->bindValue($identifier, $this->podcast_id, PDO::PARAM_INT);
break;
@ -663,6 +734,9 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
return $this->getDbAutoIngest();
break;
case 2:
return $this->getDbAutoIngestTimestamp();
break;
case 3:
return $this->getDbPodcastId();
break;
default:
@ -696,7 +770,8 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
$result = array(
$keys[0] => $this->getDbId(),
$keys[1] => $this->getDbAutoIngest(),
$keys[2] => $this->getDbPodcastId(),
$keys[2] => $this->getDbAutoIngestTimestamp(),
$keys[3] => $this->getDbPodcastId(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
@ -748,6 +823,9 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
$this->setDbAutoIngest($value);
break;
case 2:
$this->setDbAutoIngestTimestamp($value);
break;
case 3:
$this->setDbPodcastId($value);
break;
} // switch()
@ -776,7 +854,8 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
if (array_key_exists($keys[0], $arr)) $this->setDbId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setDbAutoIngest($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setDbPodcastId($arr[$keys[2]]);
if (array_key_exists($keys[2], $arr)) $this->setDbAutoIngestTimestamp($arr[$keys[2]]);
if (array_key_exists($keys[3], $arr)) $this->setDbPodcastId($arr[$keys[3]]);
}
/**
@ -790,6 +869,7 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
if ($this->isColumnModified(ImportedPodcastPeer::ID)) $criteria->add(ImportedPodcastPeer::ID, $this->id);
if ($this->isColumnModified(ImportedPodcastPeer::AUTO_INGEST)) $criteria->add(ImportedPodcastPeer::AUTO_INGEST, $this->auto_ingest);
if ($this->isColumnModified(ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP)) $criteria->add(ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP, $this->auto_ingest_timestamp);
if ($this->isColumnModified(ImportedPodcastPeer::PODCAST_ID)) $criteria->add(ImportedPodcastPeer::PODCAST_ID, $this->podcast_id);
return $criteria;
@ -855,6 +935,7 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
{
$copyObj->setDbAutoIngest($this->getDbAutoIngest());
$copyObj->setDbAutoIngestTimestamp($this->getDbAutoIngestTimestamp());
$copyObj->setDbPodcastId($this->getDbPodcastId());
if ($deepCopy && !$this->startCopy) {
@ -973,6 +1054,7 @@ abstract class BaseImportedPodcast extends BaseObject implements Persistent
{
$this->id = null;
$this->auto_ingest = null;
$this->auto_ingest_timestamp = null;
$this->podcast_id = null;
$this->alreadyInSave = false;
$this->alreadyInValidation = false;

View file

@ -24,13 +24,13 @@ abstract class BaseImportedPodcastPeer
const TM_CLASS = 'ImportedPodcastTableMap';
/** The total number of columns. */
const NUM_COLUMNS = 3;
const NUM_COLUMNS = 4;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
/** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
const NUM_HYDRATE_COLUMNS = 3;
const NUM_HYDRATE_COLUMNS = 4;
/** the column name for the id field */
const ID = 'imported_podcast.id';
@ -38,6 +38,9 @@ abstract class BaseImportedPodcastPeer
/** the column name for the auto_ingest field */
const AUTO_INGEST = 'imported_podcast.auto_ingest';
/** the column name for the auto_ingest_timestamp field */
const AUTO_INGEST_TIMESTAMP = 'imported_podcast.auto_ingest_timestamp';
/** the column name for the podcast_id field */
const PODCAST_ID = 'imported_podcast.podcast_id';
@ -60,12 +63,12 @@ abstract class BaseImportedPodcastPeer
* e.g. ImportedPodcastPeer::$fieldNames[ImportedPodcastPeer::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('DbId', 'DbAutoIngest', 'DbPodcastId', ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbAutoIngest', 'dbPodcastId', ),
BasePeer::TYPE_COLNAME => array (ImportedPodcastPeer::ID, ImportedPodcastPeer::AUTO_INGEST, ImportedPodcastPeer::PODCAST_ID, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID', 'AUTO_INGEST', 'PODCAST_ID', ),
BasePeer::TYPE_FIELDNAME => array ('id', 'auto_ingest', 'podcast_id', ),
BasePeer::TYPE_NUM => array (0, 1, 2, )
BasePeer::TYPE_PHPNAME => array ('DbId', 'DbAutoIngest', 'DbAutoIngestTimestamp', 'DbPodcastId', ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbAutoIngest', 'dbAutoIngestTimestamp', 'dbPodcastId', ),
BasePeer::TYPE_COLNAME => array (ImportedPodcastPeer::ID, ImportedPodcastPeer::AUTO_INGEST, ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP, ImportedPodcastPeer::PODCAST_ID, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID', 'AUTO_INGEST', 'AUTO_INGEST_TIMESTAMP', 'PODCAST_ID', ),
BasePeer::TYPE_FIELDNAME => array ('id', 'auto_ingest', 'auto_ingest_timestamp', 'podcast_id', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
);
/**
@ -75,12 +78,12 @@ abstract class BaseImportedPodcastPeer
* e.g. ImportedPodcastPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbAutoIngest' => 1, 'DbPodcastId' => 2, ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbAutoIngest' => 1, 'dbPodcastId' => 2, ),
BasePeer::TYPE_COLNAME => array (ImportedPodcastPeer::ID => 0, ImportedPodcastPeer::AUTO_INGEST => 1, ImportedPodcastPeer::PODCAST_ID => 2, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'AUTO_INGEST' => 1, 'PODCAST_ID' => 2, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'auto_ingest' => 1, 'podcast_id' => 2, ),
BasePeer::TYPE_NUM => array (0, 1, 2, )
BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbAutoIngest' => 1, 'DbAutoIngestTimestamp' => 2, 'DbPodcastId' => 3, ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbAutoIngest' => 1, 'dbAutoIngestTimestamp' => 2, 'dbPodcastId' => 3, ),
BasePeer::TYPE_COLNAME => array (ImportedPodcastPeer::ID => 0, ImportedPodcastPeer::AUTO_INGEST => 1, ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP => 2, ImportedPodcastPeer::PODCAST_ID => 3, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'AUTO_INGEST' => 1, 'AUTO_INGEST_TIMESTAMP' => 2, 'PODCAST_ID' => 3, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'auto_ingest' => 1, 'auto_ingest_timestamp' => 2, 'podcast_id' => 3, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
);
/**
@ -156,10 +159,12 @@ abstract class BaseImportedPodcastPeer
if (null === $alias) {
$criteria->addSelectColumn(ImportedPodcastPeer::ID);
$criteria->addSelectColumn(ImportedPodcastPeer::AUTO_INGEST);
$criteria->addSelectColumn(ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP);
$criteria->addSelectColumn(ImportedPodcastPeer::PODCAST_ID);
} else {
$criteria->addSelectColumn($alias . '.id');
$criteria->addSelectColumn($alias . '.auto_ingest');
$criteria->addSelectColumn($alias . '.auto_ingest_timestamp');
$criteria->addSelectColumn($alias . '.podcast_id');
}
}

View file

@ -8,10 +8,12 @@
*
* @method ImportedPodcastQuery orderByDbId($order = Criteria::ASC) Order by the id column
* @method ImportedPodcastQuery orderByDbAutoIngest($order = Criteria::ASC) Order by the auto_ingest column
* @method ImportedPodcastQuery orderByDbAutoIngestTimestamp($order = Criteria::ASC) Order by the auto_ingest_timestamp column
* @method ImportedPodcastQuery orderByDbPodcastId($order = Criteria::ASC) Order by the podcast_id column
*
* @method ImportedPodcastQuery groupByDbId() Group by the id column
* @method ImportedPodcastQuery groupByDbAutoIngest() Group by the auto_ingest column
* @method ImportedPodcastQuery groupByDbAutoIngestTimestamp() Group by the auto_ingest_timestamp column
* @method ImportedPodcastQuery groupByDbPodcastId() Group by the podcast_id column
*
* @method ImportedPodcastQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
@ -26,10 +28,12 @@
* @method ImportedPodcast findOneOrCreate(PropelPDO $con = null) Return the first ImportedPodcast matching the query, or a new ImportedPodcast object populated from the query conditions when no match is found
*
* @method ImportedPodcast findOneByDbAutoIngest(boolean $auto_ingest) Return the first ImportedPodcast filtered by the auto_ingest column
* @method ImportedPodcast findOneByDbAutoIngestTimestamp(string $auto_ingest_timestamp) Return the first ImportedPodcast filtered by the auto_ingest_timestamp column
* @method ImportedPodcast findOneByDbPodcastId(int $podcast_id) Return the first ImportedPodcast filtered by the podcast_id column
*
* @method array findByDbId(int $id) Return ImportedPodcast objects filtered by the id column
* @method array findByDbAutoIngest(boolean $auto_ingest) Return ImportedPodcast objects filtered by the auto_ingest column
* @method array findByDbAutoIngestTimestamp(string $auto_ingest_timestamp) Return ImportedPodcast objects filtered by the auto_ingest_timestamp column
* @method array findByDbPodcastId(int $podcast_id) Return ImportedPodcast objects filtered by the podcast_id column
*
* @package propel.generator.airtime.om
@ -138,7 +142,7 @@ abstract class BaseImportedPodcastQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT "id", "auto_ingest", "podcast_id" FROM "imported_podcast" WHERE "id" = :p0';
$sql = 'SELECT "id", "auto_ingest", "auto_ingest_timestamp", "podcast_id" FROM "imported_podcast" WHERE "id" = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@ -296,6 +300,49 @@ abstract class BaseImportedPodcastQuery extends ModelCriteria
return $this->addUsingAlias(ImportedPodcastPeer::AUTO_INGEST, $dbAutoIngest, $comparison);
}
/**
* Filter the query on the auto_ingest_timestamp column
*
* Example usage:
* <code>
* $query->filterByDbAutoIngestTimestamp('2011-03-14'); // WHERE auto_ingest_timestamp = '2011-03-14'
* $query->filterByDbAutoIngestTimestamp('now'); // WHERE auto_ingest_timestamp = '2011-03-14'
* $query->filterByDbAutoIngestTimestamp(array('max' => 'yesterday')); // WHERE auto_ingest_timestamp < '2011-03-13'
* </code>
*
* @param mixed $dbAutoIngestTimestamp The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ImportedPodcastQuery The current query, for fluid interface
*/
public function filterByDbAutoIngestTimestamp($dbAutoIngestTimestamp = null, $comparison = null)
{
if (is_array($dbAutoIngestTimestamp)) {
$useMinMax = false;
if (isset($dbAutoIngestTimestamp['min'])) {
$this->addUsingAlias(ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP, $dbAutoIngestTimestamp['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($dbAutoIngestTimestamp['max'])) {
$this->addUsingAlias(ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP, $dbAutoIngestTimestamp['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportedPodcastPeer::AUTO_INGEST_TIMESTAMP, $dbAutoIngestTimestamp, $comparison);
}
/**
* Filter the query on the podcast_id column
*