From 1445e857952c10246f3b587e30b182539db052fc Mon Sep 17 00:00:00 2001 From: drigato Date: Sun, 20 Sep 2015 12:06:51 -0400 Subject: [PATCH] SAAS-1058: Podcast table schema Changed podcast table column sizes Added some podcast table column size validation --- .../application/models/airtime/Podcast.php | 57 ++++++++++++++----- .../airtime/map/PodcastEpisodesTableMap.php | 4 +- .../models/airtime/map/PodcastTableMap.php | 8 +-- airtime_mvc/build/schema.xml | 12 ++-- airtime_mvc/build/sql/schema.sql | 12 ++-- 5 files changed, 60 insertions(+), 33 deletions(-) diff --git a/airtime_mvc/application/models/airtime/Podcast.php b/airtime_mvc/application/models/airtime/Podcast.php index 0f54017ec..766966518 100644 --- a/airtime_mvc/application/models/airtime/Podcast.php +++ b/airtime_mvc/application/models/airtime/Podcast.php @@ -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 diff --git a/airtime_mvc/application/models/airtime/map/PodcastEpisodesTableMap.php b/airtime_mvc/application/models/airtime/map/PodcastEpisodesTableMap.php index a9609542b..8a1bb9b1d 100644 --- a/airtime_mvc/application/models/airtime/map/PodcastEpisodesTableMap.php +++ b/airtime_mvc/application/models/airtime/map/PodcastEpisodesTableMap.php @@ -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() diff --git a/airtime_mvc/application/models/airtime/map/PodcastTableMap.php b/airtime_mvc/application/models/airtime/map/PodcastTableMap.php index b8cd44c2b..0fa3822f5 100644 --- a/airtime_mvc/application/models/airtime/map/PodcastTableMap.php +++ b/airtime_mvc/application/models/airtime/map/PodcastTableMap.php @@ -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); diff --git a/airtime_mvc/build/schema.xml b/airtime_mvc/build/schema.xml index ec5346165..5f3774f99 100644 --- a/airtime_mvc/build/schema.xml +++ b/airtime_mvc/build/schema.xml @@ -565,10 +565,10 @@ - - - - + + + + @@ -582,8 +582,8 @@ - - + + diff --git a/airtime_mvc/build/sql/schema.sql b/airtime_mvc/build/sql/schema.sql index 1e729bb70..a9c8d9cd5 100644 --- a/airtime_mvc/build/sql/schema.sql +++ b/airtime_mvc/build/sql/schema.sql @@ -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") );