/**
  * Update an existing metadata object
  *
  * @action update
  * @param int $id
  * @param KalturaMetadataProfile $metadataProfile
  * @param string $xsdData XSD metadata definition
  * @param string $viewsData UI views definition
  * @return KalturaMetadataProfile
  * @throws MetadataErrors::METADATA_PROFILE_NOT_FOUND
  * @throws MetadataErrors::METADATA_UNABLE_TO_TRANSFORM
  * @throws MetadataErrors::METADATA_TRANSFORMING
  * @throws MetadataErrors::METADATA_PROFILE_FILE_NOT_FOUND
  */
 function updateAction($id, KalturaMetadataProfile $metadataProfile, $xsdData = null, $viewsData = null)
 {
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_NOT_FOUND, $id);
     }
     if ($dbMetadataProfile->getStatus() != MetadataProfile::STATUS_ACTIVE) {
         throw new KalturaAPIException(MetadataErrors::METADATA_TRANSFORMING);
     }
     if ($xsdData) {
         if (!kMetadataProfileManager::validateXsdData($xsdData, $errorMessage)) {
             throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_PROFILE_SCHEMA, $errorMessage);
         }
         kMetadataManager::validateProfileFields($this->getPartnerId(), $xsdData);
     }
     $dbMetadataProfile = $metadataProfile->toUpdatableObject($dbMetadataProfile);
     $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     $oldXsd = kFileSyncUtils::file_get_contents($key, true, false);
     if (!$oldXsd) {
         throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_FILE_NOT_FOUND, $id);
     }
     if ($xsdData) {
         $xsdData = html_entity_decode($xsdData);
         $dbMetadataProfile->setXsdData($xsdData);
     }
     if (!is_null($viewsData) && $viewsData != '') {
         $viewsData = html_entity_decode($viewsData);
         $dbMetadataProfile->setViewesData($viewsData);
     }
     if ($xsdData) {
         try {
             kMetadataManager::diffMetadataProfile($dbMetadataProfile, $oldXsd, $xsdData);
         } catch (kXsdException $e) {
             throw new KalturaAPIException(MetadataErrors::METADATA_UNABLE_TO_TRANSFORM, $e->getMessage());
         }
         $dbMetadataProfile->save();
     } else {
         if (!is_null($viewsData) && $viewsData != '') {
             $dbMetadataProfile->save();
         }
     }
     $metadataProfile->fromObject($dbMetadataProfile, $this->getResponseProfile());
     return $metadataProfile;
 }