public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!$object_to_fill) {
         $object_to_fill = new kFileSyncResource();
     }
     $srcFlavorAsset = assetPeer::retrieveById($this->assetId);
     if (!$srcFlavorAsset) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $resource->assetId);
     }
     $object_to_fill->setFileSyncObjectType(FileSyncObjectType::FLAVOR_ASSET);
     $object_to_fill->setObjectSubType(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $object_to_fill->setObjectId($srcFlavorAsset->getId());
     return $object_to_fill;
 }
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!$object_to_fill) {
         $object_to_fill = new kFileSyncResource();
     }
     $srcEntry = entryPeer::retrieveByPK($this->entryId);
     if ($srcEntry->getMediaType() == KalturaMediaType::IMAGE) {
         $object_to_fill->setFileSyncObjectType(FileSyncObjectType::ENTRY);
         $object_to_fill->setObjectSubType(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         $object_to_fill->setObjectId($srcEntry->getId());
         return $object_to_fill;
     }
     $srcFlavorAsset = null;
     if (is_null($this->flavorParamsId)) {
         $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($this->entryId);
     } else {
         $srcFlavorAsset = assetPeer::retrieveByEntryIdAndParams($this->entryId, $this->flavorParamsId);
     }
     $object_to_fill->setFileSyncObjectType(FileSyncObjectType::FLAVOR_ASSET);
     $object_to_fill->setObjectSubType(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $object_to_fill->setObjectId($srcFlavorAsset->getId());
     return $object_to_fill;
 }
 /**
  * @param AttachmentAsset $attachmentAsset
  * @param kFileSyncResource $contentResource
  */
 protected function attachFileSyncResource(AttachmentAsset $attachmentAsset, kFileSyncResource $contentResource)
 {
     $syncable = kFileSyncObjectManager::retrieveObject($contentResource->getFileSyncObjectType(), $contentResource->getObjectId());
     $srcSyncKey = $syncable->getSyncKey($contentResource->getObjectSubType(), $contentResource->getVersion());
     return $this->attachFileSync($attachmentAsset, $srcSyncKey);
 }
 /**
  * @param kFileSyncResource $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return asset | NULL in case of IMAGE entry
  * @throws KalturaErrors::UPLOAD_ERROR
  * @throws KalturaErrors::INVALID_OBJECT_ID
  */
 protected function attachFileSyncResource(kFileSyncResource $resource, entry $dbEntry, asset $dbAsset = null)
 {
     $dbEntry->setSource(entry::ENTRY_MEDIA_SOURCE_KALTURA);
     $dbEntry->save();
     try {
         $syncable = kFileSyncObjectManager::retrieveObject($resource->getFileSyncObjectType(), $resource->getObjectId());
     } catch (kFileSyncException $e) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $resource->getObjectId());
     }
     $srcSyncKey = $syncable->getSyncKey($resource->getObjectSubType(), $resource->getVersion());
     $dbAsset = $this->attachFileSync($srcSyncKey, $dbEntry, $dbAsset);
     //In case the target entry's media type is image no asset is created and the image is set on a entry level file sync
     if (!$dbAsset && $dbEntry->getMediaType() == KalturaMediaType::IMAGE) {
         return null;
     }
     // Copy the media info from the old asset to the new one
     if ($syncable instanceof asset && $resource->getObjectSubType() == asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET) {
         $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($syncable->getId());
         if ($mediaInfo) {
             $newMediaInfo = $mediaInfo->copy();
             $newMediaInfo->setFlavorAssetId($dbAsset->getId());
             $newMediaInfo->save();
         }
         if ($dbAsset->getStatus() == asset::ASSET_STATUS_READY) {
             $dbEntry->syncFlavorParamsIds();
             $dbEntry->save();
         }
     }
     return $dbAsset;
 }
 /**
  * @param kFileSyncResource $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return asset
  * @throws KalturaErrors::UPLOAD_ERROR
  * @throws KalturaErrors::INVALID_OBJECT_ID
  */
 protected function attachFileSyncResource(kFileSyncResource $resource, entry $dbEntry, asset $dbAsset = null)
 {
     $dbEntry->setSource(entry::ENTRY_MEDIA_SOURCE_KALTURA);
     $dbEntry->save();
     try {
         $syncable = kFileSyncObjectManager::retrieveObject($resource->getFileSyncObjectType(), $resource->getObjectId());
     } catch (kFileSyncException $e) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $resource->getObjectId());
     }
     $srcSyncKey = $syncable->getSyncKey($resource->getObjectSubType(), $resource->getVersion());
     $dbAsset = $this->attachFileSync($srcSyncKey, $dbEntry, $dbAsset);
     // Copy the media info from the old asset to the new one
     if ($syncable instanceof asset && $resource->getObjectSubType() == asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET) {
         $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($syncable->getId());
         if ($mediaInfo) {
             $newMediaInfo = $mediaInfo->copy();
             $newMediaInfo->setFlavorAssetId($dbAsset->getId());
             $newMediaInfo->save();
         }
     }
     return $dbAsset;
 }
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     $this->validateForUsage($object_to_fill, $props_to_skip);
     $srcEntry = entryPeer::retrieveByPK($this->entryId);
     if (!$srcEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryId);
     }
     if ($srcEntry->getType() == entryType::LIVE_STREAM) {
         /* @var $srcEntry LiveEntry */
         if (!in_array($srcEntry->getSource(), array(EntrySourceType::LIVE_STREAM, EntrySourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
             throw new KalturaAPIException(KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED, get_class($this));
         }
         $mediaServer = $srcEntry->getMediaServer();
         if ($mediaServer && !is_null($mediaServer->getDc()) && $mediaServer->getDc() != kDataCenterMgr::getCurrentDcId()) {
             $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($mediaServer->getDc());
             if ($remoteDCHost) {
                 kFileUtils::dumpApiRequest($remoteDCHost);
             } else {
                 throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
             }
         }
         if ($object_to_fill && !$object_to_fill instanceof kLiveEntryResource) {
             throw new KalturaAPIException(KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED, get_class($object_to_fill));
         }
         $object_to_fill = new kLiveEntryResource();
         $object_to_fill->setEntry($srcEntry);
         return $object_to_fill;
     }
     if (!$object_to_fill) {
         $object_to_fill = new kFileSyncResource();
     }
     if ($srcEntry->getMediaType() == KalturaMediaType::IMAGE) {
         $object_to_fill->setFileSyncObjectType(FileSyncObjectType::ENTRY);
         $object_to_fill->setObjectSubType(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         $object_to_fill->setObjectId($srcEntry->getId());
         return $object_to_fill;
     }
     $srcFlavorAsset = null;
     if (is_null($this->flavorParamsId)) {
         $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($this->entryId);
         if (!$srcFlavorAsset) {
             throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
         }
     } else {
         $srcFlavorAsset = assetPeer::retrieveByEntryIdAndParams($this->entryId, $this->flavorParamsId);
         if (!$srcFlavorAsset) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $this->flavorParamsId);
         }
     }
     $object_to_fill->setFileSyncObjectType(FileSyncObjectType::FLAVOR_ASSET);
     $object_to_fill->setObjectSubType(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $object_to_fill->setObjectId($srcFlavorAsset->getId());
     $object_to_fill->setOriginEntryId($this->entryId);
     return $object_to_fill;
 }