SAAS-1058: Podcast table schema

Changed podcast table column sizes
Added some podcast table column size validation
This commit is contained in:
drigato 2015-09-20 12:06:51 -04:00
parent a6450353e5
commit 1445e85795
5 changed files with 60 additions and 33 deletions

View File

@ -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

View File

@ -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()

View File

@ -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);

View File

@ -565,10 +565,10 @@
<table name="podcast" phpName="Podcast">
<column name="id" phpName="DbId" primaryKey="true" type="INTEGER" autoIncrement="true" required="true" />
<column name="url" phpName="DbUrl" type="VARCHAR" size="256" required="true" />
<column name="title" phpName="DbTitle" type="VARCHAR" size="256" required="true" />
<column name="creator" phpName="DbCreator" type="VARCHAR" size="256" />
<column name="description" phpName="DbDescription" type="VARCHAR" size="512" />
<column name="url" phpName="DbUrl" type="VARCHAR" size="4096" required="true" />
<column name="title" phpName="DbTitle" type="VARCHAR" size="4096" required="true" />
<column name="creator" phpName="DbCreator" type="VARCHAR" size="4096" />
<column name="description" phpName="DbDescription" type="VARCHAR" size="4096" />
<column name="auto_ingest" phpName="DbAutoIngest" type="BOOLEAN" required="true" defaultValue="false"/>
<column name="owner" phpName="DbOwner" type="INTEGER" />
<column name="type" phpName="DbType" type="INTEGER" required="true" defaultValue="1"/>
@ -582,8 +582,8 @@
<column name="file_id" phpName="DbFileId" type="INTEGER" required="true" />
<column name="podcast_id" phpName="DbPodcastId" type="INTEGER" required="true" />
<column name="publication_date" phpName="DbPublicationDate" type="TIMESTAMP" required="true" />
<column name="download_url" phpName="DbDownloadUrl" type="varchar" size="512" required="true" />
<column name="episode_guid" phpName="DbEpisodeGuid" type="varchar" size="512" required="true" />
<column name="download_url" phpName="DbDownloadUrl" type="varchar" size="4096" required="true" />
<column name="episode_guid" phpName="DbEpisodeGuid" type="varchar" size="4096" required="true" />
<foreign-key foreignTable="cc_files" name="podcast_episodes_cc_files_fkey" onDelete="CASCADE">
<reference local="file_id" foreign="id" />
</foreign-key>

View File

@ -716,10 +716,10 @@ DROP TABLE IF EXISTS "podcast" CASCADE;
CREATE TABLE "podcast"
(
"id" serial NOT NULL,
"url" VARCHAR(256) NOT NULL,
"title" VARCHAR(256) NOT NULL,
"creator" VARCHAR(256),
"description" VARCHAR(512),
"url" VARCHAR(4096) NOT NULL,
"title" VARCHAR(4096) NOT NULL,
"creator" VARCHAR(4096),
"description" VARCHAR(4096),
"auto_ingest" BOOLEAN DEFAULT 'f' NOT NULL,
"owner" INTEGER,
"type" INTEGER DEFAULT 1 NOT NULL,
@ -738,8 +738,8 @@ CREATE TABLE "podcast_episodes"
"file_id" INTEGER NOT NULL,
"podcast_id" INTEGER NOT NULL,
"publication_date" TIMESTAMP NOT NULL,
"download_url" VARCHAR(512) NOT NULL,
"episode_guid" VARCHAR(512) NOT NULL,
"download_url" VARCHAR(4096) NOT NULL,
"episode_guid" VARCHAR(4096) NOT NULL,
PRIMARY KEY ("id")
);