SAAS-1058: Podcast table schema
Changed podcast table column sizes Added some podcast table column size validation
This commit is contained in:
parent
a6450353e5
commit
1445e85795
5 changed files with 60 additions and 33 deletions
|
@ -39,32 +39,36 @@ class Podcast extends BasePodcast
|
|||
* @throws PodcastLimitReachedException
|
||||
*/
|
||||
|
||||
public static function create($podcastArray)
|
||||
public static function create($data)
|
||||
{
|
||||
if (Application_Service_PodcastService::podcastLimitReached()) {
|
||||
throw new PodcastLimitReachedException();
|
||||
}
|
||||
|
||||
$rss = Application_Service_PodcastService::getPodcastFeed($podcastArray["url"]);
|
||||
$rss = Application_Service_PodcastService::getPodcastFeed($data["url"]);
|
||||
if (!$rss) {
|
||||
throw new InvalidPodcastException();
|
||||
}
|
||||
|
||||
// Ensure we are only creating Podcast with the given URL, and excluding
|
||||
// any extra data fields that may have been POSTED
|
||||
$podcastArray = array();
|
||||
$podcastArray["url"] = $data["url"];
|
||||
|
||||
// Kind of a pain; since the rss fields are SimpleXMLElements,
|
||||
// we need to explicitly cast them to strings
|
||||
$podcastArray["title"] = (string)$rss->title;
|
||||
$podcastArray["creator"] = (string)$rss->author;
|
||||
$podcastArray["description"] = (string)$rss->description;
|
||||
self::validatePodcastMetadata($podcastArray);
|
||||
|
||||
try {
|
||||
// Kind of a pain; since the rss fields are SimpleXMLElements,
|
||||
// we need to explicitly cast them to strings
|
||||
$podcast = new Podcast();
|
||||
$podcast->setDbUrl($podcastArray["url"]);
|
||||
$podcast->setDbTitle((string)$rss->title);
|
||||
$podcast->setDbCreator((string)$rss->author);
|
||||
$podcast->setDbDescription((string)$rss->description);
|
||||
$podcast->fromArray($podcastArray, BasePeer::TYPE_FIELDNAME);
|
||||
$podcast->setDbOwner(self::getOwnerId());
|
||||
$podcast->setDbType(IMPORTED_PODCAST);
|
||||
$podcast->save();
|
||||
|
||||
// $podcastArray = array();
|
||||
// array_push($podcastArray, $podcast->toArray(BasePeer::TYPE_FIELDNAME));
|
||||
|
||||
$podcastArray = $podcast->toArray(BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
$podcastArray["episodes"] = array();
|
||||
|
@ -135,7 +139,8 @@ class Podcast extends BasePodcast
|
|||
throw new PodcastNotFoundException();
|
||||
}
|
||||
|
||||
$data = self::removePrivateFields($data);
|
||||
self::removePrivateFields($data);
|
||||
self::validatePodcastMetadata($data);
|
||||
|
||||
$podcast->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
$podcast->save();
|
||||
|
@ -160,13 +165,35 @@ class Podcast extends BasePodcast
|
|||
}
|
||||
}
|
||||
|
||||
private static function removePrivateFields($data)
|
||||
/**
|
||||
* Trims the podcast metadata to fit the table's column max size
|
||||
*
|
||||
* @param $podcastArray
|
||||
* @throws PropelException
|
||||
*/
|
||||
private static function validatePodcastMetadata(&$podcastArray)
|
||||
{
|
||||
$podcastTable = PodcastPeer::getTableMap();
|
||||
|
||||
foreach ($podcastArray as $key => &$value) {
|
||||
try {
|
||||
// Make sure column exists in table
|
||||
$columnMaxSize = $podcastTable->getColumn($key)->getSize();
|
||||
} catch (PropelException $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen($value) > $columnMaxSize) {
|
||||
$value = substr($value, 0, $podcastTable->getColumn($key)->getSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function removePrivateFields(&$data)
|
||||
{
|
||||
foreach (self::$privateFields as $key) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
//TODO move this somewhere where it makes sense
|
||||
|
|
|
@ -43,8 +43,8 @@ class PodcastEpisodesTableMap extends TableMap
|
|||
$this->addForeignKey('file_id', 'DbFileId', 'INTEGER', 'cc_files', 'id', true, null, null);
|
||||
$this->addForeignKey('podcast_id', 'DbPodcastId', 'INTEGER', 'podcast', 'id', true, null, null);
|
||||
$this->addColumn('publication_date', 'DbPublicationDate', 'TIMESTAMP', true, null, null);
|
||||
$this->addColumn('download_url', 'DbDownloadUrl', 'VARCHAR', true, 512, null);
|
||||
$this->addColumn('episode_guid', 'DbEpisodeGuid', 'VARCHAR', true, 512, null);
|
||||
$this->addColumn('download_url', 'DbDownloadUrl', 'VARCHAR', true, 4096, null);
|
||||
$this->addColumn('episode_guid', 'DbEpisodeGuid', 'VARCHAR', true, 4096, null);
|
||||
// validators
|
||||
} // initialize()
|
||||
|
||||
|
|
|
@ -40,10 +40,10 @@ class PodcastTableMap extends TableMap
|
|||
$this->setPrimaryKeyMethodInfo('podcast_id_seq');
|
||||
// columns
|
||||
$this->addPrimaryKey('id', 'DbId', 'INTEGER', true, null, null);
|
||||
$this->addColumn('url', 'DbUrl', 'VARCHAR', true, 256, null);
|
||||
$this->addColumn('title', 'DbTitle', 'VARCHAR', true, 256, null);
|
||||
$this->addColumn('creator', 'DbCreator', 'VARCHAR', false, 256, null);
|
||||
$this->addColumn('description', 'DbDescription', 'VARCHAR', false, 512, null);
|
||||
$this->addColumn('url', 'DbUrl', 'VARCHAR', true, 4096, null);
|
||||
$this->addColumn('title', 'DbTitle', 'VARCHAR', true, 4096, null);
|
||||
$this->addColumn('creator', 'DbCreator', 'VARCHAR', false, 4096, null);
|
||||
$this->addColumn('description', 'DbDescription', 'VARCHAR', false, 4096, null);
|
||||
$this->addColumn('auto_ingest', 'DbAutoIngest', 'BOOLEAN', true, null, false);
|
||||
$this->addForeignKey('owner', 'DbOwner', 'INTEGER', 'cc_subjs', 'id', false, null, null);
|
||||
$this->addColumn('type', 'DbType', 'INTEGER', true, null, 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue