public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     $this->validateForUsage($object_to_fill, $props_to_skip);
     $dbUploadToken = UploadTokenPeer::retrieveByPK($this->token);
     if (is_null($dbUploadToken)) {
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_NOT_FOUND);
     }
     if (!$object_to_fill) {
         $object_to_fill = new kUploadedFileTokenResource();
     }
     $object_to_fill->setToken($this->token);
     if ($dbUploadToken->getStatus() != UploadToken::UPLOAD_TOKEN_FULL_UPLOAD) {
         $object_to_fill->setIsReady(false);
         return $object_to_fill;
     }
     try {
         $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($this->token);
     } catch (kCoreException $ex) {
         if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) {
         }
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY);
         throw $ex;
     }
     if (!file_exists($entryFullPath)) {
         $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($this->token, kDataCenterMgr::getCurrentDcId());
         if ($remoteDCHost) {
             kFileUtils::dumpApiRequest($remoteDCHost);
         } else {
             throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
         }
     }
     $object_to_fill->setLocalFilePath($entryFullPath);
     return $object_to_fill;
 }
예제 #2
0
 /**
  * Generic add entry using an uploaded file, should be used when the uploaded entry type is not known
  *
  * @action addFromUploadedFile
  * @param KalturaBaseEntry $entry
  * @param string $uploadTokenId
  * @param KalturaEntryType $type
  * @return KalturaBaseEntry
  */
 function addFromUploadedFileAction(KalturaBaseEntry $entry, $uploadTokenId, $type = -1)
 {
     try {
         // check that the uploaded file exists
         $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId);
     } catch (kCoreException $ex) {
         if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) {
         }
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY);
         throw $ex;
     }
     if (!file_exists($entryFullPath)) {
         $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId());
         if ($remoteDCHost) {
             kFile::dumpApiRequest($remoteDCHost);
         } else {
             throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
         }
     }
     // validate the input object
     //$entry->validatePropertyMinLength("name", 1);
     if (!$entry->name) {
         $entry->name = $this->getPartnerId() . '_' . time();
     }
     // first copy all the properties to the db entry, then we'll check for security stuff
     $dbEntry = $entry->toInsertableObject(new entry());
     $dbEntry->setType($type);
     $dbEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_AUTOMATIC);
     $this->checkAndSetValidUser($entry, $dbEntry);
     $this->checkAdminOnlyInsertProperties($entry);
     $this->validateAccessControlId($entry);
     $this->validateEntryScheduleDates($entry);
     $dbEntry->setPartnerId($this->getPartnerId());
     $dbEntry->setSubpId($this->getPartnerId() * 100);
     $dbEntry->setSourceId($uploadTokenId);
     $dbEntry->setSourceLink($entryFullPath);
     $dbEntry->setDefaultModerationStatus();
     $dbEntry->save();
     $kshow = $this->createDummyKShow();
     $kshowId = $kshow->getId();
     myEntryUtils::setEntryTypeAndMediaTypeFromFile($dbEntry, $entryFullPath);
     // setup the needed params for my insert entry helper
     $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags());
     $token = $this->getKsUniqueString();
     $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray);
     $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100);
     $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry);
     $dbEntry = $insert_entry_helper->getEntry();
     kUploadTokenMgr::closeUploadTokenById($uploadTokenId);
     myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry);
     $entry->fromObject($dbEntry);
     return $entry;
 }
예제 #3
0
 /**
  * Add new document entry after the specific document file was uploaded and the upload token id exists
  *
  * @action addFromUploadedFile
  * @param KalturaDocumentEntry $documentEntry Document entry metadata
  * @param string $uploadTokenId Upload token id
  * @return KalturaDocumentEntry The new document entry
  * 
  * @throws KalturaErrors::PROPERTY_VALIDATION_MIN_LENGTH
  * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
  * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
  */
 function addFromUploadedFileAction(KalturaDocumentEntry $documentEntry, $uploadTokenId)
 {
     try {
         // check that the uploaded file exists
         $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId);
     } catch (kCoreException $ex) {
         if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) {
         }
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY);
         throw $ex;
     }
     if (!file_exists($entryFullPath)) {
         $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId());
         if ($remoteDCHost) {
             kFile::dumpApiRequest($remoteDCHost);
         } else {
             throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
         }
     }
     $dbEntry = $this->prepareEntryForInsert($documentEntry);
     $dbEntry->setSource(KalturaSourceType::FILE);
     $dbEntry->setSourceLink("file:{$entryFullPath}");
     $dbEntry->save();
     $te = new TrackEntry();
     $te->setEntryId($dbEntry->getId());
     $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY);
     $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_FILE");
     TrackEntry::addTrackEntry($te);
     $msg = null;
     $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId(), $msg);
     if (!$flavorAsset) {
         KalturaLog::err("Flavor asset not created for entry [" . $dbEntry->getId() . "] reason [{$msg}]");
         $dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
         $dbEntry->save();
     } else {
         $ext = pathinfo($entryFullPath, PATHINFO_EXTENSION);
         KalturaLog::info("Uploaded file extension: {$ext}");
         $flavorAsset->setFileExt($ext);
         $flavorAsset->save();
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         kFileSyncUtils::moveFromFile($entryFullPath, $syncKey);
         kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
     }
     kUploadTokenMgr::closeUploadTokenById($uploadTokenId);
     myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry);
     $documentEntry->fromObject($dbEntry);
     return $documentEntry;
 }
예제 #4
0
 /**
  * Add new entry after the specific media file was uploaded and the upload token id exists
  *
  * @action addFromUploadedFile
  * @param KalturaMediaEntry $mediaEntry Media entry metadata
  * @param string $uploadTokenId Upload token id
  * @return KalturaMediaEntry The new media entry
  * 
  * @throws KalturaErrors::PROPERTY_VALIDATION_MIN_LENGTH
  * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
  * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
  */
 function addFromUploadedFileAction(KalturaMediaEntry $mediaEntry, $uploadTokenId)
 {
     try {
         // check that the uploaded file exists
         $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId);
     } catch (kCoreException $ex) {
         if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) {
         }
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY);
         throw $ex;
     }
     if (!file_exists($entryFullPath)) {
         $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId());
         if ($remoteDCHost) {
             kFile::dumpApiRequest($remoteDCHost);
         } else {
             throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
         }
     }
     $dbEntry = $this->prepareEntryForInsert($mediaEntry);
     $kshowId = $dbEntry->getKshowId();
     // setup the needed params for my insert entry helper
     $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags());
     $token = $this->getKsUniqueString();
     $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray);
     $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100);
     $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry);
     $dbEntry = $insert_entry_helper->getEntry();
     kUploadTokenMgr::closeUploadTokenById($uploadTokenId);
     $ret = new KalturaMediaEntry();
     if ($dbEntry) {
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry, $dbEntry->getPartnerId(), null, null, null, $dbEntry->getId());
         $ret->fromObject($dbEntry);
     }
     return $ret;
 }
예제 #5
0
 /**
  * Add new entry after the specific media file was uploaded and the upload token id exists
  *
  * @action addFromUploadedFile
  * @param KalturaMediaEntry $mediaEntry Media entry metadata
  * @param string $uploadTokenId Upload token id
  * @return KalturaMediaEntry The new media entry
  *
  * @throws KalturaErrors::PROPERTY_VALIDATION_MIN_LENGTH
  * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
  * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
  *
  * @deprecated use media.add instead
  */
 function addFromUploadedFileAction(KalturaMediaEntry $mediaEntry, $uploadTokenId)
 {
     if ($mediaEntry->conversionQuality && !$mediaEntry->conversionProfileId) {
         $mediaEntry->conversionProfileId = $mediaEntry->conversionQuality;
     }
     try {
         // check that the uploaded file exists
         $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId);
         // Make sure that the uploads path is not modified by $uploadTokenId (with the value of "../" for example )
         $entryRootDir = realpath(dirname($entryFullPath));
         $uploadPathBase = realpath(myContentStorage::getFSUploadsPath());
         if (strpos($entryRootDir, $uploadPathBase) !== 0) {
             KalturaLog::err("uploadTokenId [{$uploadTokenId}] points outside of uploads directory");
             throw new KalturaAPIException(KalturaErrors::INVALID_UPLOAD_TOKEN_ID);
         }
     } catch (kCoreException $ex) {
         if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) {
         }
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY);
         throw $ex;
     }
     if (!file_exists($entryFullPath)) {
         // Backward compatability - support case in which the required file exist in the other DC
         kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()));
         /*
         $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId());
         if($remoteDCHost)
         {
         	kFileUtils::dumpApiRequest($remoteDCHost);
         }
         else
         {
         	throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
         }
         */
     }
     $dbEntry = parent::add($mediaEntry, $mediaEntry->conversionProfileId);
     $kshowId = $dbEntry->getKshowId();
     // setup the needed params for my insert entry helper
     $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags());
     $token = $this->getKsUniqueString();
     $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray);
     $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100);
     $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry);
     $dbEntry = $insert_entry_helper->getEntry();
     kUploadTokenMgr::closeUploadTokenById($uploadTokenId);
     $ret = new KalturaMediaEntry();
     if ($dbEntry) {
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry, $dbEntry->getPartnerId(), null, null, null, $dbEntry->getId());
         $ret->fromObject($dbEntry, $this->getResponseProfile());
     }
     return $ret;
 }
 /**
  * add KalturaMediaEntry from email ingestion
  *
  * @action addMediaEntry
  * @param KalturaMediaEntry $mediaEntry Media entry metadata
  * @param string $uploadTokenId Upload token id
  * @param int $emailProfId
  * @param string $fromAddress
  * @param string $emailMsgId
  *
  * @return KalturaMediaEntry
  *
  * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
  * @throws KalturaErrors::EMAIL_INGESTION_PROFILE_NOT_FOUND
  *
  */
 function addMediaEntryAction(KalturaMediaEntry $mediaEntry, $uploadTokenId, $emailProfId, $fromAddress, $emailMsgId)
 {
     try {
         // check that the uploaded file exists
         $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId);
         if (!file_exists($entryFullPath)) {
             throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
         }
         // get the email profile by the given id
         $existingEIP = EmailIngestionProfilePeer::retrieveByPK($emailProfId);
         if (!$existingEIP) {
             throw new KalturaAPIException(KalturaErrors::EMAIL_INGESTION_PROFILE_NOT_FOUND, $emailProfId);
         }
         $emailIP = new KalturaEmailIngestionProfile();
         $emailIP->fromObject($existingEIP, $this->getResponseProfile());
         // handle defaults for media entry metadata
         $this->changeIfNull($mediaEntry->tags, $emailIP->defaultTags);
         $this->changeIfNull($mediaEntry->adminTags, $emailIP->defaultAdminTags);
         $this->changeIfNull($mediaEntry->conversionProfileId, $emailIP->conversionProfile2Id);
         $this->changeIfNull($mediaEntry->userId, $emailIP->defaultUserId);
         if (is_null($mediaEntry->categories) || is_null(categoryPeer::getByFullNameExactMatch($mediaEntry->categories))) {
             $mediaEntry->categories = $emailIP->defaultCategory;
         }
         // validate the input object
         //$entry->validatePropertyMinLength("name", 1);
         if (!$mediaEntry->name) {
             $mediaEntry->name = $this->getPartnerId() . '_' . time();
         }
         // first copy all the properties to the db entry, then we'll check for security stuff
         $dbEntry = $mediaEntry->toObject(new entry());
         if ($emailIP->moderationStatus == KalturaEntryModerationStatus::PENDING_MODERATION) {
             $dbEntry->setModerate(true);
         }
         $dbEntry->setType(KalturaEntryType::MEDIA_CLIP);
         $dbEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_AUTOMATIC);
         $this->checkAndSetValidUserInsert($mediaEntry, $dbEntry);
         $this->checkAdminOnlyInsertProperties($mediaEntry);
         $this->validateAccessControlId($mediaEntry);
         $this->validateEntryScheduleDates($mediaEntry, $dbEntry);
         $dbEntry->setPartnerId($this->getPartnerId());
         $dbEntry->setSubpId($this->getPartnerId() * 100);
         $dbEntry->setSourceId($uploadTokenId);
         $dbEntry->setSourceLink($entryFullPath);
         $dbEntry->setDefaultModerationStatus();
         $dbEntry->save();
         $te = new TrackEntry();
         $te->setEntryId($dbEntry->getId());
         $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY);
         $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_EMAIL_INGESTION");
         $te->setParam1Str($fromAddress);
         $te->setParam2Str($emailMsgId);
         $te->setParam3Str($emailProfId . '::' . $emailIP->emailAddress . '::' . $emailIP->mailboxId);
         TrackEntry::addTrackEntry($te);
         $kshow = $this->createDummyKShow();
         $kshowId = $kshow->getId();
         myEntryUtils::setEntryTypeAndMediaTypeFromFile($dbEntry, $entryFullPath);
         // setup the needed params for my insert entry helper
         $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags());
         $token = $this->getKsUniqueString();
         $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray);
         $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100);
         $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry);
         $dbEntry = $insert_entry_helper->getEntry();
         kUploadTokenMgr::closeUploadTokenById($uploadTokenId);
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry);
         $mediaEntry->fromObject($dbEntry, $this->getResponseProfile());
         return $mediaEntry;
     } catch (kCoreException $ex) {
         if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) {
         }
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY);
         throw $ex;
     }
 }
예제 #7
0
 /**
  * @param UploadToken $uploadToken
  */
 public static function handleUploadFinished(UploadToken $uploadToken)
 {
     if (!is_subclass_of($uploadToken->getObjectType(), assetPeer::OM_CLASS) && $uploadToken->getObjectType() != FileAssetPeer::OM_CLASS && $uploadToken->getObjectType() != entryPeer::OM_CLASS) {
         KalturaLog::info("Class [" . $uploadToken->getObjectType() . "] not supported");
         return;
     }
     $fullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadToken->getId());
     if (!file_exists($fullPath)) {
         KalturaLog::info("File path [{$fullPath}] not found");
         $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadToken->getId(), kDataCenterMgr::getCurrentDcId());
         if (!$remoteDCHost) {
             KalturaLog::err("File path [{$fullPath}] could not be redirected");
             return;
         }
         kFileUtils::dumpApiRequest($remoteDCHost);
     }
     if ($uploadToken->getObjectType() == FileAssetPeer::OM_CLASS) {
         $dbFileAsset = FileAssetPeer::retrieveByPK($uploadToken->getObjectId());
         if (!$dbFileAsset) {
             KalturaLog::err("File asset id [" . $uploadToken->getObjectId() . "] not found");
             return;
         }
         if (!$dbFileAsset->getFileExt()) {
             $dbFileAsset->setFileExt(pathinfo($fullPath, PATHINFO_EXTENSION));
         }
         $dbFileAsset->incrementVersion();
         $dbFileAsset->save();
         $syncKey = $dbFileAsset->getSyncKey(FileAsset::FILE_SYNC_ASSET);
         try {
             kFileSyncUtils::moveFromFile($fullPath, $syncKey, true);
         } catch (Exception $e) {
             $dbFileAsset->setStatus(FileAssetStatus::ERROR);
             $dbFileAsset->save();
             throw $e;
         }
         if ($dbFileAsset->getStatus() == FileAssetStatus::UPLOADING) {
             $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
             $dbFileAsset->setSize(kFile::fileSize($finalPath));
             $dbFileAsset->setStatus(FileAssetStatus::READY);
             $dbFileAsset->save();
         }
         $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED);
         $uploadToken->save();
         KalturaLog::info("File asset [" . $dbFileAsset->getId() . "] handled");
         return;
     }
     if (is_subclass_of($uploadToken->getObjectType(), assetPeer::OM_CLASS)) {
         $dbAsset = assetPeer::retrieveById($uploadToken->getObjectId());
         if (!$dbAsset) {
             KalturaLog::err("Asset id [" . $uploadToken->getObjectId() . "] not found");
             return;
         }
         $ext = pathinfo($fullPath, PATHINFO_EXTENSION);
         $dbAsset->setFileExt($ext);
         $dbAsset->incrementVersion();
         $dbAsset->save();
         $syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         try {
             kFileSyncUtils::moveFromFile($fullPath, $syncKey, true);
         } catch (Exception $e) {
             if ($dbAsset instanceof flavorAsset) {
                 kBatchManager::updateEntry($dbAsset->getEntryId(), entryStatus::ERROR_IMPORTING);
             }
             $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $dbAsset->save();
             throw $e;
         }
         if ($dbAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING) {
             $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
             $dbAsset->setSize(kFile::fileSize($finalPath));
             if ($dbAsset instanceof flavorAsset) {
                 if ($dbAsset->getIsOriginal()) {
                     $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED);
                 } else {
                     $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING);
                 }
             } else {
                 $dbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
             }
             if ($dbAsset instanceof thumbAsset) {
                 list($width, $height, $type, $attr) = getimagesize($finalPath);
                 $dbAsset->setWidth($width);
                 $dbAsset->setHeight($height);
             }
             $dbAsset->save();
             kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset));
         }
         $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED);
         $uploadToken->save();
     }
     if ($uploadToken->getObjectType() == entryPeer::OM_CLASS) {
         $dbEntry = entryPeer::retrieveByPK($uploadToken->getObjectId());
         if (!$dbEntry) {
             KalturaLog::err("Entry id [" . $uploadToken->getObjectId() . "] not found");
             return;
         }
         //Keep original extention
         $ext = pathinfo($fullPath, PATHINFO_EXTENSION);
         // increments version
         $dbEntry->setData('100000.' . $ext);
         $dbEntry->save();
         $syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         try {
             kFileSyncUtils::moveFromFile($fullPath, $syncKey, true);
         } catch (Exception $e) {
             if ($dbAsset instanceof flavorAsset) {
                 kBatchManager::updateEntry($dbEntry->getId(), entryStatus::ERROR_IMPORTING);
             }
             throw $e;
         }
         $dbEntry->setStatus(entryStatus::READY);
         $dbEntry->save();
         $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED);
         $uploadToken->save();
     }
 }
 /**
  * Deletes the upload token by upload token id
  * 
  * @action delete
  * @param string $uploadTokenId
  */
 function deleteAction($uploadTokenId)
 {
     $this->restrictPeerToCurrentUser();
     $uploadTokenDb = UploadTokenPeer::retrieveByPK($uploadTokenId);
     if (is_null($uploadTokenDb)) {
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_NOT_FOUND);
     }
     $uploadTokenMgr = new kUploadTokenMgr($uploadTokenDb);
     try {
         $uploadTokenMgr->deleteUploadToken();
     } catch (kCoreException $ex) {
         throw $ex;
     }
 }