/**
  * @param entry $entry
  * @return array<FileSyncKey>
  */
 protected static function getEntrySyncKeys(entry $entry, StorageProfile $externalStorage)
 {
     $exportFileSyncsKeys = array();
     $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
     $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     $flavorAssets = array();
     $flavorParamsIds = $externalStorage->getFlavorParamsIds();
     KalturaLog::log(__METHOD__ . " flavorParamsIds [{$flavorParamsIds}]");
     $relevantStatuses = array(asset::ASSET_STATUS_READY, asset::ASSET_STATUS_EXPORTING);
     if (is_null($flavorParamsIds) || !strlen(trim($flavorParamsIds))) {
         $flavorAssets = assetPeer::retrieveFlavorsByEntryIdAndStatus($entry->getId(), null, $relevantStatuses);
     } else {
         $flavorParamsArr = explode(',', $flavorParamsIds);
         KalturaLog::log(__METHOD__ . " flavorParamsIds count [" . count($flavorParamsArr) . "]");
         $flavorAssets = assetPeer::retrieveFlavorsByEntryIdAndStatus($entry->getId(), $flavorParamsArr, $relevantStatuses);
     }
     foreach ($flavorAssets as $flavorAsset) {
         if ($externalStorage->shouldExportFlavorAsset($flavorAsset)) {
             $exportFileSyncsKeys[] = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         } else {
             KalturaLog::log('Flavor asset id [' . $flavorAsset->getId() . '] should not be exported');
         }
     }
     return $exportFileSyncsKeys;
 }
Exemplo n.º 2
0
 protected function initSilverLightManifest($flavorAssets)
 {
     $key = $this->getFlavorKeyByTag($flavorAssets, assetParams::TAG_ISM_MANIFEST, flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     if (!$key) {
         $key = $this->entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     }
     $localFileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key);
     $remoteFileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key);
     //To Remove - Until the migration process from asset sub type 3 to asset sub type 1 will be completed we need to support both formats
     if (!$localFileSync && !$remoteFileSync) {
         $key = $this->getFlavorKeyByTag($flavorAssets, assetParams::TAG_ISM_MANIFEST, flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISM);
         $localFileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key);
         $remoteFileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key);
     }
     if ($this->shouldUseLocalFlavors($localFileSync, $remoteFileSync)) {
         $this->deliveryAttributes->setStorageId(null);
         $this->deliveryAttributes->setManifestFileSync($localFileSync);
     } else {
         if ($remoteFileSync) {
             $this->deliveryAttributes->setStorageId($remoteFileSync->getDc());
         }
         $this->deliveryAttributes->setManifestFileSync($remoteFileSync);
     }
     if (!$this->deliveryAttributes->getManifestFileSync()) {
         KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
     }
 }
 /**
  * @return kManifestRenderer
  */
 private function serveSilverLight()
 {
     $duration = $this->entry->getDurationInt();
     $syncKey = $this->entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     $manifestInfo = $this->getSmoothStreamUrl($syncKey);
     $renderer = new kSilverLightManifestRenderer();
     $renderer->entryId = $this->entryId;
     $renderer->tokenizer = $this->tokenizer;
     $renderer->flavor = $manifestInfo;
     $renderer->duration = $duration;
     return $renderer;
 }
Exemplo n.º 4
0
 /**
  * @param entry $entry
  * @return array<FileSyncKey>
  */
 protected function getEntrySyncKeys(entry $entry, StorageProfile $externalStorage)
 {
     $exportFileSyncsKeys = array();
     $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
     $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     $flavorAssets = array();
     $flavorParamsIds = $externalStorage->getFlavorParamsIds();
     KalturaLog::log(__METHOD__ . " flavorParamsIds [{$flavorParamsIds}]");
     if (is_null($flavorParamsIds) || !strlen(trim($flavorParamsIds))) {
         $flavorAssets = flavorAssetPeer::retreiveReadyByEntryId($entry->getId());
     } else {
         $flavorParamsArr = explode(',', $flavorParamsIds);
         KalturaLog::log(__METHOD__ . " flavorParamsIds count [" . count($flavorParamsArr) . "]");
         $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndFlavorParams($entry->getId(), $flavorParamsArr);
     }
     foreach ($flavorAssets as $flavorAsset) {
         $exportFileSyncsKeys[] = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     }
     return $exportFileSyncsKeys;
 }
Exemplo n.º 5
0
 /**
  * @param asset $asset
  * @params entry $entry
  * @return string
  */
 public static function getFileName(entry $entry, flavorAsset $flavorAsset = null)
 {
     $fileExt = "";
     $fileBaseName = $entry->getName();
     if ($flavorAsset) {
         $flavorParams = $flavorAsset->getFlavorParams();
         if ($flavorParams) {
             $fileBaseName = $fileBaseName . " (" . $flavorParams->getName() . ")";
         }
         $fileExt = $flavorAsset->getFileExt();
     } else {
         $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
         if ($fileSync) {
             $fileExt = $fileSync->getFileExt();
         }
     }
     return array($fileBaseName, $fileExt);
 }
Exemplo n.º 6
0
 private function serveSilverLight()
 {
     $duration = $this->entry->getDurationInt();
     $flavors = $this->buildFlavorsArray($duration);
     $streamType = self::PLAY_STREAM_TYPE_RECORDED;
     $durationXml = $duration ? "<duration>{$duration}</duration>" : '';
     $flvaorsXml = '';
     foreach ($flavors as $flavor) {
         $url = $flavor['url'];
         $bitrate = isset($flavor['bitrate']) ? $flavor['bitrate'] : 0;
         $width = isset($flavor['width']) ? $flavor['width'] : 0;
         $height = isset($flavor['height']) ? $flavor['height'] : 0;
         $url = htmlspecialchars($url);
         $flvaorsXml .= "<media url=\"{$url}\" bitrate=\"{$bitrate}\" width=\"{$width}\" height=\"{$height}\"/>";
     }
     $url = '';
     $syncKey = $this->entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     $url = $this->getSmoothStreamUrl($syncKey);
     $url = htmlspecialchars($url);
     return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\t\t\t\t<manifest url=\"{$url}\">\n\t\t\t\t\t<id>{$this->entryId}</id>\n\t\t\t\t\t<streamType>{$streamType}</streamType>\n\t\t\t\t\t{$durationXml}\n\t\t\t\t\t{$flvaorsXml}\n\t\t\t\t</manifest>";
     //		header("Location: $url/manifest");
     //		die;
 }
 /**
  * decideThumbGenerate is the decision layer for a single thumbnail generation 
  * 
  * @param entry $entry
  * @param thumbParams $destThumbParams
  * @param BatchJob $parentJob
  * @return thumbAsset 
  */
 public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false, $srcAsset = null)
 {
     if (is_null($srcAsset)) {
         $srcAsset = self::getSourceAssetForGenerateThumbnail($sourceAssetId, $destThumbParams->getSourceParamsId(), $entry->getId());
         if (is_null($srcAsset)) {
             throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY);
         }
     }
     $errDescription = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
     $destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription);
     if ($srcAsset->getType() == assetType::FLAVOR && is_null($destThumbParamsOutput->getVideoOffset())) {
         $destThumbParamsOutput->setVideoOffset($entry->getThumbOffset());
     }
     $destThumbParamsOutput->setVideoOffset(min($destThumbParamsOutput->getVideoOffset(), $entry->getDuration()));
     if (!$destThumbParamsOutput->getDensity()) {
         $partner = $entry->getPartner();
         if (!is_null($partner)) {
             $destThumbParamsOutput->setDensity($partner->getDefThumbDensity());
         }
     }
     $thumbAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId());
     if ($thumbAsset) {
         $description = $thumbAsset->getDescription() . "\n" . $errDescription;
         $thumbAsset->setDescription($description);
     } else {
         $thumbAsset = new thumbAsset();
         $thumbAsset->setPartnerId($entry->getPartnerId());
         $thumbAsset->setEntryId($entry->getId());
         $thumbAsset->setDescription($errDescription);
         $thumbAsset->setFlavorParamsId($destThumbParams->getId());
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setTags($destThumbParamsOutput->getTags());
     $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt());
     if ($thumbAsset->getStatus() != asset::ASSET_STATUS_READY) {
         $thumbAsset->setStatus(asset::ASSET_STATUS_CONVERTING);
     }
     //Sets the default thumb if this the only default thumb
     kBusinessPreConvertDL::setIsDefaultThumb($thumbAsset);
     if (!$destThumbParamsOutput) {
         $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
         $thumbAsset->save();
         return null;
     }
     $thumbAsset->save();
     // save flavor params
     $destThumbParamsOutput->setPartnerId($entry->getPartnerId());
     $destThumbParamsOutput->setEntryId($entry->getId());
     $destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId());
     $destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion());
     $destThumbParamsOutput->save();
     $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $srcAssetType = $srcAsset->getType();
     if (!$runSync) {
         $job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAsset->getId(), $srcAssetType, $destThumbParamsOutput);
         return $thumbAsset;
     }
     $errDescription = null;
     // Since this method is called when trying to crop an existing thumbnail, need to add this check - thumbAssets have no mediaInfo.
     $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription, $mediaInfo ? $mediaInfo->getVideoRotation() : null);
     // failed
     if (!$capturedPath) {
         $thumbAsset->incrementVersion();
         $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
         $thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}");
         $thumbAsset->save();
         return $thumbAsset;
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
     if (file_exists($capturedPath)) {
         list($width, $height, $type, $attr) = getimagesize($capturedPath);
         $thumbAsset->setWidth($width);
         $thumbAsset->setHeight($height);
         $thumbAsset->setSize(filesize($capturedPath));
     }
     $logPath = $capturedPath . '.log';
     if (file_exists($logPath)) {
         $thumbAsset->incLogFileVersion();
         $thumbAsset->save();
         // creats the file sync
         $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
         kFileSyncUtils::moveFromFile($logPath, $logSyncKey);
         KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey));
     } else {
         $thumbAsset->save();
     }
     $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($capturedPath, $syncKey);
     KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey));
     if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
         // increment thumbnail version
         $entry->setThumbnail(".jpg");
         $entry->setCreateThumb(false);
         $entry->save();
         $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey);
         if ($syncFile) {
             // removes the DEFAULT_THUMB tag from all other thumb assets
             $entryThumbAssets = assetPeer::retrieveThumbnailsByEntryId($thumbAsset->getEntryId());
             foreach ($entryThumbAssets as $entryThumbAsset) {
                 if ($entryThumbAsset->getId() == $thumbAsset->getId()) {
                     continue;
                 }
                 if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                     continue;
                 }
                 $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB));
                 $entryThumbAsset->save();
             }
         }
     }
     if (!is_null($thumbAsset->getFlavorParamsId())) {
         kFlowHelper::generateThumbnailsFromFlavor($thumbAsset->getEntryId(), null, $thumbAsset->getFlavorParamsId());
     }
     return $thumbAsset;
 }
 private function handleEntry($onlyExtractThumb, $prefix, $type, $entry_id, $name = null, $tags = null, $entry = null)
 {
     KalturaLog::debug("handleEntry({$type}, {$entry_id}, {$name})");
     $this->clear($prefix, $entry_id);
     $kuser_id = $this->kuser_id;
     $entry_data_prefix = $kuser_id . '_' . ($prefix == '' ? 'data' : rtrim($prefix, '_'));
     $uploads = myContentStorage::getFSUploadsPath();
     $content = myContentStorage::getFSContentRootPath();
     $media_source = $this->getParam('entry_media_source');
     $media_type = $this->getParam('entry_media_type');
     $entry_url = $this->getParam('entry_url');
     $entry_source_link = $this->getParam('entry_source_link');
     $entry_fileName = $this->getParam('entry_data');
     $entry_thumbNum = $this->getParam('entry_thumb_num', 0);
     $entry_thumbUrl = $this->getParam('entry_thumb_url', '');
     $should_copy = $this->getParam('should_copy', false);
     $skip_conversion = $this->getParam('skip_conversion', false);
     $webcam_suffix = $this->getParam('webcam_suffix', '');
     $duration = $this->getParam('duration', null);
     $entry_fullPath = "";
     $ext = null;
     $entry = null;
     if ($entry_id) {
         $entry = entryPeer::retrieveByPK($entry_id);
     } else {
         $entry = new entry();
     }
     $this->entry = $entry;
     $entry_status = $entry->getStatus();
     if (is_null($entry_status)) {
         $entry_status = entryStatus::READY;
     }
     // by the end of this block of code $entry_fullPath will point to the location of the entry
     // the entry status will be set (IMPORT / PRECONVERT / READY)
     // a background image is always previewed by the user no matter what source he used
     // so the entry is already in the /uploads directory
     // continue tracking the file upload
     $te = new TrackEntry();
     $te->setEntryId($entry_id);
     $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY);
     KalturaLog::debug("handleEntry: media_source: {$media_source}, prefix: {$prefix}");
     if ($media_source == entry::ENTRY_MEDIA_SOURCE_FILE || $prefix == 'bg_') {
         $full_path = $this->getParam('entry_full_path');
         if ($full_path) {
             $entry_fullPath = $full_path;
         } else {
             $entry_fullPath = $uploads . $entry_data_prefix . strrchr($entry_fileName, '.');
         }
         if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $entry_status = entryStatus::PRECONVERT;
         }
         $te->setParam3Str($entry_fullPath);
         $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_FILE");
     } else {
         if ($media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
             // set $entry_fileName to webcam output file and flag that conversion is not needed
             $webcam_basePath = $content . '/content/webcam/' . ($webcam_suffix ? $webcam_suffix : 'my_recorded_stream_' . $kuser_id);
             $entry_fullPath = $webcam_basePath . '.' . kWAMSWebcam::OUTPUT_FILE_EXT;
             $ext = kWAMSWebcam::OUTPUT_FILE_EXT;
             if (file_exists($entry_fullPath)) {
                 // continue tracking the webcam
                 $te->setParam3Str($entry_fullPath);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_WEBCAM");
             } else {
                 KalturaLog::err("File [{$entry_fullPath}] does not exist");
                 $entry_status = entryStatus::ERROR_IMPORTING;
             }
         } else {
             // if the url ends with .ext, we'll extract it this way
             $urlext = strrchr($entry_url, '.');
             // TODO: fix this patch
             if (strlen($urlext) > 4) {
                 $urlext = '.jpg';
             }
             // if we got something wierd, assume we're downloading a jpg
             $entry_fileName = $entry_data_prefix . $urlext;
             KalturaLog::debug("handleEntry: media_type: {$media_type}");
             if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
                 $duration = 0;
                 $entry_fullPath = $uploads . $entry_fileName;
                 if (!kFile::downloadUrlToFile($entry_url, $entry_fullPath)) {
                     KalturaLog::debug("Failed downloading file[{$entry_url}]");
                     $entry_status = entryStatus::ERROR_IMPORTING;
                 }
                 // track images
                 $te->setParam3Str($entry_fullPath);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_URL:ENTRY_MEDIA_TYPE_IMAGE");
             } else {
                 if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
                     //fixme - we can extract during import
                     $ext = "flv";
                 } else {
                     $ext = "mp3";
                 }
                 $entry_status = entryStatus::IMPORT;
                 // track images
                 $te->setParam3Str($ext);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_URL:ENTRY_MEDIA_TYPE_VIDEO");
             }
         }
     }
     if ($ext == null) {
         $entry_fullPathTmp = $entry_fullPath;
         $qpos = strpos($entry_fullPathTmp, "?");
         if ($qpos !== false) {
             $entry_fullPathTmp = substr($entry_fullPathTmp, 0, $qpos);
         }
         $ext = strtolower(pathinfo($entry_fullPathTmp, PATHINFO_EXTENSION));
     }
     // save the Trackentry
     TrackEntry::addTrackEntry($te);
     KalturaLog::debug("handleEntry: ext: {$ext}");
     //		We don't want to reject entries based on file extentions anumore
     //		Remarked by Tan-Tan
     //
     //		if ($entry_status == entryStatus::PRECONVERT && !myContentStorage::fileExtNeedConversion($ext))
     //		{
     //
     //			$this->errorMsg = "insertEntryAction Error - PRECONVERT file type not acceptable ($ext)";
     //			KalturaLog::debug("handleEntry: err: $this->errorMsg");
     //			if(is_null($entry) && $this->entry_id)
     //			{
     //				$entry = entryPeer::retrieveByPK($this->entry_id);
     //			}
     //			if($entry)
     //			{
     //				$entry->setStatus(entryStatus::ERROR_CONVERTING);
     //				$entry->save();
     //			}
     //			return false;
     //		}
     $media_date = null;
     //		We don't want to reject entries based on file extentions anumore
     //		Remarked by Tan-Tan
     //
     //		// if entry is ready, validate file type (webcam is an exception since we control the file type - flv)
     //		if ($entry_status == entryStatus::READY &&
     //			$media_source != entry::ENTRY_MEDIA_SOURCE_WEBCAM && !myContentStorage::fileExtAccepted($ext))
     //		{
     //			$this->errorMsg = "insertEntryAction Error - READY file type not acceptable ($ext)";
     //			KalturaLog::debug("handleEntry: err: $this->errorMsg");
     //			if(is_null($entry) && $this->entry_id)
     //			{
     //				$entry = entryPeer::retrieveByPK($this->entry_id);
     //			}
     //			if($entry)
     //			{
     //				$entry->setStatus(entryStatus::ERROR_CONVERTING);
     //				$entry->save();
     //			}
     //			return false;
     //		}
     if ($entry_status == entryStatus::ERROR_IMPORTING) {
         $need_thumb = false;
         // we wont be needing a thumb for an errornous entry
         KalturaLog::debug("handleEntry: error importing, thumb not needed");
     } else {
         // thumbs are created by one of the following ways:
         // 1. Image - images are already on disk for every selection method, so we can just create a thumb
         // 2. Audio - no thumb is needed
         // 3. Video -
         //		a. uploaded (file / webcam) - file is on disk and the user already selected a thumb
         //		b. imported - the source site had a thumbnail and we'll use it
         $thumbTempPrefix = $uploads . $entry_data_prefix . '_thumbnail_';
         $thumbBigFullPath = null;
         $need_thumb = $type == entryType::MEDIA_CLIP;
         KalturaLog::debug("handleEntry: handling media {$media_type}");
         if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
             // fetch media creation date
             $exif_image_type = @exif_imagetype($entry_fullPath);
             if ($exif_image_type == IMAGETYPE_JPEG || $exif_image_type == IMAGETYPE_TIFF_II || $exif_image_type == IMAGETYPE_TIFF_MM || $exif_image_type == IMAGETYPE_IFF || $exif_image_type == IMAGETYPE_PNG) {
                 $exif_data = @exif_read_data($entry_fullPath);
                 if ($exif_data && isset($exif_data["DateTimeOriginal"]) && $exif_data["DateTimeOriginal"]) {
                     $media_date = $exif_data["DateTimeOriginal"];
                     $ts = strtotime($media_date);
                     // handle invalid dates either due to bad format or out of range
                     if ($ts === -1 || $ts === false || $ts < strtotime('2000-01-01') || $ts > strtotime('2015-01-01')) {
                         $media_date = null;
                     }
                 }
             }
             // create thumb
             $thumbFullPath = $thumbTempPrefix . '1.jpg';
             $entry_thumbNum = 1;
             $need_thumb = true;
             //copy($entry_fullPath, $thumbFullPath);
             myFileConverter::createImageThumbnail($entry_fullPath, $thumbFullPath, "image2");
             //$thumbBigFullPath = $thumbFullPath; // no filesync for thumbnail of image
         } else {
             if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
                 if ($entry_status == entryStatus::IMPORT || $media_source == entry::ENTRY_MEDIA_SOURCE_URL) {
                     // import thumb and convert to our size
                     $thumbFullPath = $thumbTempPrefix . '1.jpg';
                     $entry_thumbNum = 1;
                     $importedThumbPath = $uploads . $entry_data_prefix . '_temp_thumb' . strrchr($entry_thumbUrl, '.');
                     if (kFile::downloadUrlToFile($entry_thumbUrl, $importedThumbPath)) {
                         myFileConverter::createImageThumbnail($importedThumbPath, $thumbFullPath, "image2");
                         // set thumb as big thumb so fileSync will be created.
                         $thumbBigFullPath = $thumbFullPath;
                     } else {
                         $need_thumb = false;
                     }
                 } else {
                     if ($entry_thumbNum == 0) {
                         $entry_thumbNum = 1;
                         $thumbTime = 3;
                         if ($duration && $duration < $thumbTime * 1000) {
                             $thumbTime = floor($duration / 1000);
                         }
                         // for videos - thumbail should be created in post convert
                         // otherwise this code will fail if the thumbanil wasn't created successfully (roman)
                         //myFileConverter::autoCaptureFrame($entry_fullPath, $thumbTempPrefix."big_", $thumbTime, -1, -1);
                         $need_thumb = false;
                         $thumbBigFullPath = $thumbTempPrefix . "big_" . $entry_thumbNum . '.jpg';
                     }
                 }
                 //else select existing thumb ($entry_thumbNum already points to the right thumbnail)
             }
         }
         $thumbFullPath = $thumbTempPrefix . $entry_thumbNum . '.jpg';
         // if we arrived here both entry and thumbnail are valid we can now update the db
         // in order to have the final entry_id and move its data to its final destination
         if ($onlyExtractThumb) {
             return $thumbFullPath;
         }
     }
     $entry->setkshowId($this->kshow_id);
     $entry->setKuserId($kuser_id);
     $entry->setCreatorKuserId($kuser_id);
     if ($this->partner_id != null) {
         $entry->setPartnerId($this->partner_id);
         $entry->setSubpId($this->subp_id);
     }
     $entry->setName($name ? $name : $this->getParam('entry_name'));
     //		$entry->setDescription('');//$this->getParam('entry_description'));
     $entry->setType($type);
     $entry->setMediaType($media_type);
     $entry->setTags($tags ? $tags : $this->getParam('entry_tags'));
     $entry->setSource($media_source);
     $entry->setSourceId($this->getParam('entry_media_id'));
     if ($media_date) {
         $entry->setMediaDate($media_date);
     }
     // if source_link wasnt given use the entry_url HOWEVER, use it only if id doesnt contain @ which suggests the use of a password
     $entry->setSourceLink($entry_source_link ? $entry_source_link : (strstr($entry_url, '@') ? "" : $entry_url));
     if ($media_source == entry::ENTRY_MEDIA_SOURCE_FILE) {
         $entry->setSourceLink("file:{$entry_fullPath}");
     }
     $entry->setLicenseType($this->getParam('entry_license'));
     $entry->setCredit($this->getParam('entry_credit'));
     $entry->setStatus($entry_status);
     if ($duration !== null) {
         $entry->setLengthInMsecs($duration);
     }
     if ($this->entry_id == 0) {
         $entry->save();
         $this->entry_id = $entry->getId();
     }
     // move thumb to final destination and set db entry
     if ($media_type != entry::ENTRY_MEDIA_TYPE_AUDIO && $entry_thumbNum && $need_thumb) {
         KalturaLog::debug("handleEntry: saving none audio thumb [{$thumbBigFullPath}]");
         $entry->setThumbnail('.jpg');
         if ($thumbBigFullPath) {
             if ($media_type != entry::ENTRY_MEDIA_TYPE_IMAGE) {
                 myFileConverter::convertImage($thumbBigFullPath, $thumbFullPath);
             }
             /*$thumbBigFinalPath = $content.$entry->getBigThumbnailPath();
             		myContentStorage::moveFile($thumbBigFullPath, $thumbBigFinalPath, true , $should_copy );
             		*/
             $entryThumbKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             try {
                 if (!$should_copy) {
                     kFileSyncUtils::moveFromFile($thumbBigFullPath, $entryThumbKey);
                 } else {
                     kFileSyncUtils::copyFromFile($thumbBigFullPath, $entryThumbKey);
                 }
             } catch (Exception $e) {
                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                 $entry->save();
                 throw $e;
             }
         }
     }
     // after extracting the thumb we can move the entry to its next destination
     KalturaLog::debug("handleEntry: current status [" . $entry->getStatus() . "]");
     // if needed a job will be submitted for importing external media sources
     if ($entry->getStatus() == entryStatus::IMPORT) {
         KalturaLog::debug("handleEntry: creating import job");
         // changed by Tan-Tan, Nov 09 to support the new batch mechanism
         kJobsManager::addImportJob(null, $this->entry_id, $this->partner_id, $entry_url);
         // remarked by Tan-Tan
         //			$entry_fullPath = $content.'/content/imports/data/'.$this->entry_id.".".$ext;
         //			myContentStorage::fullMkdir($entry_fullPath);
         //
         //			$batchClient = new myBatchUrlImportClient();
         // 			$batchClient->addJob($this->entry_id, $entry_url, $entry_fullPath);
     } else {
         if ($entry->getStatus() == entryStatus::PRECONVERT) {
             if (!$skip_conversion) {
                 // changed by Tan-Tan, Dec 09 to support the new batch mechanism
                 KalturaLog::debug("handleEntry: creating original flavor asset for pre convert");
                 $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                 if ($flavorAsset) {
                     $flavorAsset->setFileExt($ext);
                     $flavorAsset->save();
                     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     try {
                         kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                     } catch (Exception $e) {
                         $entry->setStatus(entryStatus::ERROR_CONVERTING);
                         $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                         $entry->save();
                         $flavorAsset->save();
                         throw $e;
                     }
                     kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                 } else {
                     $entry->setStatus(entryStatus::ERROR_CONVERTING);
                 }
                 //				Remarked by Tan-Tan
                 //				$targetFileName = $this->entry_id.".".$ext;
                 //				if ( false /* old conversion */)
                 //				{
                 //								// if we need to convert move entry to conversion directory
                 //								$preConvPath = $content.'/content/preconvert/';
                 //								myContentStorage::moveFile($entry_fullPath, $preConvPath."data/".$targetFileName, true , $should_copy );
                 //
                 //								$signalFilePath = $preConvPath."files/".$targetFileName;
                 //								myContentStorage::fullMkdir($signalFilePath);
                 //								touch($signalFilePath);
                 //				}
                 //				else
                 //				{
                 //								$preConvPath = myContentStorage::getFSContentRootPath (). "/content/new_preconvert";
                 //								$to_data = $preConvPath . "/$targetFileName" ;
                 //								myContentStorage::moveFile($entry_fullPath, $to_data , true);
                 //								touch ( $to_data . ".indicator" );
                 //				}
             }
         } else {
             if ($entry->getStatus() == entryStatus::PENDING || $media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
                 $entry->setData($entry_fullPath);
                 $entry->save();
                 if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_AUDIO) {
                     KalturaLog::debug("handleEntry: creating original flavor asset for ready entry");
                     $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                     if ($flavorAsset) {
                         $ext = pathinfo($entry_fullPath, PATHINFO_EXTENSION);
                         $flavorAsset->setFileExt($ext);
                         $flavorAsset->save();
                         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                         try {
                             if (!$should_copy) {
                                 kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                             } else {
                                 // copy & create file sync from $entry_fullPath
                                 kFileSyncUtils::copyFromFile($entry_fullPath, $syncKey);
                             }
                         } catch (Exception $e) {
                             $entry->setStatus(entryStatus::ERROR_CONVERTING);
                             $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                             $entry->save();
                             $flavorAsset->save();
                             throw $e;
                         }
                         //					// bypass to conversion
                         //					kBusinessPreConvertDL::bypassConversion($flavorAsset, $entry);
                         /**
                          * if this is webcam entry, create mediaInfo for the source flavor asset synchronously
                          * since entry is ready right at the beginning
                          */
                         if ($media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
                             require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "api_v3" . DIRECTORY_SEPARATOR . "bootstrap.php";
                             // extract file path
                             $sourceFileKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             $sourceFilePath = kFileSyncUtils::getLocalFilePathForKey($sourceFileKey);
                             // call mediaInfo for file
                             $mediaInfo = new mediaInfo();
                             try {
                                 $mediaInfoParser = new KMediaInfoMediaParser($sourceFilePath, kConf::get('bin_path_mediainfo'));
                                 $KalturaMediaInfo = new KalturaMediaInfo();
                                 $KalturaMediaInfo = $mediaInfoParser->getMediaInfo();
                                 $mediaInfo = $KalturaMediaInfo->toInsertableObject($mediaInfo);
                                 $mediaInfo->setFlavorAssetId($flavorAsset->getId());
                                 $mediaInfo->save();
                             } catch (Exception $e) {
                                 KalturaLog::err("Getting media info: " . $e->getMessage());
                                 $mediaInfo = null;
                             }
                             // fix flavor asset according to mediainfo
                             if ($mediaInfo) {
                                 KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfo, $flavorAsset);
                                 $flavorTags = KDLWrap::CDLMediaInfo2Tags($mediaInfo, array(flavorParams::TAG_WEB, flavorParams::TAG_MBR));
                                 $flavorAsset->setTags(implode(',', $flavorTags));
                             }
                             $flavorAsset->save();
                         }
                         kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                         $flavorAsset->setStatusLocalReady();
                         $flavorAsset->save();
                     } else {
                         $entry->setStatus(entryStatus::ERROR_IMPORTING);
                     }
                 } else {
                     if ($entry->getType() == entryType::DOCUMENT) {
                         //TODO: document should be handled by the plugin manager)
                         KalturaLog::debug("handleEntry: creating original flavor asset for ready entry");
                         $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                         if ($flavorAsset) {
                             $ext = pathinfo($entry_fullPath, PATHINFO_EXTENSION);
                             $flavorAsset->setFileExt($ext);
                             $flavorAsset->save();
                             $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             try {
                                 if (!$should_copy) {
                                     kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                                 } else {
                                     // copy & create file sync from $entry_fullPath
                                     kFileSyncUtils::copyFromFile($entry_fullPath, $syncKey);
                                 }
                             } catch (Exception $e) {
                                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                                 $entry->save();
                                 $flavorAsset->save();
                                 throw $e;
                             }
                             kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                         }
                     } else {
                         KalturaLog::debug("handleEntry: creating data file sync for file [{$entry_fullPath}]");
                         $entryDataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
                         if (!kFileSyncUtils::file_exists($entryDataKey)) {
                             try {
                                 if (!$should_copy) {
                                     kFileSyncUtils::moveFromFile($entry_fullPath, $entryDataKey);
                                 } else {
                                     // copy & create file sync from $entry_fullPath
                                     kFileSyncUtils::copyFromFile($entry_fullPath, $entryDataKey);
                                 }
                             } catch (Exception $e) {
                                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                                 $entry->save();
                                 throw $e;
                             }
                         }
                         $entry->setStatus(entryStatus::READY);
                         $entry->save();
                     }
                 }
                 //			Remarked by Tan-Tan, the flavor asset should be synced instead of the entry
                 //
                 //			$entryDataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
                 //			if(!$should_copy)
                 //			{
                 //				kFileSyncUtils::moveFromFile($entry_fullPath, $entryDataKey);
                 //			}
                 //			else
                 //			{
                 //				// copy & create file sync from $entry_fullPath
                 //				kFileSyncUtils::copyFromFile($entry_fullPath, $entryDataKey);
                 //			}
             }
         }
     }
     if ($entry->getStatus() == entryStatus::READY) {
         $entry->updateDimensions();
     }
     $entry->save();
     return true;
 }
 private function getBestSyncKeyForEntry(entry $entry)
 {
     $entryType = $entry->getType();
     $entryMediaType = $entry->getMediaType();
     $syncKey = null;
     switch ($entryType) {
         case entryType::MEDIA_CLIP:
             switch ($entryMediaType) {
                 case entry::ENTRY_MEDIA_TYPE_IMAGE:
                     $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
                     break;
             }
             break;
     }
     return $syncKey;
 }
Exemplo n.º 10
0
 public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false)
 {
     KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]");
     $newEntry = $entry->copy();
     $newEntry->setIntId(null);
     if ($toPartner instanceof Partner) {
         $newEntry->setPartnerId($toPartner->getId());
         $newEntry->setSubpId($toPartner->getId() * 100);
         $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId());
         $flavorParamsStr = $entry->getFlavorParamsIds();
         $flavorParams = explode(',', $flavorParamsStr);
         $newFlavorParams = array();
         foreach ($flavorParams as $flavorParamsId) {
             $newFlavorParamsId = kObjectCopyHandler::getMappedId('flavorParams', $flavorParamsId);
             if (is_null($newFlavorParamsId)) {
                 $newFlavorParamsId = $flavorParamsId;
             }
             $newFlavorParams[] = $newFlavorParamsId;
         }
         $newEntry->setFlavorParamsIds(implode(',', $newFlavorParams));
     }
     $newKuser = null;
     if (!$dontCopyUsers) {
         // copy the kuser (if the same puser id exists its kuser will be used)
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = $entry->getKuser();
         $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId());
         $newEntry->setKuserId($newKuser->getId());
         kuserPeer::setUseCriteriaFilter(true);
     }
     // copy the kshow
     kshowPeer::setUseCriteriaFilter(false);
     $kshow = $entry->getKshow();
     if ($kshow) {
         $newKshow = $kshow->copy();
         $newKshow->setIntId(null);
         $newKshow->setPartnerId($toPartner->getId());
         $newKshow->setSubpId($toPartner->getId() * 100);
         if ($newKuser) {
             $newKshow->setProducerId($newKuser->getId());
         }
         $newKshow->save();
         $newEntry->setKshowId($newKshow->getId());
     }
     kshowPeer::setUseCriteriaFilter(true);
     // reset the statistics
     myEntryUtils::resetEntryStatistics($newEntry);
     // set the new partner id into the default category criteria filter
     $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter();
     $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     // save the entry
     $newEntry->save();
     // restore the original partner id in the default category criteria filter
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId);
     KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created");
     // for any type that does not require assets:
     $shouldCopyDataForNonClip = $entry->getType() != entryType::MEDIA_CLIP;
     $shouldCopyDataForClip = false;
     // only images get their data copied
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $shouldCopyDataForClip = true;
         }
     }
     if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) {
         // copy the data
         $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]");
         kFileSyncUtils::softCopy($from, $to);
     }
     $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     if (kFileSyncUtils::fileSync_exists($ismFrom)) {
         $ismTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
         KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]");
         kFileSyncUtils::softCopy($ismFrom, $ismTo);
     }
     $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($ismcFrom)) {
         $ismcTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
         KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]");
         kFileSyncUtils::softCopy($ismcFrom, $ismcTo);
     }
     $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     // replaced__getThumbnailPath
     $considerCopyThumb = true;
     // if entry is image - data is thumbnail, and it was copied
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $considerCopyThumb = false;
     }
     // if entry is not clip, and there is no file in both DCs - nothing to copy
     if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) {
         $considerCopyThumb = false;
     }
     if ($considerCopyThumb) {
         $skipThumb = false;
         // don't attempt to copy a thumbnail for images - it's the same as the data which was just created
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             // check if audio entry has real thumb, if not - don't copy thumb.
             $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false);
             if (!$originalFileSync) {
                 $skipThumb = true;
             }
         }
         if (!$skipThumb) {
             $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             // replaced__getThumbnailPath
             KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]");
             kFileSyncUtils::softCopy($from, $to);
         }
     }
     // added by Tan-Tan 12/01/2010 to support falvors copy
     $sourceFlavorAssets = flavorAssetPeer::retrieveByEntryId($entry->getId());
     foreach ($sourceFlavorAssets as $sourceFlavorAsset) {
         $sourceFlavorAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId());
     }
 }
 private function markFileSyncAsReady(entry $entry)
 {
     // FileSync - mark file sync as ready for converted data file
     $fileSyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
     kFileSyncUtils::markLocalFileSyncAsReady($fileSyncKey);
     // FileSync - mark file sync as ready for converted data file in edit flavor
     $fileSyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT);
     kFileSyncUtils::markLocalFileSyncAsReady($fileSyncKey, $strict = false);
     // do not be strict, not all entries have EDIT file
 }
Exemplo n.º 12
0
 public static function copyEntryData(entry $entry, entry $targetEntry)
 {
     // for any type that does not require assets:
     $shouldCopyDataForNonClip = true;
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         $shouldCopyDataForNonClip = false;
     }
     if ($entry->getType() == entryType::PLAYLIST) {
         $shouldCopyDataForNonClip = false;
     }
     $shouldCopyDataForClip = false;
     // only images get their data copied
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $shouldCopyDataForClip = true;
         }
     }
     if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) {
         // copy the data
         $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         $to = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]");
         kFileSyncUtils::softCopy($from, $to);
     }
     $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     if (kFileSyncUtils::fileSync_exists($ismFrom)) {
         $ismTo = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
         KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]");
         kFileSyncUtils::softCopy($ismFrom, $ismTo);
     }
     $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($ismcFrom)) {
         $ismcTo = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
         KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]");
         kFileSyncUtils::softCopy($ismcFrom, $ismcTo);
     }
     $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     // replaced__getThumbnailPath
     $considerCopyThumb = true;
     // if entry is image - data is thumbnail, and it was copied
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $considerCopyThumb = false;
     }
     // if entry is not clip, and there is no file in both DCs - nothing to copy
     if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) {
         $considerCopyThumb = false;
     }
     if ($considerCopyThumb) {
         $skipThumb = false;
         // don't attempt to copy a thumbnail for images - it's the same as the data which was just created
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             // check if audio entry has real thumb, if not - don't copy thumb.
             $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false);
             if (!$originalFileSync) {
                 $skipThumb = true;
             }
         }
         if (!$skipThumb) {
             $to = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             // replaced__getThumbnailPath
             KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]");
             kFileSyncUtils::softCopy($from, $to);
         }
     }
     // added by Tan-Tan 12/01/2010 to support falvors copy
     $sourceAssets = assetPeer::retrieveByEntryId($entry->getId());
     foreach ($sourceAssets as $sourceAsset) {
         $sourceAsset->copyToEntry($targetEntry->getId(), $targetEntry->getPartnerId());
     }
 }
Exemplo n.º 13
0
 /**
  * @param IRemoteStorageResource $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return asset
  * @throws KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED
  * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND
  */
 protected function attachRemoteStorageResource(IRemoteStorageResource $resource, entry $dbEntry, asset $dbAsset = null)
 {
     $resources = $resource->getResources();
     $fileExt = $resource->getFileExt();
     $dbEntry->setSource(KalturaSourceType::URL);
     // TODO - move image handling to media service
     if ($dbEntry->getMediaType() == KalturaMediaType::IMAGE) {
         $syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         foreach ($resources as $currentResource) {
             $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId());
             $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile);
         }
         $dbEntry->setStatus(entryStatus::READY);
         $dbEntry->save();
         return null;
     }
     $dbEntry->save();
     $isNewAsset = false;
     if (!$dbAsset) {
         $isNewAsset = true;
         $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId());
     }
     if (!$dbAsset) {
         KalturaLog::err("Flavor asset not created for entry [" . $dbEntry->getId() . "]");
         if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) {
             $dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
             $dbEntry->save();
         }
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED);
     }
     $syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     foreach ($resources as $currentResource) {
         $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId());
         $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile);
     }
     $dbAsset->setFileExt($fileExt);
     if ($dbAsset instanceof flavorAsset && !$dbAsset->getIsOriginal()) {
         $dbAsset->setStatus(asset::FLAVOR_ASSET_STATUS_READY);
     }
     $dbAsset->save();
     if ($isNewAsset) {
         kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset));
     }
     kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset));
     if ($dbAsset instanceof flavorAsset && !$dbAsset->getIsOriginal()) {
         kBusinessPostConvertDL::handleConvertFinished(null, $dbAsset);
     }
     return $dbAsset;
 }
Exemplo n.º 14
0
 private static function addIsmLink(entry $entry, SimpleXMLElement $mrss)
 {
     if (self::$addedIsmUrl) {
         return;
     }
     self::$addedIsmUrl = true;
     $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     $kalturaFileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
     $urlManager = DeliveryProfilePeer::getDeliveryProfile($entry->getId(), PlaybackProtocol::SILVER_LIGHT);
     if (!$urlManager) {
         return;
     }
     $urlManager->initDeliveryDynamicAttributes($kalturaFileSync);
     $partner = $entry->getPartner();
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if ($kalturaFileSync) {
             $urlPrefix = $urlManager->getUrl();
             $url = $urlManager->getFileSyncUrl($kalturaFileSync, false);
             $mrss->addChild('ismUrl', $urlPrefix . $url);
             return;
         }
     }
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     $externalFileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
     if ($externalFileSync) {
         $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($externalFileSync->getDc(), $entry->getId(), PlaybackProtocol::SILVER_LIGHT));
         if (is_null($urlManager)) {
             return;
         }
         $url = $urlManager->getFileSyncUrl($externalFileSync, false);
         $urlPrefix = $urlManager->getUrl();
         $mrss->addChild('ismUrl', $urlPrefix . $url);
         return;
     }
     if ($partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) {
         if ($kalturaFileSync) {
             $url = $urlManager->getFileSyncUrl($kalturaFileSync, false);
             $mrss->addChild('ismUrl', $urlPrefix . $url);
             return;
         }
     }
 }
Exemplo n.º 15
0
 public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false)
 {
     KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]");
     $newEntry = $entry->copy();
     $newEntry->setIntId(null);
     $newEntry->setCategories(null);
     $newEntry->setCategoriesIds(null);
     if ($toPartner instanceof Partner) {
         $newEntry->setPartnerId($toPartner->getId());
         $newEntry->setSubpId($toPartner->getId() * 100);
         $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId());
     }
     $newKuser = null;
     if (!$dontCopyUsers) {
         // copy the kuser (if the same puser id exists its kuser will be used)
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = $entry->getKuser();
         $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId());
         $newEntry->setKuserId($newKuser->getId());
         $newEntry->setCreatorKuserId($newKuser->getId());
         kuserPeer::setUseCriteriaFilter(true);
     }
     // copy the kshow
     kshowPeer::setUseCriteriaFilter(false);
     $kshow = $entry->getKshow();
     if ($kshow) {
         $newKshow = $kshow->copy();
         $newKshow->setIntId(null);
         $newKshow->setPartnerId($toPartner->getId());
         $newKshow->setSubpId($toPartner->getId() * 100);
         if ($newKuser) {
             $newKshow->setProducerId($newKuser->getId());
         }
         $newKshow->save();
         $newEntry->setKshowId($newKshow->getId());
     }
     kshowPeer::setUseCriteriaFilter(true);
     // reset the statistics
     myEntryUtils::resetEntryStatistics($newEntry);
     // set the new partner id into the default category criteria filter
     $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter();
     $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     // save the entry
     $newEntry->save();
     // restore the original partner id in the default category criteria filter
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId);
     KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created");
     // for any type that does not require assets:
     $shouldCopyDataForNonClip = true;
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         $shouldCopyDataForNonClip = false;
     }
     if ($entry->getType() == entryType::PLAYLIST) {
         $shouldCopyDataForNonClip = false;
     }
     $shouldCopyDataForClip = false;
     // only images get their data copied
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $shouldCopyDataForClip = true;
         }
     }
     //if entry is a static playlist, link between it and its new child entries
     if ($entry->getType() == entryType::PLAYLIST) {
         switch ($entry->getMediaType()) {
             case entry::ENTRY_MEDIA_TYPE_TEXT:
                 $from = $entry->getDataContent();
                 KalturaLog::debug("Entries to copy from source static playlist: [{$from}]");
                 $fromEntryIds = explode(",", $from);
                 $toEntryIds = array();
                 foreach ($fromEntryIds as $fromEntryId) {
                     $toEntryIds[] = kObjectCopyHandler::getMappedId(entryPeer::OM_CLASS, $fromEntryId);
                 }
                 $newEntry->setDataContent(implode(",", $toEntryIds));
                 break;
             case entry::ENTRY_MEDIA_TYPE_XML:
                 list($totalResults, $fromFiltersList) = myPlaylistUtils::getPlaylistFilterListStruct($entry->getDataContent());
                 $toPlaylistXml = new SimpleXMLElement("<playlist/>");
                 $toPlaylistXml->addChild("total_results", $totalResults);
                 $toFiltersXml = $toPlaylistXml->addChild("filters");
                 foreach ($fromFiltersList as $filterXML) {
                     $entryFilter = new entryFilter();
                     $entryFilter->fillObjectFromXml($filterXML, "_");
                     if (isset($entryFilter->fields["_matchand_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchand_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchand_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_matchor_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchor_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchor_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_in_category_ancestor_id"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_in_category_ancestor_id"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_in_category_ancestor_id"] = implode(",", $newCategoriesIds);
                     }
                     $toEntryFilterXML = $toFiltersXml->addChild("filter");
                     $toEntryFilterXML = $entryFilter->toXml($toEntryFilterXML);
                 }
                 $newEntry->setDataContent($toPlaylistXml->asXML());
                 break;
         }
     }
     if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) {
         // copy the data
         $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]");
         kFileSyncUtils::softCopy($from, $to);
     }
     $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     if (kFileSyncUtils::fileSync_exists($ismFrom)) {
         $ismTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
         KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]");
         kFileSyncUtils::softCopy($ismFrom, $ismTo);
     }
     $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($ismcFrom)) {
         $ismcTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
         KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]");
         kFileSyncUtils::softCopy($ismcFrom, $ismcTo);
     }
     $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     // replaced__getThumbnailPath
     $considerCopyThumb = true;
     // if entry is image - data is thumbnail, and it was copied
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $considerCopyThumb = false;
     }
     // if entry is not clip, and there is no file in both DCs - nothing to copy
     if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) {
         $considerCopyThumb = false;
     }
     if ($considerCopyThumb) {
         $skipThumb = false;
         // don't attempt to copy a thumbnail for images - it's the same as the data which was just created
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             // check if audio entry has real thumb, if not - don't copy thumb.
             $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false);
             if (!$originalFileSync) {
                 $skipThumb = true;
             }
         }
         if (!$skipThumb) {
             $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             // replaced__getThumbnailPath
             KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]");
             kFileSyncUtils::softCopy($from, $to);
         }
     }
     // added by Tan-Tan 12/01/2010 to support falvors copy
     $sourceAssets = assetPeer::retrieveByEntryId($entry->getId());
     foreach ($sourceAssets as $sourceAsset) {
         $sourceAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId());
     }
     // copy relationships to categories
     KalturaLog::debug('Copy relationships to categories from entry [' . $entry->getId() . '] to entry [' . $newEntry->getId() . ']');
     $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS);
     $c->addAnd(categoryEntryPeer::ENTRY_ID, $entry->getId());
     $c->addAnd(categoryEntryPeer::STATUS, CategoryEntryStatus::ACTIVE, Criteria::EQUAL);
     $c->addAnd(categoryEntryPeer::PARTNER_ID, $entry->getPartnerId());
     categoryEntryPeer::setUseCriteriaFilter(false);
     $categoryEntries = categoryEntryPeer::doSelect($c);
     categoryEntryPeer::setUseCriteriaFilter(true);
     // Create srcCategoryIdToDstCategoryIdMap - a map of source partner category ids -> dst. partner category ids
     //
     // Build src category IDs set
     $srcCategoryIdSet = array();
     foreach ($categoryEntries as $categoryEntry) {
         $srcCategoryIdSet[] = $categoryEntry->getCategoryId();
     }
     $illegalCategoryStatus = array(CategoryStatus::DELETED, CategoryStatus::PURGED);
     // Get src category objects
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $srcCategoryIdSet, Criteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $entry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $srcCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     // Map the category names to their IDs
     $fullNamesToSrcCategoryIdMap = array();
     foreach ($srcCategories as $category) {
         $fullNamesToSrcCategoryIdMap[$category->getFullName()] = $category->getId();
     }
     // Get dst. partner categories based on src. category full-names
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::FULL_NAME, array_keys($fullNamesToSrcCategoryIdMap), KalturaCriteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $dstCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     $srcCategoryIdToDstCategoryIdMap = array();
     foreach ($dstCategories as $dstCategory) {
         $fullName = $dstCategory->getFullName();
         if (array_key_exists($fullName, $fullNamesToSrcCategoryIdMap)) {
             $srcCategoryId = $fullNamesToSrcCategoryIdMap[$fullName];
             $srcCategoryIdToDstCategoryIdMap[$srcCategoryId] = $dstCategory->getId();
         }
     }
     foreach ($categoryEntries as $categoryEntry) {
         /* @var $categoryEntry categoryEntry */
         $newCategoryEntry = $categoryEntry->copy();
         $newCategoryEntry->setPartnerId($newEntry->getPartnerId());
         $newCategoryEntry->setEntryId($newEntry->getId());
         $srcCategoryId = $categoryEntry->getCategoryId();
         if (!array_key_exists($srcCategoryId, $srcCategoryIdToDstCategoryIdMap)) {
             continue;
             // Skip the category_entry's creation
         }
         $dstCategoryId = $srcCategoryIdToDstCategoryIdMap[$srcCategoryId];
         $newCategoryEntry->setCategoryId($dstCategoryId);
         categoryPeer::setUseCriteriaFilter(false);
         entryPeer::setUseCriteriaFilter(false);
         $newCategoryEntry->save();
         entryPeer::setUseCriteriaFilter(true);
         categoryPeer::setUseCriteriaFilter(true);
     }
     return $newEntry;
 }
 /**
  * @param entry $entry
  * @param entry $tempEntry
  */
 public static function replaceEntry(entry $entry, entry $tempEntry = null)
 {
     KalturaLog::debug("in replaceEntry");
     if (!$tempEntry) {
         $tempEntry = entryPeer::retrieveByPK($entry->getReplacingEntryId());
     }
     if (!$tempEntry) {
         KalturaLog::err("Temp entry id [" . $entry->getReplacingEntryId() . "] not found");
         return;
     }
     //Extract all assets of the temp entry
     $tempAssets = assetPeer::retrieveByEntryId($tempEntry->getId());
     //Extract all assets of the existing entry
     $oldAssets = assetPeer::retrieveByEntryId($entry->getId());
     KalturaLog::debug("num of old assets: " . count($oldAssets));
     $newAssets = array();
     //Loop which creates a mapping between the new assets' paramsId and their type to the asset itself
     foreach ($tempAssets as $newAsset) {
         if ($newAsset->getStatus() != asset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::debug("Do not add new asset [" . $newAsset->getId() . "] to flavor [" . $newAsset->getFlavorParamsId() . "] status [" . $newAsset->getStatus() . "]");
             continue;
         }
         //If doesn't exist - create a new array for the current asset's type.
         if (!isset($newAssets[$newAsset->getType()])) {
             $newAssets[$newAsset->getType()] = array();
         }
         if ($newAsset->getFlavorParamsId() || $newAsset instanceof flavorAsset) {
             $newAssets[$newAsset->getType()][$newAsset->getFlavorParamsId()] = $newAsset;
             KalturaLog::debug("Added new asset [" . $newAsset->getId() . "] for asset params [" . $newAsset->getFlavorParamsId() . "]");
         } else {
             $newAssets[$newAsset->getType()]['asset_' . count($newAssets[$newAsset->getType()])] = $newAsset;
             KalturaLog::debug("Added new asset [" . $newAsset->getId() . "] with no asset params");
         }
     }
     $saveEntry = false;
     $defaultThumbAssetNew = null;
     foreach ($oldAssets as $oldAsset) {
         /* @var $oldAsset asset */
         kFileSyncUtils::clearWAMSDataForKey($oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET));
         //If the newAssets map contains an asset of the same type and paramsId as the current old asset,
         // re-link the old asset to the new asset.
         if (isset($newAssets[$oldAsset->getType()]) && isset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()])) {
             $newAsset = $newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()];
             /* @var $newAsset asset */
             KalturaLog::debug("Create link from new asset [" . $newAsset->getId() . "] to old asset [" . $oldAsset->getId() . "] for flavor [" . $oldAsset->getFlavorParamsId() . "]");
             if ($oldAsset instanceof flavorAsset) {
                 $oldAsset->setBitrate($newAsset->getBitrate());
                 $oldAsset->setFrameRate($newAsset->getFrameRate());
                 $oldAsset->setVideoCodecId($newAsset->getVideoCodecId());
             }
             $oldAsset->setWidth($newAsset->getWidth());
             $oldAsset->setHeight($newAsset->getHeight());
             $oldAsset->setContainerFormat($newAsset->getContainerFormat());
             $oldAsset->setSize($newAsset->getSize());
             $oldAsset->setFileExt($newAsset->getFileExt());
             $oldAsset->setTags($newAsset->getTags());
             $oldAsset->setDescription($newAsset->getDescription());
             $oldAsset->incrementVersion();
             $oldAsset->setStatusLocalReady();
             $oldAsset->save();
             $oldFileSync = $oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             $newFileSync = $newAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             kFileSyncUtils::createSyncFileLinkForKey($oldFileSync, $newFileSync);
             $newFlavorMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($newAsset->getId());
             if ($newFlavorMediaInfo) {
                 $oldFlavorNewMediaInfo = $newFlavorMediaInfo->copy();
                 $oldFlavorNewMediaInfo->setFlavorAssetId($oldAsset->getId());
                 $oldFlavorNewMediaInfo->setFlavorAssetVersion($oldAsset->getVersion());
                 $oldFlavorNewMediaInfo->save();
             }
             unset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]);
             if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                 $defaultThumbAssetNew = $oldAsset;
                 KalturaLog::debug("Nominating ThumbAsset [" . $oldAsset->getId() . "] as the default ThumbAsset after replacent");
             }
         } elseif ($oldAsset instanceof flavorAsset || $oldAsset instanceof thumbAsset) {
             KalturaLog::debug("Delete old asset [" . $oldAsset->getId() . "] for paramsId [" . $oldAsset->getFlavorParamsId() . "]");
             $oldAsset->setStatus(flavorAsset::ASSET_STATUS_DELETED);
             $oldAsset->setDeletedAt(time());
             $oldAsset->save();
             $entry->removeFlavorParamsId($oldAsset->getFlavorParamsId());
             $saveEntry = true;
         }
     }
     foreach ($newAssets as $newAssetsByTypes) {
         foreach ($newAssetsByTypes as $newAsset) {
             $createdAsset = $newAsset->copyToEntry($entry->getId(), $entry->getPartnerId());
             KalturaLog::debug("Copied from new asset [" . $newAsset->getId() . "] to copied asset [" . $createdAsset->getId() . "] for flavor [" . $newAsset->getFlavorParamsId() . "]");
             if ($createdAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                 $defaultThumbAssetNew = $newAsset;
                 KalturaLog::debug("Nominating ThumbAsset [" . $newAsset->getId() . "] as the default ThumbAsset after replacent");
             }
         }
     }
     if ($defaultThumbAssetNew) {
         kBusinessConvertDL::setAsDefaultThumbAsset($defaultThumbAssetNew);
         kalturalog::debug("Setting ThumbAsset [" . $defaultThumbAssetNew->getId() . "] as the default ThumbAsset");
     } else {
         kalturalog::debug("No default ThumbAsset found for replacing entry [" . $tempEntry->getId() . "]");
         $entry->setThumbnail(".jpg");
         // thumbnailversion++
         $entry->save();
         $tempEntrySyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $realEntrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         kFileSyncUtils::createSyncFileLinkForKey($realEntrySyncKey, $tempEntrySyncKey);
     }
     $entry->setDimensions($tempEntry->getWidth(), $tempEntry->getHeight());
     $entry->setLengthInMsecs($tempEntry->getLengthInMsecs());
     $entry->setConversionProfileId($tempEntry->getConversionProfileId());
     $entry->setConversionQuality($tempEntry->getConversionQuality());
     $entry->setReplacingEntryId(null);
     $entry->setReplacementStatus(entryReplacementStatus::NONE);
     $entry->setStatus($tempEntry->getStatus());
     $entry->save();
     myEntryUtils::deleteEntry($tempEntry, null, true);
     $te = new TrackEntry();
     $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_REPLACED_ENTRY);
     $te->setEntryId($entry->getId());
     $te->setParam1Str($tempEntry->getId());
     $te->setDescription(__METHOD__ . "[" . __LINE__ . "]");
     TrackEntry::addTrackEntry($te);
 }
 private static function addIsmLink(entry $entry, SimpleXMLElement $mrss)
 {
     if (self::$addedIsmUrl) {
         return;
     }
     self::$addedIsmUrl = true;
     $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     $kalturaFileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
     $urlPrefix = myPartnerUtils::getIisHost($entry->getPartnerId(), StorageProfile::PLAY_FORMAT_HTTP);
     $iisHost = parse_url($urlPrefix, PHP_URL_HOST);
     $matches = null;
     if (preg_match('/(https?:\\/\\/[^\\/]+)(.*)/', $urlPrefix, $matches)) {
         $urlPrefix = $matches[1];
     }
     $urlPrefix = rtrim($urlPrefix, '/') . '/';
     $urlManager = kUrlManager::getUrlManagerByCdn($iisHost, $entry->getId());
     if ($kalturaFileSync) {
         $urlManager->setFileExtension(pathinfo($kalturaFileSync->getFilePath(), PATHINFO_EXTENSION));
     }
     $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_SILVER_LIGHT);
     $partner = $entry->getPartner();
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if ($kalturaFileSync) {
             $url = $urlManager->getFileSyncUrl($kalturaFileSync, false);
             $mrss->addChild('ismUrl', $urlPrefix . $url);
             return;
         }
     }
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     $externalFileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
     if ($externalFileSync) {
         $urlManager = kUrlManager::getUrlManagerByStorageProfile($externalFileSync->getDc(), $entry->getId());
         $urlManager->setFileExtension(pathinfo($externalFileSync->getFilePath(), PATHINFO_EXTENSION));
         $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_SILVER_LIGHT);
         $url = $urlManager->getFileSyncUrl($externalFileSync, false);
         $url = ltrim($url, '/');
         if (strpos($url, "://") !== false) {
             $urlPrefix = '';
         }
         $mrss->addChild('ismUrl', $urlPrefix . $url);
         return;
     }
     if ($partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) {
         if ($kalturaFileSync) {
             $url = $urlManager->getFileSyncUrl($kalturaFileSync, false);
             $mrss->addChild('ismUrl', $urlPrefix . $url);
             return;
         }
     }
 }
Exemplo n.º 18
0
 /**
  * delete ISM, ISMC and Data files on the entry from remote storage
  * 
  * @param entry $entry
  * @param StorageProfile $profile
  */
 protected static function deleteAdditionalEntryFilesFromStorage(entry $entry, StorageProfile $profile)
 {
     $additionalFileSyncKeys = array(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM, entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     foreach ($additionalFileSyncKeys as $subType) {
         $key = $entry->getSyncKey($subType);
         if ($profile->isExported($key)) {
             self::delete($entry, $profile, $key);
         }
     }
 }
Exemplo n.º 19
0
 /**
  * decideThumbGenerate is the decision layer for a single thumbnail generation 
  * 
  * @param entry $entry
  * @param thumbParams $destThumbParams
  * @param BatchJob $parentJob
  * @return thumbAsset 
  */
 public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false)
 {
     $srcAsset = null;
     assetPeer::resetInstanceCriteriaFilter();
     if ($sourceAssetId) {
         $srcAsset = assetPeer::retrieveById($sourceAssetId);
     } else {
         if ($destThumbParams->getSourceParamsId()) {
             KalturaLog::debug("Look for flavor params [" . $destThumbParams->getSourceParamsId() . "]");
             $srcAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getSourceParamsId());
         }
         if (is_null($srcAsset)) {
             KalturaLog::debug("Look for original flavor");
             $srcAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId());
         }
         if (is_null($srcAsset) || $srcAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::debug("Look for highest bitrate flavor");
             $srcAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entry->getId());
         }
     }
     if (is_null($srcAsset)) {
         throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY);
     }
     $errDescription = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
     $destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription);
     $thumbAsset = thumbAssetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId());
     if ($thumbAsset) {
         $description = $thumbAsset->getDescription() . "\n" . $errDescription;
         $thumbAsset->setDescription($description);
     } else {
         $thumbAsset = new thumbAsset();
         $thumbAsset->setPartnerId($entry->getPartnerId());
         $thumbAsset->setEntryId($entry->getId());
         $thumbAsset->setDescription($errDescription);
         $thumbAsset->setFlavorParamsId($destThumbParams->getId());
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING);
     $thumbAsset->setTags($destThumbParamsOutput->getTags());
     $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt());
     if (!$destThumbParamsOutput) {
         $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
         $thumbAsset->save();
         return null;
     }
     $thumbAsset->save();
     // save flavor params
     $destThumbParamsOutput->setPartnerId($entry->getPartnerId());
     $destThumbParamsOutput->setEntryId($entry->getId());
     $destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId());
     $destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion());
     $destThumbParamsOutput->save();
     $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $srcAssetType = $srcAsset->getType();
     if (!$runSync) {
         $job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAssetType, $destThumbParamsOutput);
         return $thumbAsset;
     }
     $errDescription = null;
     $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription);
     // failed
     if (!$capturedPath) {
         $thumbAsset->incrementVersion();
         $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
         $thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}");
         $thumbAsset->save();
         return $thumbAsset;
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
     if (file_exists($capturedPath)) {
         list($width, $height, $type, $attr) = getimagesize($capturedPath);
         $thumbAsset->setWidth($width);
         $thumbAsset->setHeight($height);
         $thumbAsset->setSize(filesize($capturedPath));
     }
     $logPath = $capturedPath . '.log';
     if (file_exists($logPath)) {
         $thumbAsset->incLogFileVersion();
         $thumbAsset->save();
         // creats the file sync
         $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
         kFileSyncUtils::moveFromFile($logPath, $logSyncKey);
         KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey));
     } else {
         $thumbAsset->save();
     }
     $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($capturedPath, $syncKey);
     KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey));
     if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
         // increment thumbnail version
         $entry->setThumbnail(".jpg");
         $entry->save();
         $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey, false);
         if ($syncFile) {
             // removes the DEFAULT_THUMB tag from all other thumb assets
             $entryThumbAssets = thumbAssetPeer::retrieveByEntryId($thumbAsset->getEntryId());
             foreach ($entryThumbAssets as $entryThumbAsset) {
                 if ($entryThumbAsset->getId() == $thumbAsset->getId()) {
                     continue;
                 }
                 if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                     continue;
                 }
                 $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB));
                 $entryThumbAsset->save();
             }
         }
     }
     if (!is_null($thumbAsset->getFlavorParamsId())) {
         kFlowHelper::generateThumbnailsFromFlavor($thumbAsset->getEntryId(), null, $thumbAsset->getFlavorParamsId());
     }
     return $thumbAsset;
 }
Exemplo n.º 20
0
 /**
  * @param entry $entry
  * @param entry $tempEntry
  */
 public static function replaceEntry(entry $entry, entry $tempEntry = null)
 {
     if (!$tempEntry) {
         $tempEntry = entryPeer::retrieveByPK($entry->getReplacingEntryId());
     }
     if (!$tempEntry) {
         KalturaLog::err("Temp entry id [" . $entry->getReplacingEntryId() . "] not found");
         return;
     }
     //Extract all assets of the temp entry
     $tempAssets = assetPeer::retrieveByEntryId($tempEntry->getId());
     //Extract all assets of the existing entry
     $oldAssets = assetPeer::retrieveByEntryId($entry->getId());
     $newAssets = array();
     //Loop which creates a mapping between the new assets' paramsId and their type to the asset itself
     foreach ($tempAssets as $newAsset) {
         if ($newAsset->getStatus() != asset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::info("Do not add new asset [" . $newAsset->getId() . "] to flavor [" . $newAsset->getFlavorParamsId() . "] status [" . $newAsset->getStatus() . "]");
             continue;
         }
         //If doesn't exist - create a new array for the current asset's type.
         if (!isset($newAssets[$newAsset->getType()])) {
             $newAssets[$newAsset->getType()] = array();
         }
         if ($newAsset->getFlavorParamsId() || $newAsset instanceof flavorAsset) {
             $newAssets[$newAsset->getType()][$newAsset->getFlavorParamsId()] = $newAsset;
             KalturaLog::info("Added new asset [" . $newAsset->getId() . "] for asset params [" . $newAsset->getFlavorParamsId() . "]");
         } else {
             $newAssets[$newAsset->getType()]['asset_' . count($newAssets[$newAsset->getType()])] = $newAsset;
             KalturaLog::info("Added new asset [" . $newAsset->getId() . "] with no asset params");
         }
     }
     $defaultThumbAssetNew = null;
     $defaultThumbAssetOld = null;
     foreach ($oldAssets as $oldAsset) {
         /* @var $oldAsset asset */
         //If the newAssets map contains an asset of the same type and paramsId as the current old asset,
         // re-link the old asset to the new asset.
         if (isset($newAssets[$oldAsset->getType()]) && isset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()])) {
             $newAsset = $newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()];
             if ($oldAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) {
                 $newAsset->addTags(array(assetParams::TAG_RECORDING_ANCHOR));
             }
             /* @var $newAsset asset */
             KalturaLog::info("Create link from new asset [" . $newAsset->getId() . "] to old asset [" . $oldAsset->getId() . "] for flavor [" . $oldAsset->getFlavorParamsId() . "]");
             $oldAsset->linkFromAsset($newAsset);
             $oldAsset->save();
             self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_ISM);
             self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
             self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_MPD);
             $newFlavorMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($newAsset->getId());
             if ($newFlavorMediaInfo) {
                 $oldFlavorNewMediaInfo = $newFlavorMediaInfo->copy();
                 $oldFlavorNewMediaInfo->setFlavorAssetId($oldAsset->getId());
                 $oldFlavorNewMediaInfo->setFlavorAssetVersion($oldAsset->getVersion());
                 $oldFlavorNewMediaInfo->save();
             }
             unset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]);
             if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                 $defaultThumbAssetNew = $oldAsset;
                 KalturaLog::info("Nominating ThumbAsset [" . $oldAsset->getId() . "] as the default ThumbAsset after replacent");
             }
         } elseif ($oldAsset instanceof flavorAsset || $oldAsset instanceof thumbAsset) {
             if ($oldAsset instanceof thumbAsset && $oldAsset->keepOnEntryReplacement()) {
                 KalturaLog::info("KeepManualThumbnails ind is set, manual thumbnail is not deleted [" . $oldAsset->getId() . "]");
                 if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                     $defaultThumbAssetOld = $oldAsset;
                 }
             } else {
                 KalturaLog::info("Delete old asset [" . $oldAsset->getId() . "] for paramsId [" . $oldAsset->getFlavorParamsId() . "]");
                 $oldAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
                 $oldAsset->setDeletedAt(time());
                 $oldAsset->save();
             }
         }
     }
     foreach ($newAssets as $newAssetsByTypes) {
         foreach ($newAssetsByTypes as $newAsset) {
             $createdAsset = $newAsset->copyToEntry($entry->getId(), $entry->getPartnerId());
             KalturaLog::info("Copied from new asset [" . $newAsset->getId() . "] to copied asset [" . $createdAsset->getId() . "] for flavor [" . $newAsset->getFlavorParamsId() . "]");
             if ($createdAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                 $defaultThumbAssetNew = $newAsset;
                 KalturaLog::info("Nominating ThumbAsset [" . $newAsset->getId() . "] as the default ThumbAsset after replacent");
             }
         }
     }
     if ($defaultThumbAssetOld) {
         KalturaLog::info("Kepping ThumbAsset [" . $defaultThumbAssetOld->getId() . "] as the default ThumbAsset");
     } elseif ($defaultThumbAssetNew) {
         kBusinessConvertDL::setAsDefaultThumbAsset($defaultThumbAssetNew);
         KalturaLog::info("Setting ThumbAsset [" . $defaultThumbAssetNew->getId() . "] as the default ThumbAsset");
     } else {
         KalturaLog::info("No default ThumbAsset found for replacing entry [" . $tempEntry->getId() . "]");
         $entry->setThumbnail(".jpg");
         // thumbnailversion++
         $entry->save();
         $tempEntrySyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $realEntrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         kFileSyncUtils::createSyncFileLinkForKey($realEntrySyncKey, $tempEntrySyncKey);
     }
     self::createIsmManifestFileSyncLinkFromReplacingEntry($tempEntry, $entry);
     $entry->setDimensions($tempEntry->getWidth(), $tempEntry->getHeight());
     $entry->setLengthInMsecs($tempEntry->getLengthInMsecs());
     $entry->setConversionProfileId($tempEntry->getConversionProfileId());
     $entry->setConversionQuality($tempEntry->getConversionQuality());
     $entry->setReplacingEntryId(null);
     $entry->setReplacementStatus(entryReplacementStatus::NONE);
     $entry->setReplacementOptions(null);
     $entry->setStatus($tempEntry->getStatus());
     $entry->save();
     //flush deffered events to re-index sphinx before temp entry deletion
     kEventsManager::flushEvents();
     kBusinessConvertDL::checkForPendingLiveClips($entry);
     kEventsManager::raiseEvent(new kObjectReplacedEvent($entry, $tempEntry));
     myEntryUtils::deleteEntry($tempEntry, null, true);
     $te = new TrackEntry();
     $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_REPLACED_ENTRY);
     $te->setEntryId($entry->getId());
     $te->setParam1Str($tempEntry->getId());
     $te->setDescription(__METHOD__ . "[" . __LINE__ . "]");
     TrackEntry::addTrackEntry($te);
 }