public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaUverseDistributionProfile) {
         return;
     }
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         // if we have specific flavor assets for this distribution, grab the first one
         $flavorAsset = reset($flavorAssets);
     } else {
         // take the source asset
         $flavorAsset = assetPeer::retrieveOriginalReadyByEntryId($distributionJobData->entryDistribution->entryId);
     }
     if ($flavorAsset) {
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $this->localAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         }
     }
     $entryDistributionDb = EntryDistributionPeer::retrieveByPK($distributionJobData->entryDistributionId);
     if ($entryDistributionDb) {
         $this->remoteAssetUrl = $entryDistributionDb->getFromCustomData(UverseEntryDistributionCustomDataField::REMOTE_ASSET_URL);
         $this->remoteAssetFileName = $entryDistributionDb->getFromCustomData(UverseEntryDistributionCustomDataField::REMOTE_ASSET_FILE_NAME);
     } else {
         KalturaLog::err('Entry distribution [' . $distributionJobData->entryDistributionId . '] not found');
     }
 }
 /**
  * Called on the server side and enables you to populate the object with any data from the DB
  * 
  * @param KalturaDistributionJobData $distributionJobData
  */
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaQuickPlayDistributionProfile) {
         return;
     }
     $this->videoFilePaths = new KalturaStringArray();
     $this->thumbnailFilePaths = new KalturaStringArray();
     // loads all the flavor assets that should be submitted to the remote destination site
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     $entry = entryPeer::retrieveByPK($distributionJobData->entryDistribution->entryId);
     foreach ($flavorAssets as $asset) {
         $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $str = new KalturaString();
             $str->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
             $this->videoFilePaths[] = $str;
         }
     }
     foreach ($thumbAssets as $asset) {
         $syncKey = $asset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $str = new KalturaString();
             $str->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
             $this->thumbnailFilePaths[] = $str;
         }
     }
     $feed = new QuickPlayFeed($distributionJobData, $this, $flavorAssets, $thumbAssets, $entry);
     $this->xml = $feed->getXml();
 }
 /**
  * Called on the server side and enables you to populate the object with any data from the DB
  * 
  * @param KalturaDistributionJobData $distributionJobData
  */
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaHuluDistributionProfile) {
         return;
     }
     // loads all the flavor assets that should be submitted to the remote destination site
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         $flavorAsset = reset($flavorAssets);
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
     }
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets)) {
         $thumbAsset = reset($thumbAssets);
         $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
     }
     $additionalAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->assetIds));
     $this->captionLocalPaths = new KalturaStringArray();
     if (count($additionalAssets)) {
         $captionAssetFilePathArray = array();
         foreach ($additionalAssets as $additionalAsset) {
             $assetType = $additionalAsset->getType();
             $syncKey = $additionalAsset->getSyncKey(CaptionAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
             if (kFileSyncUtils::fileSync_exists($syncKey)) {
                 if ($assetType == CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION) || $assetType == AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT)) {
                     $string = new KalturaString();
                     $string->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                     $this->captionLocalPaths[] = $string;
                 }
             }
         }
     }
     $tempFieldValues = unserialize($this->fieldValues);
     $pattern = '/[^A-Za-z0-9_\\-]/';
     $seriesTitle = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::SERIES_TITLE]);
     $seasonNumber = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::SEASON_NUMBER]);
     $videoEpisodeNumber = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::VIDEO_EPISODE_NUMBER]);
     $videoTitle = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::VIDEO_TITLE]);
     $this->fileBaseName = $seriesTitle . '-' . $seasonNumber . '-' . $videoEpisodeNumber . '-' . $videoTitle;
     // entry cue points
     $c = KalturaCriteria::create(CuePointPeer::OM_CLASS);
     $c->add(CuePointPeer::PARTNER_ID, $distributionJobData->entryDistribution->partnerId);
     $c->add(CuePointPeer::ENTRY_ID, $distributionJobData->entryDistribution->entryId);
     $c->add(CuePointPeer::TYPE, AdCuePointPlugin::getCuePointTypeCoreValue(AdCuePointType::AD));
     $c->addAscendingOrderByColumn(CuePointPeer::START_TIME);
     $cuePointsDb = CuePointPeer::doSelect($c);
     $this->cuePoints = KalturaCuePointArray::fromDbArray($cuePointsDb);
 }
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaYahooDistributionProfile) {
         return;
     }
     //Flavor Assets
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         $videoAssetFilePathArray = array();
         foreach ($flavorAssets as $flavorAsset) {
             if ($flavorAsset) {
                 /* @var $flavorAsset flavorAsset */
                 $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
                 if (kFileSyncUtils::fileSync_exists($syncKey)) {
                     $id = $flavorAsset->getId();
                     //$this->videoAssetFilePath[$id] = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                     $videoAssetFilePathArray[$id] = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                 }
             }
         }
         $this->videoAssetFilePath = serialize($videoAssetFilePathArray);
     }
     //Thumbnails
     $c = new Criteria();
     $c->addAnd(assetPeer::ID, explode(',', $distributionJobData->entryDistribution->thumbAssetIds), Criteria::IN);
     $c->addAscendingOrderByColumn(assetPeer::ID);
     $thumbAssets = assetPeer::doSelect($c);
     //$thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets) >= 2) {
         if ($thumbAssets[0]->getWidth() <= $thumbAssets[1]->getWidth()) {
             $smallThumbAsset = $thumbAssets[0];
             $largeThumbAsset = $thumbAssets[1];
         } else {
             $smallThumbAsset = $thumbAssets[1];
             $largeThumbAsset = $thumbAssets[0];
         }
         $syncKey = $smallThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $this->smallThumbPath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         }
         $syncKey = $largeThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $this->largeThumbPath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         }
     }
 }
 /**
  * @param uiConf $fromObject
  * @param uiConf $toObject
  */
 protected function uiConfCopied(uiConf $fromObject, uiConf $toObject)
 {
     $fileAssets = FileAssetPeer::retrieveByObject(FileAssetObjectType::UI_CONF, $fromObject->getId());
     foreach ($fileAssets as $fileAsset) {
         /* @var $fileAsset FileAsset */
         $newFileAssets = $fileAsset->copy();
         $newFileAssets->setObjectId($toObject->getId());
         $newFileAssets->incrementVersion();
         $newFileAssets->save();
         $syncKey = $fileAsset->getSyncKey(FileAsset::FILE_SYNC_ASSET);
         $newSyncKey = $newFileAssets->getSyncKey(FileAsset::FILE_SYNC_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             kFileSyncUtils::softCopy($syncKey, $newSyncKey);
         }
     }
 }
 /**
  * Serves thumbnail by its id
  *  
  * @action serve
  * @serverOnly
  * @param string $thumbAssetId
  *  
  * @throws KalturaErrors::THUMB_ASSET_IS_NOT_READY
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  */
 public function serveAction($thumbAssetId)
 {
     $thumbAsset = thumbAssetPeer::retrieveById($thumbAssetId);
     if (!$thumbAsset) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     $ext = $thumbAsset->getFileExt();
     if (is_null($ext)) {
         $ext = 'jpg';
     }
     $fileName = $thumbAsset->getEntryId() . "_" . $thumbAsset->getId() . ".{$ext}";
     $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_IS_NOT_READY, $thumbAsset);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     return $this->serveThumbToFile($fileSync, $local, $fileName);
 }
 /**
  * @param Partner $fromPartner
  * @param Partner $toPartner
  */
 protected function copyEventNotificationTemplates(Partner $fromPartner, Partner $toPartner, $permissionRequiredOnly = false)
 {
     $fromPartnerId = $fromPartner->getId();
     $toPartnerId = $toPartner->getId();
     KalturaLog::debug("Copy event-notification templates from [{$fromPartnerId}] to [{$toPartnerId}]");
     $c = new Criteria();
     $c->add(EventNotificationTemplatePeer::PARTNER_ID, $fromPartnerId);
     $systemNameCriteria = new Criteria();
     $systemNameCriteria->add(EventNotificationTemplatePeer::PARTNER_ID, $toPartnerId);
     $systemNameCriteria->add(EventNotificationTemplatePeer::STATUS, EventNotificationTemplateStatus::ACTIVE);
     $eventNotificationTemplates = EventNotificationTemplatePeer::doSelect($c);
     foreach ($eventNotificationTemplates as $eventNotificationTemplate) {
         /* @var $eventNotificationTemplate EventNotificationTemplate */
         if ($permissionRequiredOnly && !count($eventNotificationTemplate->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if (!myPartnerUtils::isPartnerPermittedForCopy($toPartner, $eventNotificationTemplate->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if ($eventNotificationTemplate->getSystemName()) {
             $c = clone $systemNameCriteria;
             $c->add(EventNotificationTemplatePeer::SYSTEM_NAME, $eventNotificationTemplate->getSystemName());
             if (EventNotificationTemplatePeer::doCount($c)) {
                 continue;
             }
         }
         $newEventNotificationTemplate = $eventNotificationTemplate->copy();
         $newEventNotificationTemplate->setPartnerId($toPartnerId);
         $newEventNotificationTemplate->save();
         if ($eventNotificationTemplate instanceof ISyncableFile) {
             $key = $eventNotificationTemplate->getSyncKey(1);
             if (kFileSyncUtils::fileSync_exists($key)) {
                 kFileSyncUtils::createSyncFileLinkForKey($newEventNotificationTemplate->getSyncKey(1), $key);
             }
         }
     }
 }
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaMetroPcsDistributionProfile) {
         return;
     }
     $distributedFlavorIds = null;
     $distributedThumbIds = null;
     //Flavor Assets
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         $videoAssetFilePathArray = array();
         foreach ($flavorAssets as $flavorAsset) {
             if ($flavorAsset) {
                 /* @var $flavorAsset flavorAsset */
                 $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
                 if (kFileSyncUtils::fileSync_exists($syncKey)) {
                     $id = $flavorAsset->getId();
                     $videoAssetFilePathArray[$id] = kFileSyncUtils::getLocalFilePathForKey($syncKey, true);
                 }
             }
         }
         $this->assetLocalPaths = serialize($videoAssetFilePathArray);
     }
     //thumbnails
     $thumbnails = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbnails)) {
         $thumbUrlsArray = array();
         foreach ($thumbnails as $thumb) {
             $thumbUrlsArray[$thumb->getId()] = self::getAssetUrl($thumb);
         }
         $this->thumbUrls = serialize($thumbUrlsArray);
     }
 }
 /**
  * @param ISyncableFile $syncable
  * @param int $fileSubType
  * @param string $fileName
  * @param bool $forceProxy
  * @throws KalturaErrors::FILE_DOESNT_EXIST
  */
 protected function serveFile(ISyncableFile $syncable, $fileSubType, $fileName, $entryId = null, $forceProxy = false)
 {
     /* @var $fileSync FileSync */
     $syncKey = $syncable->getSyncKey($fileSubType);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $wamsAssetId = $fileSync->getWamsAssetId();
         if (empty($wamsAssetId)) {
             $mimeType = kFile::mimeType($filePath);
             kFile::dumpFile($filePath, $mimeType);
         } else {
             kWAMS::getInstance($fileSync->getPartnerId())->dumpFile($wamsAssetId, pathinfo($filePath, PATHINFO_EXTENSION));
         }
     } else {
         if (in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) {
             $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
             KalturaLog::info("Redirecting to [{$remoteUrl}]");
             if ($forceProxy) {
                 kFile::dumpApiRequest($remoteUrl);
             } else {
                 //TODO find or build function which redurects the API request with all its parameters without using curl.
                 // or redirect if no proxy
                 header("Location: {$remoteUrl}");
                 die;
             }
         } else {
             $remoteUrl = $fileSync->getExternalUrl($entryId);
             header("Location: {$remoteUrl}");
             die;
         }
     }
 }
Exemple #10
0
 private static function createIsmManifestFileSyncLinkFromReplacingEntry($tempEntry, $realEntry)
 {
     $tempEntryIsmSyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     $tempEntryIsmcSyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($tempEntryIsmSyncKey) && kFileSyncUtils::fileSync_exists($tempEntryIsmcSyncKey)) {
         $ismVersion = $realEntry->incrementIsmVersion();
         $realEntryIsmSyncKey = $realEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM, $ismVersion);
         kFileSyncUtils::createSyncFileLinkForKey($realEntryIsmSyncKey, $tempEntryIsmSyncKey);
         $realEntryIsmcSyncKey = $realEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC, $ismVersion);
         kFileSyncUtils::createSyncFileLinkForKey($realEntryIsmcSyncKey, $tempEntryIsmcSyncKey);
     }
 }
 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());
     }
 }
Exemple #12
0
 public function objectAdded(BaseObject $object, BatchJob $raisedJob = null)
 {
     $entry = $object->getentry();
     if ($object->getStatus() == asset::FLAVOR_ASSET_STATUS_QUEUED || $object->getStatus() == asset::FLAVOR_ASSET_STATUS_IMPORTING) {
         if (!$object instanceof flavorAsset) {
             $object->setStatus(asset::FLAVOR_ASSET_STATUS_READY);
             $object->save();
         } elseif ($object->getIsOriginal()) {
             if ($entry->getType() == entryType::MEDIA_CLIP) {
                 $syncKey = $object->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                 if (kFileSyncUtils::fileSync_exists($syncKey)) {
                     // Get the asset fileSync.
                     // For URL typed sync - assume remote and use the relative file path.
                     // For the other types - use the ordinary kFileSyncUtils::getLocalFilePathForKey.
                     $fsArr = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
                     $fs = $fsArr[0];
                     if ($fs->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) {
                         $path = $fs->getFilePath();
                     } else {
                         $path = kFileSyncUtils::getLocalFilePathForKey($syncKey);
                     }
                     kJobsManager::addConvertProfileJob($raisedJob, $entry, $object->getId(), $path);
                 }
             }
         } else {
             $object->setStatus(asset::FLAVOR_ASSET_STATUS_VALIDATING);
             $object->save();
         }
     }
     if ($object->getStatus() == asset::FLAVOR_ASSET_STATUS_READY && $object instanceof thumbAsset) {
         if ($object->getFlavorParamsId()) {
             kFlowHelper::generateThumbnailsFromFlavor($object->getEntryId(), $raisedJob, $object->getFlavorParamsId());
         } else {
             if ($object->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                 kBusinessConvertDL::setAsDefaultThumbAsset($object);
             }
         }
         return true;
     }
     if ($object->getIsOriginal() && $entry->getStatus() == entryStatus::NO_CONTENT) {
         $entry->setStatus(entryStatus::PENDING);
         $entry->save();
     }
     return true;
 }
 if (in_array($entry->getId(), $processedIds)) {
     continue;
 }
 $processedIds[] = $entry->getId();
 $lastCreatedAt = $entry->getCreatedAt(null);
 $keys = array();
 $keys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
 $keys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
 $flavors = assetPeer::retrieveReadyFlavorsByEntryId($entry->getId());
 foreach ($flavors as $flavor) {
     if (!$flavorParamsArr || in_array($flavor->getFlavorParamsId(), $flavorParamsArr)) {
         $keys[] = $flavor->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     }
 }
 foreach ($keys as $index => $key) {
     if (!kFileSyncUtils::fileSync_exists($key)) {
         unset($keys[$index]);
         continue;
     }
     if (kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageProfileId)) {
         unset($keys[$index]);
     }
     if (!kFileSyncUtils::getReadyInternalFileSyncForKey($key)) {
         echo 'file sync key does not have an internal file -' . serialize($key) . PHP_EOL;
         unset($keys[$index]);
     }
 }
 if (!count($keys)) {
     echo $entry->getId() . " - has no keys to export\n";
     continue;
 }
 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());
     }
 }
Exemple #15
0
 public function copyToEntry($entryId = null, $partnerId = null)
 {
     $newFlavorAsset = $this->copy();
     //this is the first version of the new asset.
     $newFlavorAsset->incrementVersion();
     if ($partnerId) {
         $newFlavorAsset->setPartnerId($partnerId);
     }
     if ($entryId) {
         $newFlavorAsset->setEntryId($entryId);
     }
     $newFlavorAsset->save();
     $flavorParamsOutput = assetParamsOutputPeer::retrieveByAssetId($this->getId());
     if ($flavorParamsOutput) {
         $newFlavorParamsOutput = $flavorParamsOutput->copy();
         $newFlavorParamsOutput->setPartnerId($newFlavorAsset->getPartnerId());
         $newFlavorParamsOutput->setEntryId($newFlavorAsset->getEntryId());
         $newFlavorParamsOutput->setFlavorAssetId($newFlavorAsset->getId());
         $newFlavorParamsOutput->save();
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($this->getId());
     if ($mediaInfo) {
         $newMediaInfo = $mediaInfo->copy();
         $newMediaInfo->setFlavorAssetId($newFlavorAsset->getId());
         $newMediaInfo->setFlavorAssetVersion($newFlavorAsset->getVersion());
         $newMediaInfo->save();
     }
     $assetSyncKey = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $convertLogSyncKey = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     $ismSyncKey = $this->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISM);
     $ismcSyncKey = $this->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
     $newAssetSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $newConvertLogSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     $newIsmSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISM);
     $newIsmcSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($assetSyncKey)) {
         kFileSyncUtils::softCopy($assetSyncKey, $newAssetSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($convertLogSyncKey)) {
         kFileSyncUtils::softCopy($convertLogSyncKey, $newConvertLogSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($ismSyncKey)) {
         kFileSyncUtils::softCopy($ismSyncKey, $newIsmSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($ismcSyncKey)) {
         kFileSyncUtils::softCopy($ismcSyncKey, $newIsmcSyncKey);
     }
     kEventsManager::raiseEvent(new kObjectAddedEvent($newFlavorAsset));
     return $newFlavorAsset;
 }
Exemple #16
0
 public function setFlavorAsset(DOMElement $item, array $flavorAssets, $flavorLang)
 {
     $flavorAsset = $flavorAssets[0];
     /* @var $flavorAsset flavorAsset */
     $url = $this->getAssetUrl($flavorAsset);
     kXml::setNodeValue($this->xpath, 'media:content/@url', $url, $item);
     kXml::setNodeValue($this->xpath, 'media:content/@width', $flavorAsset->getWidth(), $item);
     kXml::setNodeValue($this->xpath, 'media:content/@height', $flavorAsset->getHeight(), $item);
     //setting mime type
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (kFileSyncUtils::fileSync_exists($syncKey)) {
         $filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         $mimeType = kFile::mimeType($filePath);
     }
     kXml::setNodeValue($this->xpath, 'media:content/@type', $mimeType, $item);
     if (!empty($flavorLang)) {
         kXml::setNodeValue($this->xpath, 'media:content/@lang', $flavorLang, $item);
     }
 }
Exemple #17
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kPostConvertJobData $data
  * @return BatchJob|BatchJob
  */
 public static function handlePostConvertFinished(BatchJob $dbBatchJob, kPostConvertJobData $data)
 {
     if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) {
         return $dbBatchJob;
     }
     if ($data->getCreateThumb()) {
         try {
             self::createThumbnail($dbBatchJob, $data);
         } catch (Exception $e) {
             KalturaLog::err($e->getMessage());
             // sometimes, because of disc IO load, it takes long time for the thumb to be moved.
             // in such cases, the entry thumb version may be increased by other process.
             // retry the job, it solves the issue.
             kJobsManager::retryJob($dbBatchJob->getId(), $dbBatchJob->getJobType(), true);
             $dbBatchJob->reload();
             return $dbBatchJob;
         }
     }
     $currentFlavorAsset = kBusinessPostConvertDL::handleFlavorReady($dbBatchJob, $data->getFlavorAssetId());
     if ($data->getPostConvertAssetType() == BatchJob::POSTCONVERT_ASSET_TYPE_SOURCE) {
         $convertProfileJob = $dbBatchJob->getRootJob();
         if ($convertProfileJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
             try {
                 $currFlavorAsset = assetPeer::retrieveById($data->getFlavorAssetId());
                 //In cases we are returning from intermediate flow need to check maybe if another round is needed
                 //This comes to support the creation of silent audio tracks on source assets such as .arf that require initial inter flow for the source and only than the addition
                 //of the silent audio track
                 if ($currFlavorAsset instanceof flavorAsset && $currFlavorAsset->getIsOriginal() && $currFlavorAsset->getInterFlowCount() != null) {
                     //check if the inter flow count is larger than 2.
                     //In this cases probably something went wrong so we will continue with the original flow and will not check if any additioanl inter flow nneds to be done.
                     if ($currentFlavorAsset && $currFlavorAsset->getInterFlowCount() < self::MAX_INTER_FLOW_ITERATIONS_ALLOWED_ON_SOURCE) {
                         $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
                         kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $convertProfileJob, $mediaInfo->getId());
                     } else {
                         kBusinessPreConvertDL::continueProfileConvert($dbBatchJob);
                     }
                 } else {
                     kBusinessPreConvertDL::continueProfileConvert($dbBatchJob);
                 }
             } catch (Exception $e) {
                 KalturaLog::err($e->getMessage());
                 kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING);
                 return $dbBatchJob;
             }
         } elseif ($currentFlavorAsset) {
             KalturaLog::log("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
             $syncKey = $currentFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             if (kFileSyncUtils::fileSync_exists($syncKey)) {
                 $path = kFileSyncUtils::getLocalFilePathForKey($syncKey);
                 $entry = $dbBatchJob->getEntry();
                 if ($entry) {
                     kJobsManager::addConvertProfileJob(null, $entry, $currentFlavorAsset->getId(), $path);
                 }
             }
             $currentFlavorAsset = null;
         }
     }
     if ($currentFlavorAsset) {
         kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset);
     }
     return $dbBatchJob;
 }
 private function validateVideo(flavorAsset $flavorAsset)
 {
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (kFileSyncUtils::fileSync_exists($syncKey)) {
         $videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
         if (!$mediaInfo) {
             return false;
         }
         try {
             FacebookGraphSdkUtils::validateVideoAttributes($videoAssetFilePath, $mediaInfo->getFileSize(), $mediaInfo->getVideoDuration());
             return true;
         } catch (Exception $e) {
             KalturaLog::debug('Asset [' . $flavorAsset->getId() . '] not valid for distribution: ' . $e->getMessage());
         }
     }
     return false;
 }
 /**
  * @param ISyncableFile $syncable
  * @param int $fileSubType
  * @param string $fileName
  * @param bool $forceProxy
  * @throws KalturaErrors::FILE_DOESNT_EXIST
  */
 protected function serveFile(ISyncableFile $syncable, $fileSubType, $fileName, $entryId = null, $forceProxy = false)
 {
     /* @var $fileSync FileSync */
     $syncKey = $syncable->getSyncKey($fileSubType);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $mimeType = kFile::mimeType($filePath);
         return $this->dumpFile($filePath, $mimeType);
     } else {
         if (in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) {
             $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
             KalturaLog::info("Redirecting to [{$remoteUrl}]");
             if ($forceProxy) {
                 kFileUtils::dumpApiRequest($remoteUrl);
             } else {
                 //TODO find or build function which redurects the API request with all its parameters without using curl.
                 // or redirect if no proxy
                 header("Location: {$remoteUrl}");
                 die;
             }
         } else {
             $remoteUrl = $fileSync->getExternalUrl($entryId);
             header("Location: {$remoteUrl}");
             die;
         }
     }
 }
 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;
 }
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaAttUverseDistributionProfile) {
         return;
     }
     /* @var $distributionProfileDb AttUverseDistributionProfile */
     $distributionProfileDb = DistributionProfilePeer::retrieveByPK($distributionJobData->distributionProfileId);
     $distributedFlavorIds = null;
     $distributedThumbIds = null;
     $this->filesForDistribution = new KalturaAttUverseDistributionFileArray();
     $entryDistributionDb = EntryDistributionPeer::retrieveByPK($distributionJobData->entryDistributionId);
     //Flavor Assets
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         $assetLocalIds = array();
         foreach ($flavorAssets as $flavorAsset) {
             $file = new KalturaAttUverseDistributionFile();
             $file->assetType = KalturaAssetType::FLAVOR;
             /* @var $flavorAsset flavorAsset */
             $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
             if (kFileSyncUtils::fileSync_exists($syncKey)) {
                 $assetLocalIds[] = $flavorAsset->getId();
                 $file->assetId = $flavorAsset->getId();
                 $file->localFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                 $defaultFilename = pathinfo($file->localFilePath, PATHINFO_BASENAME);
                 $file->remoteFilename = $distributionProfileDb->getFlavorAssetFilename($entryDistributionDb, $defaultFilename, $flavorAsset->getId());
                 $this->filesForDistribution[] = $file;
             }
         }
         $distributedFlavorIds = implode(',', $assetLocalIds);
     }
     //Thumbnail
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets)) {
         $thumbLocalIds = array();
         foreach ($thumbAssets as $thumbAsset) {
             $file = new KalturaAttUverseDistributionFile();
             $file->assetType = KalturaAssetType::THUMBNAIL;
             $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
             if (kFileSyncUtils::fileSync_exists($syncKey)) {
                 $thumbLocalIds[] = $thumbAsset->getId();
                 $file->assetId = $thumbAsset->getId();
                 $file->localFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                 $defaultFilename = pathinfo($file->localFilePath, PATHINFO_BASENAME);
                 $file->remoteFilename = $distributionProfileDb->getThumbnailAssetFilename($entryDistributionDb, $defaultFilename, $thumbAsset->getId());
                 $this->filesForDistribution[] = $file;
             }
         }
         $distributedThumbIds = implode(',', $thumbLocalIds);
     }
     //additional assets
     $additionalAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->assetIds));
     if (count($additionalAssets)) {
         $captionLocalIds = array();
         foreach ($additionalAssets as $additionalAsset) {
             $file = new KalturaAttUverseDistributionFile();
             $file->assetType = kPluginableEnumsManager::coreToApi(KalturaAssetType::getEnumClass(), $additionalAsset->getType());
             $syncKey = $additionalAsset->getSyncKey(CaptionAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
             $id = $additionalAsset->getId();
             if (kFileSyncUtils::fileSync_exists($syncKey)) {
                 if ($file->assetType == CaptionPlugin::getApiValue(CaptionAssetType::CAPTION) || $file->assetType == AttachmentPlugin::getApiValue(AttachmentAssetType::ATTACHMENT)) {
                     $captionLocalIds[] = $additionalAsset->getId();
                     $file->assetId = $additionalAsset->getId();
                     $file->localFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                     $defaultFilename = pathinfo($file->localFilePath, PATHINFO_BASENAME);
                     $file->remoteFilename = $distributionProfileDb->getAssetFilename($entryDistributionDb, $defaultFilename, $additionalAsset->getId());
                     $this->filesForDistribution[] = $file;
                 }
             }
         }
         $distributedCaptionIds = implode(',', $captionLocalIds);
     }
     //putting distributed flavors ids and distributed thumbnail ids in entry distribution custom data
     if ($entryDistributionDb) {
         $entryDistributionDb->putInCustomData(AttUverseEntryDistributionCustomDataField::DISTRIBUTED_FLAVOR_IDS, $distributedFlavorIds);
         $entryDistributionDb->putInCustomData(AttUverseEntryDistributionCustomDataField::DISTRIBUTED_THUMBNAIL_IDS, $distributedThumbIds);
         $entryDistributionDb->putInCustomData(AttUverseEntryDistributionCustomDataField::DISTRIBUTED_CAPTION_IDS, $distributedCaptionIds);
         $entryDistributionDb->save();
     } else {
         KalturaLog::err('Entry distribution [' . $distributionJobData->entryDistributionId . '] not found');
     }
 }
 private function getValidVideoPath(KalturaDistributionJobData $distributionJobData)
 {
     $flavorAssets = array();
     $videoAssetFilePath = null;
     $isValidVideo = false;
     if (count($distributionJobData->entryDistribution->flavorAssetIds)) {
         $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     } else {
         $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryId($distributionJobData->entryDistribution->entryId);
     }
     foreach ($flavorAssets as $flavorAsset) {
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
             if ($mediaInfo) {
                 try {
                     FacebookGraphSdkUtils::validateVideoAttributes($videoAssetFilePath, $mediaInfo->getFileSize(), $mediaInfo->getVideoDuration());
                     $isValidVideo = true;
                 } catch (Exception $e) {
                     KalturaLog::debug('Asset [' . $flavorAsset->getId() . '] not valid for distribution: ' . $e->getMessage());
                 }
             }
             if ($isValidVideo) {
                 break;
             }
         }
     }
     return $videoAssetFilePath;
 }
Exemple #23
0
 /**
  * @param BatchJob $parentJob
  * @param liveAsset $asset
  * @param int $mediaServerIndex
  * @param string $filePath
  * @param float $endTime
  */
 public static function addConvertLiveSegmentJob(BatchJob $parentJob = null, liveAsset $asset, $mediaServerIndex, $filePath, $endTime)
 {
     $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_PRIMARY;
     if ($mediaServerIndex == MediaServerIndex::SECONDARY) {
         $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_SECONDARY;
     }
     $key = $asset->getSyncKey($keyType);
     $files = array();
     if (kFileSyncUtils::fileSync_exists($key)) {
         $files = kFileSyncUtils::dir_get_files($key, false);
     }
     $jobData = new kConvertLiveSegmentJobData();
     $jobData->setEntryId($asset->getEntryId());
     $jobData->setAssetId($asset->getId());
     $jobData->setMediaServerIndex($mediaServerIndex);
     $jobData->setEndTime($endTime);
     $jobData->setSrcFilePath($filePath);
     $jobData->setFileIndex(count($files));
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::CONVERT_LIVE_SEGMENT);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($asset->getEntryId());
         $batchJob->setPartnerId($asset->getPartnerId());
     }
     $batchJob->setObjectId($asset->getEntryId());
     $batchJob->setObjectType(BatchJobObjectType::ENTRY);
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_LIVE_SEGMENT);
 }
 /**
  * Update an existing metadata object definition file
  *
  * @action revert
  * @param int $id
  * @param int $toVersion
  * @return KalturaMetadataProfile
  * @throws MetadataErrors::METADATA_PROFILE_NOT_FOUND
  * @throws MetadataErrors::METADATA_FILE_NOT_FOUND
  * @throws MetadataErrors::METADATA_UNABLE_TO_TRANSFORM
  */
 function revertAction($id, $toVersion)
 {
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_NOT_FOUND, $id);
     }
     $oldKey = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION, $toVersion);
     if (!kFileSyncUtils::fileSync_exists($oldKey)) {
         throw new KalturaAPIException(MetadataErrors::METADATA_FILE_NOT_FOUND, $oldKey);
     }
     $dbMetadataProfile->incrementFileSyncVersion();
     $dbMetadataProfile->incrementVersion();
     $dbMetadataProfile->save();
     $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     kFileSyncUtils::createSyncFileLinkForKey($key, $oldKey);
     kMetadataManager::parseProfileSearchFields($this->getPartnerId(), $dbMetadataProfile);
     MetadataPeer::setUseCriteriaFilter(false);
     $metadatas = MetadataPeer::retrieveByProfile($id, $toVersion);
     foreach ($metadatas as $metadata) {
         // validate object exists
         $object = kMetadataManager::getObjectFromPeer($metadata);
         if (!$object) {
             continue;
         }
         $metadata->incrementVersion();
         $oldKey = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA, $toVersion);
         if (!kFileSyncUtils::fileSync_exists($oldKey)) {
             continue;
         }
         $xml = kFileSyncUtils::file_get_contents($oldKey, true, false);
         if (!$xml) {
             continue;
         }
         $errorMessage = '';
         if (!kMetadataManager::validateMetadata($dbMetadataProfile->getId(), $xml, $errorMessage)) {
             continue;
         }
         $metadata->setMetadataProfileVersion($dbMetadataProfile->getVersion());
         $metadata->setStatus(Metadata::STATUS_VALID);
         $metadata->save();
         $key = $metadata->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
         kFileSyncUtils::createSyncFileLinkForKey($key, $oldKey);
     }
     $metadataProfile = new KalturaMetadataProfile();
     $metadataProfile->fromObject($dbMetadataProfile, $this->getResponseProfile());
     return $metadataProfile;
 }
 public function loadProperties(KalturaDistributionJobData $distributionJobData, KalturaGenericDistributionProfile $distributionProfile, $action)
 {
     $actionName = self::$actionAttributes[$action];
     $genericProviderAction = GenericDistributionProviderActionPeer::retrieveByProviderAndAction($distributionProfile->genericProviderId, $action);
     if (!$genericProviderAction) {
         KalturaLog::err("Generic provider [{$distributionProfile->genericProviderId}] action [{$actionName}] not found");
         return;
     }
     if (!$distributionJobData->entryDistribution) {
         KalturaLog::err("Entry Distribution object not provided");
         return;
     }
     if (!$distributionProfile->{$actionName}->protocol) {
         $distributionProfile->{$actionName}->protocol = $genericProviderAction->getProtocol();
     }
     if (!$distributionProfile->{$actionName}->serverUrl) {
         $distributionProfile->{$actionName}->serverUrl = $genericProviderAction->getServerAddress();
     }
     if (!$distributionProfile->{$actionName}->serverPath) {
         $distributionProfile->{$actionName}->serverPath = $genericProviderAction->getRemotePath();
     }
     if (!$distributionProfile->{$actionName}->username) {
         $distributionProfile->{$actionName}->username = $genericProviderAction->getRemoteUsername();
     }
     if (!$distributionProfile->{$actionName}->password) {
         $distributionProfile->{$actionName}->password = $genericProviderAction->getRemotePassword();
     }
     if (!$distributionProfile->{$actionName}->ftpPassiveMode) {
         $distributionProfile->{$actionName}->ftpPassiveMode = $genericProviderAction->getFtpPassiveMode();
     }
     if (!$distributionProfile->{$actionName}->httpFieldName) {
         $distributionProfile->{$actionName}->httpFieldName = $genericProviderAction->getHttpFieldName();
     }
     if (!$distributionProfile->{$actionName}->httpFileName) {
         $distributionProfile->{$actionName}->httpFileName = $genericProviderAction->getHttpFileName();
     }
     $entry = entryPeer::retrieveByPKNoFilter($distributionJobData->entryDistribution->entryId);
     if (!$entry) {
         KalturaLog::err("Entry [" . $distributionJobData->entryDistribution->entryId . "] not found");
         return;
     }
     $mrss = kMrssManager::getEntryMrss($entry);
     if (!$mrss) {
         KalturaLog::err("MRSS not returned for entry [" . $entry->getId() . "]");
         return;
     }
     $xml = new KDOMDocument();
     if (!$xml->loadXML($mrss)) {
         KalturaLog::err("MRSS not is not valid XML:\n{$mrss}\n");
         return;
     }
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_MRSS_TRANSFORMER);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $xslPath = kFileSyncUtils::getLocalFilePathForKey($key);
         if ($xslPath) {
             $xsl = new KDOMDocument();
             $xsl->load($xslPath);
             // set variables in the xsl
             $varNodes = $xsl->getElementsByTagName('variable');
             foreach ($varNodes as $varNode) {
                 $nameAttr = $varNode->attributes->getNamedItem('name');
                 if (!$nameAttr) {
                     continue;
                 }
                 $name = $nameAttr->value;
                 if ($name && $distributionJobData->{$name}) {
                     $varNode->textContent = $distributionJobData->{$name};
                     $varNode->appendChild($xsl->createTextNode($distributionJobData->{$name}));
                 }
             }
             $proc = new XSLTProcessor();
             $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions());
             $proc->importStyleSheet($xsl);
             $xml = $proc->transformToDoc($xml);
             if (!$xml) {
                 KalturaLog::err("Transform returned false");
                 return;
             }
         }
     }
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_MRSS_VALIDATOR);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $xsdPath = kFileSyncUtils::getLocalFilePathForKey($key);
         if ($xsdPath && !$xml->schemaValidate($xsdPath)) {
             KalturaLog::err("Inavlid XML:\n" . $xml->saveXML());
             KalturaLog::err("Schema [{$xsdPath}]:\n" . file_get_contents($xsdPath));
             return;
         }
     }
     $this->xml = $xml->saveXML();
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_RESULTS_TRANSFORMER);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $this->resultParseData = kFileSyncUtils::file_get_contents($key, true, false);
     }
     $this->resultParserType = $genericProviderAction->getResultsParser();
 }
 public function getCaptionAssetInfo($captionAssetIds)
 {
     $captionAssetInfo = array();
     $assetIdsArray = explode(',', $captionAssetIds);
     if (empty($assetIdsArray)) {
         return;
     }
     $assets = assetPeer::retrieveByIds($assetIdsArray);
     foreach ($assets as $asset) {
         $assetType = $asset->getType();
         if ($assetType == CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION)) {
             /* @var $asset CaptionAsset */
             $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             if (kFileSyncUtils::fileSync_exists($syncKey)) {
                 $captionAssetInfo[$asset->getId()]['fileUrl'] = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                 $captionAssetInfo[$asset->getId()]['fileExt'] = $asset->getFileExt();
                 $captionAssetInfo[$asset->getId()]['language'] = $asset->getLanguage();
                 break;
             }
         }
     }
     return $captionAssetInfo;
 }
 private function addCaptionsData(KalturaDistributionJobData $distributionJobData)
 {
     /* @var $mediaFile KalturaDistributionRemoteMediaFile */
     $assetIdsArray = explode(',', $distributionJobData->entryDistribution->assetIds);
     if (empty($assetIdsArray)) {
         return;
     }
     $assets = array();
     $this->captionsInfo = new KalturaDailymotionDistributionCaptionInfoArray();
     foreach ($assetIdsArray as $assetId) {
         $asset = assetPeer::retrieveByIdNoFilter($assetId);
         if (!$asset) {
             KalturaLog::err("Asset [{$assetId}] not found");
             continue;
         }
         if ($asset->getStatus() == asset::ASSET_STATUS_READY) {
             $assets[] = $asset;
         } elseif ($asset->getStatus() == asset::ASSET_STATUS_DELETED) {
             $captionInfo = new KalturaDailymotionDistributionCaptionInfo();
             $captionInfo->action = KalturaDailymotionDistributionCaptionAction::DELETE_ACTION;
             $captionInfo->assetId = $assetId;
             //getting the asset's remote id
             foreach ($distributionJobData->mediaFiles as $mediaFile) {
                 if ($mediaFile->assetId == $assetId) {
                     $captionInfo->remoteId = $mediaFile->remoteId;
                     $this->captionsInfo[] = $captionInfo;
                     break;
                 }
             }
         } else {
             KalturaLog::err("Asset [{$assetId}] has status [" . $asset->getStatus() . "]. not added to provider data");
         }
     }
     foreach ($assets as $asset) {
         $assetType = $asset->getType();
         switch ($assetType) {
             case CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION):
                 $syncKey = $asset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                 if (kFileSyncUtils::fileSync_exists($syncKey)) {
                     $captionInfo = $this->getCaptionInfo($asset, $syncKey, $distributionJobData);
                     if ($captionInfo) {
                         $captionInfo->language = $this->getLanguageCode($asset->getLanguage());
                         $captionInfo->format = $this->getCaptionFormat($asset);
                         if ($captionInfo->language) {
                             $this->captionsInfo[] = $captionInfo;
                         } else {
                             KalturaLog::err('The caption [' . $asset->getId() . '] has unrecognized language [' . $asset->getLanguage() . ']');
                         }
                     }
                 }
                 break;
             case AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT):
                 $syncKey = $asset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                 if (kFileSyncUtils::fileSync_exists($syncKey)) {
                     $captionInfo = $this->getCaptionInfo($asset, $syncKey, $distributionJobData);
                     if ($captionInfo) {
                         //language code should be set in the attachments title
                         $captionInfo->language = $asset->getTitle();
                         $captionInfo->format = $this->getCaptionFormat($asset);
                         $languageCodeReflector = KalturaTypeReflectorCacher::get('KalturaLanguageCode');
                         //check if the language code exists
                         if ($languageCodeReflector && $languageCodeReflector->getConstantName($captionInfo->language)) {
                             $this->captionsInfo[] = $captionInfo;
                         } else {
                             KalturaLog::err('The attachment [' . $asset->getId() . '] has unrecognized language [' . $asset->getTitle() . ']');
                         }
                     }
                 }
                 break;
         }
     }
 }
Exemple #28
0
 /**
  * Serves thumbnail by its id
  *  
  * @action serve
  * @param string $thumbAssetId
  * @param int $version
  * @param KalturaThumbParams $thumbParams
  * @param KalturaThumbnailServeOptions $options
  * @return file
  *  
  * @throws KalturaErrors::THUMB_ASSET_IS_NOT_READY
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  */
 public function serveAction($thumbAssetId, $version = null, KalturaThumbParams $thumbParams = null, KalturaThumbnailServeOptions $options = null)
 {
     if (!kCurrentContext::$ks) {
         $thumbAsset = kCurrentContext::initPartnerByAssetId($thumbAssetId);
         if (!$thumbAsset || $thumbAsset->getStatus() == asset::ASSET_STATUS_DELETED) {
             throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
         }
         // enforce entitlement
         $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId());
         kEntitlementUtils::initEntitlementEnforcement();
     } else {
         $thumbAsset = assetPeer::retrieveById($thumbAssetId);
     }
     if (!$thumbAsset || !$thumbAsset instanceof thumbAsset) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     $entry = entryPeer::retrieveByPK($thumbAsset->getEntryId());
     if (!$entry) {
         //we will throw thumb asset not found, as the user is not entitled, and should not know that the entry exists.
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     $securyEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, null, ContextType::THUMBNAIL);
     $securyEntryHelper->validateAccessControl();
     $ext = $thumbAsset->getFileExt();
     if (is_null($ext)) {
         $ext = 'jpg';
     }
     $fileName = $thumbAsset->getEntryId() . "_" . $thumbAsset->getId() . ".{$ext}";
     if (!$thumbParams) {
         if ($options && $options->download) {
             header("Content-Disposition: attachment; filename=\"{$fileName}\"");
         }
         return $this->serveAsset($thumbAsset, $fileName, $version);
     }
     $thumbParams->validate();
     $syncKey = $thumbAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $version);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     /* @var $fileSync FileSync */
     if (!$local) {
         if (!in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) {
             throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
         }
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         KalturaLog::info("Redirecting to [{$remoteUrl}]");
         header("Location: {$remoteUrl}");
         die;
     }
     $filePath = $fileSync->getFullPath();
     $thumbVersion = $thumbAsset->getId() . '_' . $version;
     $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $thumbVersion, $thumbParams->width, $thumbParams->height, $thumbParams->cropType, $thumbParams->backgroundColor, null, $thumbParams->quality, $thumbParams->cropX, $thumbParams->cropY, $thumbParams->cropWidth, $thumbParams->cropHeight, -1, 0, -1, $filePath, $thumbParams->density, $thumbParams->stripProfiles, null);
     if ($options && $options->download) {
         header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     }
     $mimeType = kFile::mimeType($tempThumbPath);
     return $this->dumpFile($tempThumbPath, $mimeType);
 }
 /**
  * returns absolute valid url for asset file
  * 
  * @action getAssetUrl
  * @param string $assetId
  * @return string
  * @throws KalturaErrors::INVALID_OBJECT_ID
  * @throws KalturaErrors::FLAVOR_ASSET_IS_NOT_READY
  * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND
  */
 function getAssetUrlAction($assetId)
 {
     assetPeer::resetInstanceCriteriaFilter();
     $asset = assetPeer::retrieveById($assetId);
     if (!$asset) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $assetId);
     }
     $ext = $asset->getFileExt();
     if (is_null($ext)) {
         $ext = 'jpg';
     }
     $fileName = $asset->getEntryId() . "_" . $asset->getId() . ".{$ext}";
     $syncKey = $asset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY, $asset->getId());
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     if (!$fileSync) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $asset->getId());
     }
     return $fileSync->getExternalUrl();
 }
 /**
  * Update content of thumbnail asset
  *
  * @action setContent
  * @param string $id
  * @param KalturaContentResource $contentResource
  * @return KalturaThumbAsset
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  * @throws KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY
  * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
  * @throws KalturaErrors::RECORDED_WEBCAM_FILE_NOT_FOUND
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND
  * @throws KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED
  * @validateUser asset::entry id edit 
  */
 function setContentAction($id, KalturaContentResource $contentResource)
 {
     $dbThumbAsset = assetPeer::retrieveById($id);
     if (!$dbThumbAsset || !$dbThumbAsset instanceof thumbAsset) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $id);
     }
     $dbEntry = $dbThumbAsset->getentry();
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $dbThumbAsset->getEntryId());
     }
     $previousStatus = $dbThumbAsset->getStatus();
     $contentResource->validateEntry($dbThumbAsset->getentry());
     $contentResource->validateAsset($dbThumbAsset);
     $kContentResource = $contentResource->toObject();
     $this->attachContentResource($dbThumbAsset, $kContentResource);
     $contentResource->entryHandled($dbThumbAsset->getentry());
     kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbThumbAsset));
     $newStatuses = array(thumbAsset::ASSET_STATUS_READY, thumbAsset::ASSET_STATUS_VALIDATING, thumbAsset::ASSET_STATUS_TEMP);
     if ($previousStatus == thumbAsset::ASSET_STATUS_QUEUED && in_array($dbThumbAsset->getStatus(), $newStatuses)) {
         kEventsManager::raiseEvent(new kObjectAddedEvent($dbThumbAsset));
     }
     $thumbAssetsCount = assetPeer::countThumbnailsByEntryId($dbThumbAsset->getEntryId());
     $defaultThumbKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     //If the thums has the default tag or the entry is in no content and this is the first thumb
     if ($dbEntry->getCreateThumb() && ($dbThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB) || $dbEntry->getStatus() == KalturaEntryStatus::NO_CONTENT && $thumbAssetsCount == 1 && !kFileSyncUtils::fileSync_exists($defaultThumbKey))) {
         $this->setAsDefaultAction($dbThumbAsset->getId());
     }
     $thumbAsset = new KalturaThumbAsset();
     $thumbAsset->fromObject($dbThumbAsset);
     return $thumbAsset;
 }