From 691841eba4b793d337da7997d88be17a06fb0223 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 12 May 2014 11:29:58 -0400 Subject: [PATCH] CC-5844: Airtime Analyzer: Auto format the 'year' tag. --- .../rest/controllers/MediaController.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index 8a578fc0c..dbe579606 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -221,6 +221,7 @@ class Rest_MediaController extends Zend_Rest_Controller $requestData = json_decode($this->getRequest()->getRawBody(), true); $whiteList = $this->removeBlacklistedFieldsFromRequestData($requestData); + $whiteList = $this->stripTimeStampFromYearTag($whiteList); if (!$this->validateRequestData($file, $whiteList)) { $file->save(); @@ -486,5 +487,21 @@ class Rest_MediaController extends Zend_Rest_Controller exec("find $path -empty -type d -delete"); } + /* + * It's possible that the year tag will be a timestamp but Airtime doesn't support this. + * The year field in cc_files can only be 16 chars max. + * + * This functions strips the year field of it's timestamp, if one, and leaves just the year + */ + private function stripTimeStampFromYearTag($metadata) + { + if (isset($metadata["year"])) { + if (preg_match("/^(\d{4})-(\d{2})-(\d{2})(?:\s+(\d{2}):(\d{2}):(\d{2}))?$/", $metadata["year"])) { + $metadata["year"] = substr($metadata["year"], 0, 4); + } + } + return $metadata; + } + }