Пример #1
0
 /**
  * Add new Syndication Feed
  * 
  * @action add
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed 
  */
 public function addAction(KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeed->validatePlaylistId();
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $syndicationFeed->validateXslt();
         $syndicationFeedDB = new genericSyndicationFeed();
         $syndicationFeedDB->setVersion(1);
     } else {
         $syndicationFeedDB = new syndicationFeed();
     }
     $syndicationFeed->partnerId = $this->getPartnerId();
     $syndicationFeed->status = KalturaSyndicationFeedStatus::ACTIVE;
     $syndicationFeed->toObject($syndicationFeedDB);
     $syndicationFeedDB->save();
     if ($syndicationFeed->addToDefaultConversionProfile) {
         $partner = PartnerPeer::retrieveByPK($this->getPartnerId());
         $c = new Criteria();
         $c->addAnd(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $partner->getDefaultConversionProfileId());
         $c->addAnd(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $syndicationFeed->flavorParamId);
         $is_exist = flavorParamsConversionProfilePeer::doCount($c);
         if (!$is_exist || $is_exist === 0) {
             $fpc = new flavorParamsConversionProfile();
             $fpc->setConversionProfileId($partner->getDefaultConversionProfileId());
             $fpc->setFlavorParamsId($syndicationFeed->flavorParamId);
             $fpc->save();
         }
     }
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed->fromObject($syndicationFeedDB);
     return $syndicationFeed;
 }
Пример #2
0
 public function clearMemory()
 {
     accessControlPeer::clearInstancePool();
     BatchJobPeer::clearInstancePool();
     BulkUploadResultPeer::clearInstancePool();
     categoryPeer::clearInstancePool();
     EmailIngestionProfilePeer::clearInstancePool();
     entryPeer::clearInstancePool();
     FileSyncPeer::clearInstancePool();
     flavorAssetPeer::clearInstancePool();
     flavorParamsConversionProfilePeer::clearInstancePool();
     flavorParamsOutputPeer::clearInstancePool();
     flavorParamsPeer::clearInstancePool();
     kshowPeer::clearInstancePool();
     mediaInfoPeer::clearInstancePool();
     moderationFlagPeer::clearInstancePool();
     moderationPeer::clearInstancePool();
     notificationPeer::clearInstancePool();
     roughcutEntryPeer::clearInstancePool();
     SchedulerConfigPeer::clearInstancePool();
     SchedulerPeer::clearInstancePool();
     SchedulerStatusPeer::clearInstancePool();
     SchedulerWorkerPeer::clearInstancePool();
     StorageProfilePeer::clearInstancePool();
     syndicationFeedPeer::clearInstancePool();
     TrackEntryPeer::clearInstancePool();
     uiConfPeer::clearInstancePool();
     UploadTokenPeer::clearInstancePool();
     // TODO clear default filters
     // TODO call all memory cleaner plugins
     if (function_exists('gc_collect_cycles')) {
         // php 5.3 and above
         gc_collect_cycles();
     }
 }
 public function loadFlavorParamsIds()
 {
     $conversionProfileIds = array();
     // find all profile ids
     foreach ($this as $conversionProfile) {
         $conversionProfileIds[] = $conversionProfile->id;
     }
     // get all params relations by the profile ids list
     $c = new Criteria();
     $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfileIds, Criteria::IN);
     $allParams = flavorParamsConversionProfilePeer::doSelect($c);
     $paramsIdsPerProfile = array();
     // group the params by profile id
     foreach ($allParams as $item) {
         if (!isset($paramsIdsPerProfile[$item->getConversionProfileId()])) {
             $paramsIdsPerProfile[$item->getConversionProfileId()] = array();
         }
         $paramsIdsPerProfile[$item->getConversionProfileId()][] = $item->getFlavorParamsId();
     }
     // assign the params ids to the profiles
     foreach ($this as $conversionProfile) {
         if (isset($paramsIdsPerProfile[$conversionProfile->id])) {
             $conversionProfile->flavorParamsIds = implode(",", $paramsIdsPerProfile[$conversionProfile->id]);
         }
     }
 }
 /**
  * 
  * @param int $conversionProfileId
  * @param $con
  * 
  * @return array
  */
 public static function getFlavorIdsByProfileId($conversionProfileId, $con = null)
 {
     $criteria = new Criteria();
     $criteria->addSelectColumn(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID);
     $criteria->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfileId);
     $stmt = flavorParamsConversionProfilePeer::doSelectStmt($criteria, $con);
     return $stmt->fetchAll(PDO::FETCH_COLUMN);
 }
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     $assetParamsConversionProfileFilter = $this->toObject();
     $c = new Criteria();
     $assetParamsConversionProfileFilter->attachToCriteria($c);
     $totalCount = flavorParamsConversionProfilePeer::doCount($c);
     $pager->attachToCriteria($c);
     $dbList = flavorParamsConversionProfilePeer::doSelect($c);
     $list = KalturaConversionProfileAssetParamsArray::fromDbArray($dbList, $responseProfile);
     $response = new KalturaConversionProfileAssetParamsListResponse();
     $response->objects = $list;
     $response->totalCount = $totalCount;
     return $response;
 }
 /**
  * Update asset parmas of conversion profile by ID
  * 
  * @action update
  * @param int $conversionProfileId
  * @param int $assetParamsId
  * @param KalturaConversionProfileAssetParams $conversionProfileAssetParams
  * @return KalturaConversionProfileAssetParams
  */
 public function updateAction($conversionProfileId, $assetParamsId, KalturaConversionProfileAssetParams $conversionProfileAssetParams)
 {
     $conversionProfile = ConversionProfile2Peer::retrieveByPK($conversionProfileId);
     if (!$conversionProfile) {
         throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId);
     }
     $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($assetParamsId, $conversionProfileId);
     if (!$flavorParamsConversionProfile) {
         throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ASSET_PARAMS_NOT_FOUND, $conversionProfileId, $assetParamsId);
     }
     $conversionProfileAssetParams->toUpdatableObject($flavorParamsConversionProfile);
     $flavorParamsConversionProfile->save();
     $conversionProfileAssetParams->fromObject($flavorParamsConversionProfile);
     return $conversionProfileAssetParams;
 }
Пример #7
0
 /**
  * Add new Syndication Feed
  * 
  * @action add
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed 
  */
 public function addAction(KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeed->validatePlaylistId();
     $syndicationFeed->validateStorageId($this->getPartnerId());
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $syndicationFeed->validatePropertyNotNull('xslt');
         $syndicationFeedDB = new genericSyndicationFeed();
         $syndicationFeedDB->incrementVersion();
     } else {
         $syndicationFeedDB = new syndicationFeed();
     }
     $syndicationFeed->toInsertableObject($syndicationFeedDB);
     $syndicationFeedDB->setPartnerId($this->getPartnerId());
     $syndicationFeedDB->setStatus(KalturaSyndicationFeedStatus::ACTIVE);
     $syndicationFeedDB->save();
     if ($syndicationFeed->addToDefaultConversionProfile) {
         $partner = PartnerPeer::retrieveByPK($this->getPartnerId());
         $c = new Criteria();
         $c->addAnd(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $partner->getDefaultConversionProfileId());
         $c->addAnd(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $syndicationFeed->flavorParamId);
         $is_exist = flavorParamsConversionProfilePeer::doCount($c);
         if (!$is_exist || $is_exist === 0) {
             $assetParams = assetParamsPeer::retrieveByPK($syndicationFeed->flavorParamId);
             $fpc = new flavorParamsConversionProfile();
             $fpc->setConversionProfileId($partner->getDefaultConversionProfileId());
             $fpc->setFlavorParamsId($syndicationFeed->flavorParamId);
             if ($assetParams) {
                 $fpc->setReadyBehavior($assetParams->getReadyBehavior());
                 $fpc->setSystemName($assetParams->getSystemName());
                 if ($assetParams->hasTag(assetParams::TAG_SOURCE) || $assetParams->hasTag(assetParams::TAG_INGEST)) {
                     $fpc->setOrigin(assetParamsOrigin::INGEST);
                 } else {
                     $fpc->setOrigin(assetParamsOrigin::CONVERT);
                 }
             }
             $fpc->save();
         }
     }
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed->fromObject($syndicationFeedDB, $this->getResponseProfile());
     return $syndicationFeed;
 }
Пример #8
0
 public static function getReadyBehavior(flavorAsset $flavorAsset)
 {
     if ($flavorAsset->getIsOriginal()) {
         try {
             $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId());
             if ($profile) {
                 $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavorAsset->getFlavorParamsId(), $profile->getId());
                 if ($flavorParamsConversionProfile) {
                     return $flavorParamsConversionProfile->getReadyBehavior();
                 }
             }
         } catch (Exception $e) {
             KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage());
         }
     }
     $targetFlavor = flavorParamsOutputPeer::retrieveByFlavorAssetId($flavorAsset->getId());
     if ($targetFlavor) {
         return $targetFlavor->getReadyBehavior();
     }
     return flavorParamsConversionProfile::READY_BEHAVIOR_INHERIT_FLAVOR_PARAMS;
 }
Пример #9
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this assetParams is new, it will return
  * an empty collection; or if this assetParams has previously
  * been saved, it will retrieve related flavorParamsConversionProfiles from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in assetParams.
  */
 public function getflavorParamsConversionProfilesJoinconversionProfile2($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(assetParamsPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collflavorParamsConversionProfiles === null) {
         if ($this->isNew()) {
             $this->collflavorParamsConversionProfiles = array();
         } else {
             $criteria->add(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $this->id);
             $this->collflavorParamsConversionProfiles = flavorParamsConversionProfilePeer::doSelectJoinconversionProfile2($criteria, $con, $join_behavior);
         }
     } else {
         // the following code is to determine if a new query is
         // called for.  If the criteria is the same as the last
         // one, just return the collection.
         $criteria->add(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $this->id);
         if (!isset($this->lastflavorParamsConversionProfileCriteria) || !$this->lastflavorParamsConversionProfileCriteria->equals($criteria)) {
             $this->collflavorParamsConversionProfiles = flavorParamsConversionProfilePeer::doSelectJoinconversionProfile2($criteria, $con, $join_behavior);
         }
     }
     $this->lastflavorParamsConversionProfileCriteria = $criteria;
     return $this->collflavorParamsConversionProfiles;
 }
Пример #10
0
 /**
  * Delete the relation of flavorParams <> conversionProfile2
  * 
  * @param conversionProfile2 $conversionProfileDb
  */
 protected function deleteFlavorParamsRelation(conversionProfile2 $conversionProfileDb)
 {
     $c = new Criteria();
     $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfileDb->getId());
     flavorParamsConversionProfilePeer::doDelete($c);
 }
 /**
  * Serve XML rendition of the Kaltura Live Transcoding Profile usable by the Wowza transcoding add-on
  * 
  * @action serve
  * @param string $streamName the id of the live entry with it's stream suffix
  * @param string $hostname the media server host name
  * @return file
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws WowzaErrors::INVALID_STREAM_NAME
  */
 public function serveAction($streamName, $hostname = null)
 {
     $matches = null;
     if (!preg_match('/^(\\d_.{8})_(\\d+)$/', $streamName, $matches)) {
         throw new KalturaAPIException(WowzaErrors::INVALID_STREAM_NAME, $streamName);
     }
     $entryId = $matches[1];
     $suffix = $matches[2];
     $entry = null;
     if (!kCurrentContext::$ks) {
         kEntitlementUtils::initEntitlementEnforcement(null, false);
         $entry = kCurrentContext::initPartnerByEntryId($entryId);
         if (!$entry || $entry->getStatus() == entryStatus::DELETED) {
             throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
         }
         // enforce entitlement
         $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId());
     } else {
         $entry = entryPeer::retrieveByPK($entryId);
     }
     if (!$entry || $entry->getType() != KalturaEntryType::LIVE_STREAM || !in_array($entry->getSource(), array(KalturaSourceType::LIVE_STREAM, KalturaSourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $mediaServer = null;
     if ($hostname) {
         $mediaServer = MediaServerPeer::retrieveByHostname($hostname);
     }
     $conversionProfileId = $entry->getConversionProfileId();
     $liveParams = assetParamsPeer::retrieveByProfile($conversionProfileId);
     $liveParamsInput = null;
     $disableIngested = true;
     foreach ($liveParams as $liveParamsItem) {
         /* @var $liveParamsItem liveParams */
         if ($liveParamsItem->getStreamSuffix() == $suffix) {
             $liveParamsInput = $liveParamsItem;
             if (!$liveParamsInput->hasTag(assetParams::TAG_SOURCE)) {
                 $liveParams = array($liveParamsInput);
                 $disableIngested = false;
             }
             break;
         }
     }
     $ignoreLiveParamsIds = array();
     if ($disableIngested) {
         $conversionProfileAssetParams = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfileId);
         foreach ($conversionProfileAssetParams as $conversionProfileAssetParamsItem) {
             /* @var $conversionProfileAssetParamsItem flavorParamsConversionProfile */
             if ($conversionProfileAssetParamsItem->getOrigin() == assetParamsOrigin::INGEST) {
                 $ignoreLiveParamsIds[] = $conversionProfileAssetParamsItem->getFlavorParamsId();
             }
         }
     }
     // translate the $liveParams to XML according to doc: http://www.wowza.com/forums/content.php?304#configTemplate
     $root = new SimpleXMLElement('<Root/>');
     $transcode = $root->addChild('Transcode');
     $encodes = $transcode->addChild('Encodes');
     $groups = array();
     foreach ($liveParams as $liveParamsItem) {
         /* @var $liveParamsItem liveParams */
         if (!$liveParamsItem->hasTag(assetParams::TAG_SOURCE) && in_array($liveParamsItem->getId(), $ignoreLiveParamsIds)) {
             continue;
         }
         $this->appendLiveParams($entry, $mediaServer, $encodes, $liveParamsItem);
         $tags = $liveParamsItem->getTagsArray();
         $tags[] = 'all';
         foreach ($tags as $tag) {
             if (!isset($groups[$tag])) {
                 $groups[$tag] = array();
             }
             $systemName = $liveParamsItem->getSystemName() ? $liveParamsItem->getSystemName() : $liveParamsItem->getId();
             $groups[$tag][] = $systemName;
         }
     }
     $decode = $transcode->addChild('Decode');
     $video = $decode->addChild('Video');
     $video->addChild('Deinterlace', 'false');
     $streamNameGroups = $transcode->addChild('StreamNameGroups');
     foreach ($groups as $groupName => $groupMembers) {
         $streamNameGroup = $streamNameGroups->addChild('StreamNameGroup');
         $streamNameGroup->addChild('Name', $groupName);
         $streamNameGroup->addChild('StreamName', '${SourceStreamName}_' . $groupName);
         $members = $streamNameGroup->addChild('Members');
         foreach ($groupMembers as $groupMember) {
             $member = $members->addChild('Member');
             $member->addChild('EncodeName', $groupMember);
         }
     }
     $properties = $transcode->addChild('Properties');
     $dom = new DOMDocument("1.0");
     $dom->preserveWhiteSpace = false;
     $dom->formatOutput = true;
     $dom->loadXML($root->asXML());
     return new kRendererString($dom->saveXML(), 'text/xml');
 }
Пример #12
0
 /**
  * @param assetParams $assetParam
  */
 protected function assetParamDeleted(assetParams $assetParam)
 {
     //In Case Flavor Deleted Belongs To Partner 0 Exit Without Deleteing
     if ($assetParam->getPartnerId() == 0) {
         KalturaLog::log("Deleting Flavor Param Of Partner 0 Is Restricted");
         return;
     }
     $c = new Criteria();
     $c->setLimit(100);
     $c->add(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $assetParam->getId());
     for (;;) {
         $flavorParamsConversionProfiles = flavorParamsConversionProfilePeer::doSelect($c);
         foreach ($flavorParamsConversionProfiles as $flavorParamsConversionProfile) {
             /* @var $flavorParamsConversionProfile flavorParamsConversionProfile */
             $flavorParamsConversionProfile->delete();
         }
         if (count($flavorParamsConversionProfiles) < 100) {
             break;
         }
         flavorParamsConversionProfilePeer::clearInstancePool();
     }
     KalturaLog::info("Flavor Params Conversion Profile Relations were deleted for flavor param id [" . $assetParam->getId() . "]");
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(flavorParamsConversionProfilePeer::DATABASE_NAME);
         $criteria->add(flavorParamsConversionProfilePeer::ID, $pks, Criteria::IN);
         $objs = flavorParamsConversionProfilePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Пример #14
0
 public function calculatePriority(BatchJob $batchJob)
 {
     if ($this->priority == 0) {
         $flavorParamsId = $this->getFlavorParamsOutput()->getFlavorParamsId();
         $fpcp = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavorParamsId, $this->conversionProfileId);
         if (!is_null($fpcp) && $fpcp->getPriority() != 0) {
             $this->priority = $fpcp->getPriority();
         } else {
             $this->priority = parent::calculatePriority($batchJob);
         }
     }
     return $this->priority;
 }
Пример #15
0
 private static function deleteTemporaryFlavors($entryId)
 {
     $originalflavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if ($originalflavorAsset && $originalflavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_TEMP) {
         $originalflavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalflavorAsset->setDeletedAt(time());
         $originalflavorAsset->save();
     }
     $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$conversionProfile) {
         return;
     }
     $criteria = new Criteria();
     $criteria->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
     $criteria->add(flavorParamsConversionProfilePeer::DELETE_POLICY, AssetParamsDeletePolicy::DELETE);
     $tempFlavorsParams = flavorParamsConversionProfilePeer::doSelect($criteria);
     foreach ($tempFlavorsParams as $tempFlavorsParam) {
         $tempFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $tempFlavorsParam->getFlavorParamsId());
         if ($tempFlavorAsset) {
             $tempFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
             $tempFlavorAsset->setDeletedAt(time());
             $tempFlavorAsset->save();
         }
     }
 }
 public static function copyConversionProfiles(Partner $fromPartner, Partner $toPartner)
 {
     $copiedList = array();
     KalturaLog::log("Copying conversion profiles from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     $c = new Criteria();
     $c->add(conversionProfile2Peer::PARTNER_ID, $fromPartner->getId());
     $conversionProfiles = conversionProfile2Peer::doSelect($c);
     foreach ($conversionProfiles as $conversionProfile) {
         $newConversionProfile = $conversionProfile->copy();
         $newConversionProfile->setPartnerId($toPartner->getId());
         $newConversionProfile->save();
         KalturaLog::log("Copied [" . $conversionProfile->getId() . "], new id is [" . $newConversionProfile->getId() . "]");
         $copiedList[$conversionProfile->getId()] = $newConversionProfile->getId();
         $c = new Criteria();
         $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
         $fpcpList = flavorParamsConversionProfilePeer::doSelect($c);
         foreach ($fpcpList as $fpcp) {
             $flavorParamsId = $fpcp->getFlavorParamsId();
             $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
             if ($flavorParams && $flavorParams->getPartnerId() === 0) {
                 $newFpcp = $fpcp->copy();
                 $newFpcp->setConversionProfileId($newConversionProfile->getId());
                 $newFpcp->save();
             }
         }
     }
     $toPartner->save();
     // make sure conversion profile is set on the new partner in case it was missed/skiped in the conversionProfile2::copy method
     if (!$toPartner->getDefaultConversionProfileId()) {
         $fromPartnerDefaultProfile = $fromPartner->getDefaultConversionProfileId();
         if ($fromPartnerDefaultProfile && key_exists($fromPartnerDefaultProfile, $copiedList)) {
             $toPartner->setDefaultConversionProfileId($copiedList[$fromPartnerDefaultProfile]);
             $toPartner->save();
         }
     }
 }
Пример #17
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     // gets the flavor params by the id
     $flavors = assetParamsPeer::retrieveFlavorsByPKs($flavorsIds);
     self::checkConvertProfileParams($flavors, $conversionProfileFlavorParams, $entry);
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     try {
         return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $profile->getId(), $mediaInfo);
     } catch (Exception $e) {
         KalturaLog::err('decideProfileFlavorsConvert - ' . $e->getMessage());
     }
 }
Пример #18
0
 /**
  * Authenticate live-stream entry against stream token and partner limitations
  * 
  * @action authenticate
  * @param string $entryId Live stream entry id
  * @param string $token Live stream broadcasting token
  * @return KalturaLiveStreamEntry The authenticated live stream entry
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::LIVE_STREAM_INVALID_TOKEN
  */
 function authenticateAction($entryId, $token)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || $dbEntry->getType() != entryType::LIVE_STREAM) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     /* @var $dbEntry LiveStreamEntry */
     if ($dbEntry->getStreamPassword() != $token) {
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_INVALID_TOKEN, $entryId);
     }
     $mediaServer = $dbEntry->getMediaServer(true);
     if ($mediaServer) {
         $url = null;
         $protocol = null;
         foreach (array(KalturaPlaybackProtocol::HLS, KalturaPlaybackProtocol::APPLE_HTTP) as $hlsProtocol) {
             $config = $dbEntry->getLiveStreamConfigurationByProtocol($hlsProtocol, requestUtils::PROTOCOL_HTTP, null, true);
             if ($config) {
                 $url = $config->getUrl();
                 $protocol = $hlsProtocol;
                 break;
             }
         }
         if ($url) {
             KalturaLog::info('Determining status of live stream URL [' . $url . ']');
             $dpda = new DeliveryProfileDynamicAttributes();
             $dpda->setEntryId($entryId);
             $dpda->setFormat($protocol);
             $deliveryProfile = DeliveryProfilePeer::getLiveDeliveryProfileByHostName(parse_url($url, PHP_URL_HOST), $dpda);
             if ($deliveryProfile && $deliveryProfile->isLive($url)) {
                 throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_ALREADY_BROADCASTING, $entryId, $mediaServer->getHostname());
             }
         }
     }
     // fetch current stream live params
     $liveParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($dbEntry->getConversionProfileId());
     $usedLiveParamsIds = array();
     foreach ($liveParamsIds as $liveParamsId) {
         $usedLiveParamsIds[$liveParamsId] = array($entryId);
     }
     // fetch all live entries that currently are live
     $baseCriteria = KalturaCriteria::create(entryPeer::OM_CLASS);
     $filter = new entryFilter();
     $filter->setIsLive(true);
     $filter->setIdNotIn(array($entryId));
     $filter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE);
     $filter->attachToCriteria($baseCriteria);
     $entries = entryPeer::doSelect($baseCriteria);
     $maxInputStreams = $this->getPartner()->getMaxLiveStreamInputs();
     if (!$maxInputStreams) {
         $maxInputStreams = kConf::get('partner_max_live_stream_inputs', 'local', 10);
     }
     KalturaLog::debug("Max live stream inputs [{$maxInputStreams}]");
     $maxTranscodedStreams = 0;
     if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_KALTURA_LIVE_STREAM_TRANSCODE, $this->getPartnerId())) {
         $maxTranscodedStreams = $this->getPartner()->getMaxLiveStreamOutputs();
         if (!$maxTranscodedStreams) {
             $maxTranscodedStreams = kConf::get('partner_max_live_stream_outputs', 'local', 10);
         }
     }
     KalturaLog::debug("Max live stream outputs [{$maxTranscodedStreams}]");
     $totalInputStreams = count($entries) + 1;
     if ($totalInputStreams > $maxInputStreams + $maxTranscodedStreams) {
         KalturaLog::debug("Live input stream [{$totalInputStreams}]");
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_PASSTHRU, $entryId);
     }
     $entryIds = array($entryId);
     foreach ($entries as $liveEntry) {
         /* @var $liveEntry LiveEntry */
         $entryIds[] = $liveEntry->getId();
         $liveParamsIds = array_map('intval', explode(',', $liveEntry->getFlavorParamsIds()));
         foreach ($liveParamsIds as $liveParamsId) {
             if (isset($usedLiveParamsIds[$liveParamsId])) {
                 $usedLiveParamsIds[$liveParamsId][] = $liveEntry->getId();
             } else {
                 $usedLiveParamsIds[$liveParamsId] = array($liveEntry->getId());
             }
         }
     }
     $liveParams = assetParamsPeer::retrieveByPKs(array_keys($usedLiveParamsIds));
     $passthruEntries = null;
     $transcodedEntries = null;
     foreach ($liveParams as $liveParamsItem) {
         /* @var $liveParamsItem LiveParams */
         if ($liveParamsItem->hasTag(liveParams::TAG_INGEST)) {
             $passthruEntries = array_intersect(is_array($passthruEntries) ? $passthruEntries : $entryIds, $usedLiveParamsIds[$liveParamsItem->getId()]);
         } else {
             $transcodedEntries = array_intersect(is_array($transcodedEntries) ? $transcodedEntries : $entryIds, $usedLiveParamsIds[$liveParamsItem->getId()]);
         }
     }
     $passthruEntries = array_diff($passthruEntries, $transcodedEntries);
     $passthruEntriesCount = count($passthruEntries);
     $transcodedEntriesCount = count($transcodedEntries);
     KalturaLog::debug("Live transcoded entries [{$transcodedEntriesCount}], max live transcoded streams [{$maxTranscodedStreams}]");
     if ($transcodedEntriesCount > $maxTranscodedStreams) {
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_TRANSCODED, $entryId);
     }
     $maxInputStreams += $maxTranscodedStreams - $transcodedEntriesCount;
     KalturaLog::debug("Live params inputs [{$passthruEntriesCount}], max live stream inputs [{$maxInputStreams}]");
     if ($passthruEntriesCount > $maxInputStreams) {
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_PASSTHRU, $entryId);
     }
     $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType());
     $entry->fromObject($dbEntry, $this->getResponseProfile());
     return $entry;
 }
Пример #19
0
 /**
  * @param BatchJob $batchJob
  * @param entry $entry
  * @param string $flavorAssetId
  * @param string $inputFileSyncLocalPath
  * @return BatchJob
  */
 public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath)
 {
     KalturaLog::debug("Parent job [" . ($parentJob ? $parentJob->getId() : 'none') . "] entry [" . $entry->getId() . "] flavor asset [{$flavorAssetId}] input file [{$inputFileSyncLocalPath}]");
     if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) {
         $entry->setStatus(entryStatus::PENDING);
         $entry->save();
         KalturaLog::notice('Entry should not be converted');
         return null;
     }
     $importingSources = false;
     // if file size is 0, do not create conversion profile and set entry status as error converting
     if (!file_exists($inputFileSyncLocalPath) || kFile::fileSize($inputFileSyncLocalPath) == 0) {
         KalturaLog::debug("Input file [{$inputFileSyncLocalPath}] does not exist");
         $partner = $entry->getPartner();
         $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entry->getId());
         // load the asset params to the instance pool
         $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfile->getId());
         assetParamsPeer::retrieveByPKs($flavorIds);
         $conversionRequired = false;
         $sourceFileRequiredStorages = array();
         $sourceIncludedInProfile = false;
         $flavorAsset = assetPeer::retrieveById($flavorAssetId);
         $flavors = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfile->getId());
         KalturaLog::debug("Found flavors [" . count($flavors) . "] in conversion profile [" . $conversionProfile->getId() . "]");
         foreach ($flavors as $flavor) {
             /* @var $flavor flavorParamsConversionProfile */
             if ($flavor->getFlavorParamsId() == $flavorAsset->getFlavorParamsId()) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] is ingested source");
                 $sourceIncludedInProfile = true;
                 continue;
             }
             $flavorParams = assetParamsPeer::retrieveByPK($flavor->getFlavorParamsId());
             if ($flavorParams instanceof liveParams || $flavor->getOrigin() == assetParamsOrigin::INGEST) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] should be ingested");
                 continue;
             }
             if ($flavor->getOrigin() == assetParamsOrigin::CONVERT_WHEN_MISSING) {
                 $siblingFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor->getFlavorParamsId());
                 if ($siblingFlavorAsset) {
                     KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] already ingested");
                     continue;
                 }
             }
             $sourceFileRequiredStorages[] = $flavorParams->getSourceRemoteStorageProfileId();
             $conversionRequired = true;
             break;
         }
         if ($conversionRequired) {
             foreach ($sourceFileRequiredStorages as $storageId) {
                 if ($storageId == StorageProfile::STORAGE_KALTURA_DC) {
                     $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     list($syncFile, $local) = kFileSyncUtils::getReadyFileSyncForKey($key, true, false);
                     if ($syncFile && $syncFile->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) {
                         KalturaLog::debug("Creates import job for remote file sync");
                         $url = $syncFile->getExternalUrl($entry->getId());
                         kJobsManager::addImportJob($parentJob, $entry->getId(), $partner->getId(), $url, $flavorAsset, null, null, true);
                         $importingSources = true;
                         continue;
                     }
                 } elseif ($flavorAsset->getExternalUrl($storageId)) {
                     continue;
                 }
                 kBatchManager::updateEntry($entry->getId(), entryStatus::ERROR_CONVERTING);
                 $flavorAsset = assetPeer::retrieveById($flavorAssetId);
                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                 $flavorAsset->setDescription('Entry of size 0 should not be converted');
                 $flavorAsset->save();
                 KalturaLog::err('Entry of size 0 should not be converted');
                 return null;
             }
         } else {
             if ($flavorAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_QUEUED) {
                 if ($sourceIncludedInProfile) {
                     $flavorAsset->setStatusLocalReady();
                 } else {
                     $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED);
                     $flavorAsset->setDeletedAt(time());
                 }
                 $flavorAsset->save();
                 if ($sourceIncludedInProfile) {
                     kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset);
                 }
             }
             return null;
         }
     }
     if ($entry->getStatus() != entryStatus::READY) {
         $entry->setStatus(entryStatus::PRECONVERT);
     }
     $jobData = new kConvertProfileJobData();
     $jobData->setFlavorAssetId($flavorAssetId);
     $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath);
     $jobData->setExtractMedia(true);
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         $jobData->setExtractMedia(false);
         $entry->setCreateThumb(false);
     }
     $entry->save();
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::CONVERT_PROFILE);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entry->getId());
         $batchJob->setPartnerId($entry->getPartnerId());
         $batchJob->setUseNewRoot(true);
     }
     $batchJob->setObjectId($entry->getId());
     $batchJob->setObjectType(BatchJobObjectType::ENTRY);
     if ($importingSources) {
         $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     }
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE);
 }
 /**
  * Delete the relation of flavorParams <> conversionProfile2
  * 
  * @param conversionProfile2 $conversionProfileDb
  * @param string|array $notInFlavorIds comma sepeartaed id that should not be deleted
  */
 protected function deleteFlavorParamsRelation(conversionProfile2 $conversionProfileDb, $notInFlavorIds = null)
 {
     $c = new Criteria();
     $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfileDb->getId());
     if ($notInFlavorIds) {
         if (!is_array($notInFlavorIds)) {
             $notInFlavorIds = explode(',', $notInFlavorIds);
         }
         $c->add(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $notInFlavorIds, Criteria::NOT_IN);
     }
     flavorParamsConversionProfilePeer::doDelete($c);
 }
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(flavorParamsConversionProfilePeer::DATABASE_NAME);
     $criteria->add(flavorParamsConversionProfilePeer::ID, $this->id);
     if ($this->alreadyInSave && count($this->modifiedColumns) == 2 && $this->isColumnModified(flavorParamsConversionProfilePeer::UPDATED_AT)) {
         $theModifiedColumn = null;
         foreach ($this->modifiedColumns as $modifiedColumn) {
             if ($modifiedColumn != flavorParamsConversionProfilePeer::UPDATED_AT) {
                 $theModifiedColumn = $modifiedColumn;
             }
         }
         $atomicColumns = flavorParamsConversionProfilePeer::getAtomicColumns();
         if (in_array($theModifiedColumn, $atomicColumns)) {
             $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
         }
     }
     return $criteria;
 }
Пример #22
0
 public static function decideLiveProfile(LiveEntry $entry)
 {
     // find all live assets of the entry
     $c = new Criteria();
     $c->add(assetPeer::PARTNER_ID, $entry->getPartnerId());
     $c->add(assetPeer::ENTRY_ID, $entry->getId());
     $c->add(assetPeer::TYPE, assetType::LIVE);
     // include deleted assets
     assetPeer::setUseCriteriaFilter(false);
     $liveAssets = assetPeer::doSelect($c);
     assetPeer::setUseCriteriaFilter(true);
     // build array of all assets with asset params id as key
     $liveAssetsParams = array();
     foreach ($liveAssets as $liveAsset) {
         /* @var $liveAsset liveAsset */
         $flavorParamsId = is_null($liveAsset->getFlavorParamsId()) ? $liveAsset->getId() : $liveAsset->getFlavorParamsId();
         $liveAssetsParams[$flavorParamsId] = $liveAsset;
     }
     $flavorParamsConversionProfileArray = flavorParamsConversionProfilePeer::retrieveByConversionProfile($entry->getConversionProfileId());
     $liveParamIdsArray = array();
     foreach ($flavorParamsConversionProfileArray as $flavorParamsConversionProfile) {
         /* @var $flavorParamsConversionProfile flavorParamsConversionProfile */
         $liveParamIdsArray[] = $flavorParamsConversionProfile->getFlavorParamsId();
     }
     asort($liveParamIdsArray);
     $liveParamIds = implode(",", $liveParamIdsArray);
     if ($liveParamIds == $entry->getFlavorParamsIds()) {
         return;
     }
     $streamBitrates = array();
     $definedRecordingAnchor = false;
     foreach ($flavorParamsConversionProfileArray as $flavorParamsConversionProfile) {
         /* @var $flavorParamsConversionProfile flavorParamsConversionProfile */
         $liveParams = $flavorParamsConversionProfile->getassetParams();
         if ($liveParams instanceof liveParams) {
             if ($flavorParamsConversionProfile->getOrigin() == assetParamsOrigin::INGEST) {
                 $streamBitrate = array('bitrate' => $liveParams->getVideoBitrate(), 'width' => $liveParams->getWidth(), 'height' => $liveParams->getHeight(), 'tags' => $liveParams->getTags());
                 $streamBitrates[] = $streamBitrate;
             }
             // check if asset already exists
             if (isset($liveAssetsParams[$liveParams->getId()])) {
                 $liveAsset = $liveAssetsParams[$liveParams->getId()];
                 $liveAsset->setDeletedAt(null);
                 // remove the asset from the list, the left assets will be deleted later
                 unset($liveAssetsParams[$liveParams->getId()]);
             } else {
                 // create a new asset
                 $liveAsset = new liveAsset();
                 $liveAsset->setType(assetType::LIVE);
                 $liveAsset->setPartnerId($entry->getPartnerId());
                 $liveAsset->setFlavorParamsId($liveParams->getId());
                 $liveAsset->setFromAssetParams($liveParams);
                 $liveAsset->setEntryId($entry->getId());
                 if ($entry->getRecordStatus() && !$definedRecordingAnchor) {
                     // We specifically add a flag that does NOT exist on the live asset, since we can't predict which
                     // live params the conversion profile is going to contain.
                     $liveAsset->addTags(array(assetParams::TAG_RECORDING_ANCHOR));
                     $definedRecordingAnchor = true;
                 }
             }
             // set the status according to the entry status
             if ($entry->getStatus() == entryStatus::READY) {
                 $liveAsset->setStatus(asset::ASSET_STATUS_READY);
             } else {
                 $liveAsset->setStatus(asset::ASSET_STATUS_IMPORTING);
             }
             $liveAsset->save();
         }
     }
     // delete all left assets
     foreach ($liveAssetsParams as $liveAsset) {
         /* @var $liveAsset liveAsset */
         $liveAsset->setDeletedAt(time());
         $liveAsset->setStatus(asset::ASSET_STATUS_DELETED);
         $liveAsset->save();
     }
     if (!count($streamBitrates)) {
         $streamBitrate = array('bitrate' => 900, 'width' => 640, 'height' => 480);
         $streamBitrates[] = $streamBitrate;
     }
     $entry->setStreamBitrates($streamBitrates);
     $entry->save();
 }
Пример #23
0
 /**
  * @param BatchJob $parentJob
  * @param int $srcParamsId
  */
 public static function generateThumbnailsFromFlavor($entryId, BatchJob $parentJob = null, $srcParamsId = null)
 {
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     } catch (Exception $e) {
         KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage());
     }
     if (!$profile) {
         KalturaLog::notice("Profile not found for entry id [{$entryId}]");
         return;
     }
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         KalturaLog::notice("Entry id [{$entryId}] not found");
         return;
     }
     $assetParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($profile->getId());
     if (!count($assetParamsIds)) {
         KalturaLog::notice("No asset params objects found for profile id [" . $profile->getId() . "]");
         return;
     }
     // the alternative is the source or the highest bitrate if source not defined
     $alternateFlavorParamsId = null;
     if (is_null($srcParamsId)) {
         $flavorParamsObjects = flavorParamsPeer::retrieveByPKs($assetParamsIds);
         foreach ($flavorParamsObjects as $flavorParams) {
             if ($flavorParams->hasTag(flavorParams::TAG_SOURCE)) {
                 $alternateFlavorParamsId = $flavorParams->getId();
             }
         }
         if (is_null($alternateFlavorParamsId)) {
             $srcFlavorAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entryId);
             $alternateFlavorParamsId = $srcFlavorAsset->getFlavorParamsId();
         }
         if (is_null($alternateFlavorParamsId)) {
             KalturaLog::notice("No source flavor params object found for entry id [{$entryId}]");
             return;
         }
     }
     // create list of created thumbnails
     $thumbAssetsList = array();
     $thumbAssets = thumbAssetPeer::retrieveByEntryId($entryId);
     if (count($thumbAssets)) {
         foreach ($thumbAssets as $thumbAsset) {
             if (!is_null($thumbAsset->getFlavorParamsId())) {
                 $thumbAssetsList[$thumbAsset->getFlavorParamsId()] = $thumbAsset;
             }
         }
     }
     $thumbParamsObjects = thumbParamsPeer::retrieveByPKs($assetParamsIds);
     foreach ($thumbParamsObjects as $thumbParams) {
         // check if this thumbnail already created
         if (isset($thumbAssetsList[$thumbParams->getId()])) {
             continue;
         }
         if (is_null($srcParamsId) && is_null($thumbParams->getSourceParamsId())) {
             // alternative should be used
             $thumbParams->setSourceParamsId($alternateFlavorParamsId);
         } elseif ($thumbParams->getSourceParamsId() != $srcParamsId) {
             // only thumbnails that uses srcParamsId should be generated for now
             continue;
         }
         kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams, $parentJob);
     }
 }
Пример #24
0
 /**
  * @param int $conversionProfileId
  * @param $con
  * @return array<flavorParamsOutput>
  */
 public static function retrieveByProfile($conversionProfileId, $con = null)
 {
     $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfileId);
     $criteria = new Criteria();
     $criteria->add(assetParamsPeer::ID, $flavorIds, Criteria::IN);
     return assetParamsPeer::doSelect($criteria, $con);
 }
Пример #25
0
 public static function copyConversionProfiles(Partner $fromPartner, Partner $toPartner, $permissionRequiredOnly = false)
 {
     $copiedList = array();
     KalturaLog::log("Copying conversion profiles from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     $c = new Criteria();
     $c->add(conversionProfile2Peer::PARTNER_ID, $fromPartner->getId());
     $conversionProfiles = conversionProfile2Peer::doSelect($c);
     foreach ($conversionProfiles as $conversionProfile) {
         /* @var $conversionProfile conversionProfile2 */
         if ($permissionRequiredOnly && !count($conversionProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if (!self::isPartnerPermittedForCopy($toPartner, $conversionProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         $newConversionProfile = $conversionProfile->copy();
         $newConversionProfile->setPartnerId($toPartner->getId());
         try {
             $newConversionProfile->save();
         } catch (Exception $e) {
             KalturaLog::info("Exception occured, conversion profile was not copied. Message: [" . $e->getMessage() . "]");
             continue;
         }
         KalturaLog::log("Copied [" . $conversionProfile->getId() . "], new id is [" . $newConversionProfile->getId() . "]");
         $copiedList[$conversionProfile->getId()] = $newConversionProfile->getId();
         $c = new Criteria();
         $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
         $fpcpList = flavorParamsConversionProfilePeer::doSelect($c);
         foreach ($fpcpList as $fpcp) {
             $flavorParamsId = $fpcp->getFlavorParamsId();
             $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
             if ($flavorParams && $flavorParams->getPartnerId() === 0) {
                 $newFpcp = $fpcp->copy();
                 $newFpcp->setConversionProfileId($newConversionProfile->getId());
                 $newFpcp->save();
             }
         }
     }
     // make sure conversion profile is set on the new partner in case it was missed/skiped in the conversionProfile2::copy method
     if (!$toPartner->getDefaultConversionProfileId()) {
         $fromPartnerDefaultProfile = $fromPartner->getDefaultConversionProfileId();
         if ($fromPartnerDefaultProfile && key_exists($fromPartnerDefaultProfile, $copiedList)) {
             $toPartner->setDefaultConversionProfileId($copiedList[$fromPartnerDefaultProfile]);
         }
     }
     if (!$toPartner->getDefaultLiveConversionProfileId()) {
         $fromPartnerDefaultLiveProfile = $fromPartner->getDefaultLiveConversionProfileId();
         if ($fromPartnerDefaultLiveProfile && key_exists($fromPartnerDefaultLiveProfile, $copiedList)) {
             $toPartner->setDefaultLiveConversionProfileId($copiedList[$fromPartnerDefaultLiveProfile]);
         }
     }
     $toPartner->save();
 }
 /**
  * @param BatchJob $dbBatchJob
  * @param flavorAsset $currentFlavorAsset
  * @return BatchJob
  */
 public static function handleConvertFinished(BatchJob $dbBatchJob = null, flavorAsset $currentFlavorAsset)
 {
     KalturaLog::debug("entry id [" . $currentFlavorAsset->getEntryId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "]");
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($currentFlavorAsset->getEntryId());
         KalturaLog::debug("profile [" . $profile->getId() . "]");
     } catch (Exception $e) {
         KalturaLog::err($e->getMessage());
     }
     $currentReadyBehavior = self::getReadyBehavior($currentFlavorAsset, $profile);
     KalturaLog::debug("Current ready behavior [{$currentReadyBehavior}]");
     if ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
         return $dbBatchJob;
     }
     $rootBatchJob = null;
     if ($dbBatchJob) {
         $rootBatchJob = $dbBatchJob->getRootJob();
     }
     if ($rootBatchJob) {
         KalturaLog::debug("root batch job id [" . $rootBatchJob->getId() . "] type [" . $rootBatchJob->getJobType() . "]");
     }
     // update the root job end exit
     if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) {
         $siblingJobs = $rootBatchJob->getChildJobs();
         foreach ($siblingJobs as $siblingJob) {
             // checking only conversion child jobs
             if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::CONVERT_COLLECTION && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) {
                 continue;
             }
             // if not complete leave function
             if (!in_array($siblingJob->getStatus(), BatchJobPeer::getClosedStatusList())) {
                 KalturaLog::debug("job id [" . $siblingJob->getId() . "] status [" . $siblingJob->getStatus() . "]");
                 return $dbBatchJob;
             }
         }
         KalturaLog::debug("finish bulk download root job");
         // all child jobs completed
         kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         return $dbBatchJob;
     }
     $inheritedFlavorParamsIds = array();
     $requiredFlavorParamsIds = array();
     $flavorParamsConversionProfileItems = array();
     if ($profile) {
         $flavorParamsConversionProfileItems = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     }
     foreach ($flavorParamsConversionProfileItems as $flavorParamsConversionProfile) {
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_NO_IMPACT) {
             $inheritedFlavorParamsIds[] = $flavorParamsConversionProfile->getFlavorParamsId();
         }
     }
     $flavorParamsItems = assetParamsPeer::retrieveByPKs($inheritedFlavorParamsIds);
     foreach ($flavorParamsItems as $flavorParams) {
         if ($flavorParams->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     // go over all the flavor assets of the entry
     $inCompleteFlavorIds = array();
     $origianlAssetFlavorId = null;
     $siblingFlavorAssets = assetPeer::retrieveFlavorsByEntryId($currentFlavorAsset->getEntryId());
     foreach ($siblingFlavorAssets as $siblingFlavorAsset) {
         KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] flavor params id [" . $siblingFlavorAsset->getFlavorParamsId() . "]");
         // don't mark any incomplete flag
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ready");
             if (isset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()])) {
                 unset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()]);
             }
             continue;
         }
         $readyBehavior = self::getReadyBehavior($siblingFlavorAsset, $profile);
         if ($siblingFlavorAsset->getStatus() == flavorAsset::ASSET_STATUS_EXPORTING) {
             if ($siblingFlavorAsset->getIsOriginal()) {
                 $origianlAssetFlavorId = $siblingFlavorAsset->getFlavorParamsId();
             } else {
                 if ($readyBehavior != flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
                     KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
                     $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
                 }
             }
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ignored");
             continue;
         }
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_QUEUED || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
             $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is required");
             $requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("left required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     KalturaLog::debug("left incomplete flavor ids [" . print_r($inCompleteFlavorIds, true) . "]");
     if (count($requiredFlavorParamsIds)) {
         $inCompleteRequiredFlavorParamsIds = array_keys($requiredFlavorParamsIds);
         foreach ($inCompleteRequiredFlavorParamsIds as $inCompleteFlavorId) {
             $inCompleteFlavorIds[] = $inCompleteFlavorId;
         }
         KalturaLog::debug('Convert Finished - has In-Complete Required flavors [[' . print_r($inCompleteRequiredFlavorParamsIds, true) . ']');
     } elseif ($currentFlavorAsset->getStatus() == asset::ASSET_STATUS_READY && ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL || $currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED)) {
         // mark the entry as ready if all required conversions completed or any of the optionals
         if ($currentFlavorAsset->getentry()->getReplacedEntryId()) {
             KalturaLog::debug('Entry is temporary replacement and requires all flavors to complete');
         } else {
             KalturaLog::debug('Mark the entry as ready');
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
         }
     }
     if ($origianlAssetFlavorId) {
         $inCompleteFlavorIds = array_diff($inCompleteFlavorIds, array($origianlAssetFlavorId));
     }
     if (!count($inCompleteFlavorIds)) {
         KalturaLog::debug('Convert Finished');
         if ($origianlAssetFlavorId && $rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
             kStorageExporter::exportSourceAssetFromJob($rootBatchJob);
         } else {
             // mark the context root job as finished only if all conversion jobs are completed
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
             if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
                 kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
             }
         }
         return $dbBatchJob;
     }
     KalturaLog::debug('Convert Finished - has In-Complete flavors [' . print_r($inCompleteFlavorIds, true) . ']');
     if (!$rootBatchJob || $rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         return $dbBatchJob;
     }
     $childJobs = $rootBatchJob->getChildJobs();
     KalturaLog::debug('Child jobs found [' . count($childJobs) . ']');
     if (count($childJobs) > 1) {
         $allDone = true;
         foreach ($childJobs as $childJob) {
             if ($childJob->getId() != $rootBatchJob->getId() && $childJob->getStatus() != BatchJob::BATCHJOB_STATUS_FINISHED) {
                 KalturaLog::debug('Child job id [' . $childJob->getId() . '] status [' . $childJob->getStatus() . ']');
                 $allDone = false;
             }
         }
         if ($allDone) {
             KalturaLog::debug('All child jobs done, closing profile');
             kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         }
     }
     return $dbBatchJob;
 }
Пример #27
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         KalturaLog::err("No flavors created: {$errDescription}");
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     $dynamicFlavorAttributes = $entry->getDynamicFlavorAttributes();
     // gets the flavor params by the id
     $flavors = flavorParamsPeer::retrieveByPKs($flavorsIds);
     foreach ($flavors as $index => $flavor) {
         if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
             unset($flavors[$index]);
             continue;
         }
         if (isset($dynamicFlavorAttributes[$flavor->getId()])) {
             foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
     }
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo);
 }
<?php

require_once __DIR__ . '/../bootstrap.php';
if ($argc == 3) {
    $flavor_param_id = $argv[1];
    $conversion_profile_id = $argv[2];
} else {
    die('usage: php ' . $_SERVER['SCRIPT_NAME'] . " [flavor_param_id] [conversion profile id]" . PHP_EOL);
}
$conversion_flavor = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavor_param_id, $conversion_profile_id);
if (!$conversion_flavor) {
    die('no such flavor param id and conversion profile id.' . PHP_EOL);
}
$conversion = conversionProfile2Peer::retrieveByPK($conversion_profile_id);
$input_tags_maps = $conversion->getInputTagsMap();
if (strpos($input_tags_maps, ",mbr") === false) {
    $input_tags_maps .= ",mbr";
    $conversion->setInputTagsMap($input_tags_maps);
    $conversion->save();
}
$conversion_flavor->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL);
$conversion_flavor->save();
echo "Done.";
Пример #29
0
 /**
  * Handles drop folder file status change to PENDING
  * 1. set parsed slug and flavor
  * 2. in case there is no parsed flavor (no related files) - add ContentProcessor job
  * 3. otherwise
  * 	a. verify all required flavors are ready 
  *	b. if yes - add content processor 
  *	c. else - change files status to WAITING
  * @param DropFolder $folder
  * @param DropFolderFile $file
  */
 private function onContentDropFolderFileStatusChangedToPending(DropFolder $folder, DropFolderFile $file)
 {
     $updatedFile = $this->setParsedSlugFlavor($folder, $file);
     if ($updatedFile) {
         $file = $updatedFile;
         if (is_null($file->getParsedFlavor())) {
             KalturaLog::log('Parsed flavor is null, triggering ContentProcessing job for source');
             $this->triggerContentDropFolderFileProcessing($folder, $file);
         } else {
             $assetParamsList = flavorParamsConversionProfilePeer::retrieveByConversionProfile($folder->getConversionProfileId());
             $flavorNameValid = $this->validateFlavorName($file, $assetParamsList);
             if ($flavorNameValid) {
                 KalturaLog::log('Parsed flavor is set, verifying if all files ready');
                 $statuses = array(DropFolderFileStatus::PENDING, DropFolderFileStatus::WAITING, DropFolderFileStatus::NO_MATCH);
                 $relatedFiles = DropFolderFilePeer::retrieveByDropFolderIdStatusesAndSlug($folder->getId(), $statuses, $file->getParsedSlug());
                 $isReady = $this->isAllContentDropFolderIngestedFilesReady($folder, $relatedFiles, $assetParamsList);
                 if ($isReady) {
                     $this->triggerContentDropFolderFileProcessing($folder, $file, $relatedFiles);
                 } else {
                     $file->setStatus(DropFolderFileStatus::WAITING);
                     $file->save();
                 }
             }
         }
     } else {
         $this->setFileError($file, DropFolderFileStatus::ERROR_HANDLING, DropFolderFileErrorCode::SLUG_REGEX_NO_MATCH, DropFolderPlugin::SLUG_REGEX_NO_MATCH_MESSAGE);
     }
 }
 public function getFieldNameFromPeer($field_name)
 {
     $res = flavorParamsConversionProfilePeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
     return $res;
 }