/**
  * 
  * @param int $objectType
  * @param string $objectId
  * @return ISyncableFile
  */
 public static function retrieveObject($objectType, $objectId)
 {
     $object = null;
     switch ($objectType) {
         case FileSyncObjectType::ENTRY:
             entryPeer::setUseCriteriaFilter(false);
             $object = entryPeer::retrieveByPK($objectId);
             entryPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::UICONF:
             uiConfPeer::setUseCriteriaFilter(false);
             $object = uiConfPeer::retrieveByPK($objectId);
             uiConfPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::BATCHJOB:
             BatchJobPeer::setUseCriteriaFilter(false);
             $object = BatchJobPeer::retrieveByPK($objectId);
             BatchJobPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::FLAVOR_ASSET:
             assetPeer::setUseCriteriaFilter(false);
             $object = assetPeer::retrieveById($objectId);
             assetPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::SYNDICATION_FEED:
             syndicationFeedPeer::setUseCriteriaFilter(false);
             $object = syndicationFeedPeer::retrieveByPK($objectId);
             syndicationFeedPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::CONVERSION_PROFILE:
             conversionProfile2Peer::setUseCriteriaFilter(false);
             $object = conversionProfile2Peer::retrieveByPK($objectId);
             conversionProfile2Peer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::FILE_ASSET:
             conversionProfile2Peer::setUseCriteriaFilter(false);
             $object = FileAssetPeer::retrieveByPK($objectId);
             conversionProfile2Peer::setUseCriteriaFilter(true);
             break;
     }
     if ($object == null) {
         $object = KalturaPluginManager::loadObject('ISyncableFile', $objectType, array('objectId' => $objectId));
     }
     if ($object == null) {
         $error = __METHOD__ . " Cannot find object type [" . $objectType . "] with object_id [" . $objectId . "]";
         KalturaLog::err($error);
         throw new kFileSyncException($error);
     }
     return $object;
 }
Example #2
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();
     }
 }
Example #3
0
 /**
  * Set content of file asset
  *
  * @action setContent
  * @param string $id
  * @param KalturaContentResource $contentResource
  * @return KalturaFileAsset
  * @throws KalturaErrors::FILE_ASSET_ID_NOT_FOUND
  * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
  * @throws KalturaErrors::RECORDED_WEBCAM_FILE_NOT_FOUND
  * @throws KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED 
  */
 function setContentAction($id, KalturaContentResource $contentResource)
 {
     $dbFileAsset = FileAssetPeer::retrieveByPK($id);
     if (!$dbFileAsset) {
         throw new KalturaAPIException(KalturaErrors::FILE_ASSET_ID_NOT_FOUND, $id);
     }
     $kContentResource = $contentResource->toObject();
     $this->attachContentResource($dbFileAsset, $kContentResource);
     $fileAsset = new KalturaFileAsset();
     $fileAsset->fromObject($dbFileAsset, $this->getResponseProfile());
     return $fileAsset;
 }