Beispiel #1
0
 /**
  * Adds a metadata object associated with Kaltura object
  * 
  * @param int $metadataProfileId
  * @param KalturaMetadataObjectType $objectType
  * @param string $objectId
  * @return Metadata
  * @throws MetadataErrors::METADATA_ALREADY_EXISTS
  * @throws MetadataErrors::INVALID_METADATA_PROFILE
  * @throws MetadataErrors::INVALID_METADATA_PROFILE_TYPE
  * @throws MetadataErrors::INVALID_METADATA_OBJECT
  */
 protected function addMetadata($metadataProfileId, $objectType, $objectId)
 {
     $objectType = kPluginableEnumsManager::apiToCore('MetadataObjectType', $objectType);
     $check = MetadataPeer::retrieveByObject($metadataProfileId, $objectType, $objectId);
     if ($check) {
         throw new KalturaAPIException(MetadataErrors::METADATA_ALREADY_EXISTS, $check->getId());
     }
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_PROFILE, $metadataProfileId);
     }
     if ($dbMetadataProfile->getObjectType() != $objectType) {
         throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_PROFILE_TYPE, $dbMetadataProfile->getObjectType());
     }
     $dbMetadata = new Metadata();
     $dbMetadata->setPartnerId($this->getPartnerId());
     $dbMetadata->setMetadataProfileId($metadataProfileId);
     $dbMetadata->setMetadataProfileVersion($dbMetadataProfile->getVersion());
     $dbMetadata->setObjectType($objectType);
     $dbMetadata->setObjectId($objectId);
     $dbMetadata->setStatus(KalturaMetadataStatus::VALID);
     $dbMetadata->setLikeNew(true);
     // dynamic objects are metadata only, skip validating object id
     if ($objectType != KalturaMetadataObjectType::DYNAMIC_OBJECT) {
         // validate object exists
         $object = kMetadataManager::getObjectFromPeer($dbMetadata);
         if (!$object) {
             throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_OBJECT, $objectId);
         }
     }
     $dbMetadata->save();
     $this->deleteOldVersions($dbMetadata);
     return $dbMetadata;
 }