Merge branch 'cc-5709-airtime-analyzer' into cc-5709-airtime-analyzer-saas

This commit is contained in:
Albert Santoni 2014-05-26 19:11:47 -04:00
commit 01fc9e6ffc
4 changed files with 213 additions and 85 deletions

View file

@ -215,7 +215,6 @@ class Rest_MediaController extends Zend_Rest_Controller
$requestData = json_decode($this->getRequest()->getRawBody(), true);
$whiteList = $this->removeBlacklistedFieldsFromRequestData($requestData);
$whiteList = $this->stripTimeStampFromYearTag($whiteList);
$whiteList = $this->truncateGenreTag($whiteList);
if (!$this->validateRequestData($file, $whiteList)) {
$file->save();
@ -375,12 +374,29 @@ class Rest_MediaController extends Zend_Rest_Controller
$resp->appendBody("ERROR: Invalid data");
}
private function validateRequestData($file, $whiteList)
private function validateRequestData($file, &$whiteList)
{
// EditAudioMD form is used here for validation
$fileForm = new Application_Form_EditAudioMD();
$fileForm->startForm($file->getDbId());
$fileForm->populate($whiteList);
/*
* Here we are truncating metadata of any characters greater than the
* max string length set in the database. In the rare case a track's
* genre is more than 64 chars, for example, we don't want to reject
* tracks for that reason
*/
foreach($whiteList as $tag => &$value) {
if ($fileForm->getElement($tag)) {
$stringLengthValidator = $fileForm->getElement($tag)->getValidator('StringLength');
//$stringLengthValidator will be false if the StringLength validator doesn't exist on the current element
//in which case we don't have to truncate the extra characters
if ($stringLengthValidator) {
$value = substr($value, 0, $stringLengthValidator->getMax());
}
}
}
if (!$fileForm->isValidPartial($whiteList)) {
$file->setDbImportStatus(2);
@ -503,20 +519,5 @@ class Rest_MediaController extends Zend_Rest_Controller
}
return $metadata;
}
/** The genre tag in our cc_files schema is currently a varchar(64). It's possible for MP3 genre tags
* to be longer than that, so we have to truncate longer genres. (We've seen ridiculously long genre tags.)
* @param string array $metadata
*/
private function truncateGenreTag($metadata)
{
if (isset($metadata["genre"]))
{
if (strlen($metadata["genre"]) >= 64) {
$metadata["genre"] = substr($metadata["genre"], 0, 64);
}
}
return $metadata;
}
}