/**
  * 
  * Sets the default thumb for the assets 
  * If others already exists then we don't set the asset as not default
  * @param thumbAsset $thumbAsset
  */
 protected static function setIsDefaultThumb(thumbAsset $thumbAsset)
 {
     $entryThumbAssets = assetPeer::retrieveThumbnailsByEntryId($thumbAsset->getEntryId());
     foreach ($entryThumbAssets as $entryThumbAsset) {
         //if we found another asset with a defualt tag. we remove our default tag
         if ($entryThumbAsset->getId() !== $thumbAsset->getId() && $entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
             KalturaLog::debug("Found default tag on thumbAsset id[" . $entryThumbAsset->getId() . "]");
             $thumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB));
             KalturaLog::debug("Removed default tag from thumbAsset id[" . $thumbAsset->getId() . "]");
             return;
         }
     }
 }
 /**
  * @action addFromImage
  * @param string $entryId
  * @param file $fileData
  * @return KalturaThumbAsset
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @validateUser entry entryId edit
  */
 public function addFromImageAction($entryId, $fileData)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $ext = pathinfo($fileData["name"], PATHINFO_EXTENSION);
     $dbThumbAsset = new thumbAsset();
     $dbThumbAsset->setPartnerId($dbEntry->getPartnerId());
     $dbThumbAsset->setEntryId($dbEntry->getId());
     $dbThumbAsset->setStatus(thumbAsset::ASSET_STATUS_QUEUED);
     $dbThumbAsset->setFileExt($ext);
     $dbThumbAsset->incrementVersion();
     $dbThumbAsset->save();
     $syncKey = $dbThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($fileData["tmp_name"], $syncKey);
     $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     list($width, $height, $type, $attr) = getimagesize($finalPath);
     $dbThumbAsset->setWidth($width);
     $dbThumbAsset->setHeight($height);
     $dbThumbAsset->setSize(filesize($finalPath));
     $dbThumbAsset->setStatus(thumbAsset::ASSET_STATUS_READY);
     $dbThumbAsset->save();
     $dbEntryThumbs = assetPeer::retrieveThumbnailsByEntryId($entryId);
     //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 && count($dbEntryThumbs) == 1)) {
         $this->setAsDefaultAction($dbThumbAsset->getId());
     }
     $thumbAssets = new KalturaThumbAsset();
     $thumbAssets->fromObject($dbThumbAsset);
     return $thumbAssets;
 }
Exemplo n.º 3
0
 public static function removeThumbAssetDeafultTags($entryID, $thumbAssetId = null)
 {
     $entryThumbAssets = assetPeer::retrieveThumbnailsByEntryId($entryID);
     foreach ($entryThumbAssets as $entryThumbAsset) {
         if ($thumbAssetId && $entryThumbAsset->getId() == $thumbAssetId) {
             continue;
         }
         if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
             continue;
         }
         $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB));
         $entryThumbAsset->save();
     }
 }
Exemplo n.º 4
0
 /**
  * @param BatchJob $parentJob
  * @param int $srcParamsId
  */
 public static function generateThumbnailsFromFlavor($entryId, BatchJob $parentJob = null, $srcParamsId = null)
 {
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         KalturaLog::notice("Entry id [{$entryId}] not found");
         return;
     }
     if ($entry->getType() != entryType::MEDIA_CLIP || $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO) {
         KalturaLog::notice("Cupture thumbnail is not supported for entry [{$entryId}] of type [" . $entry->getType() . "] and media type [" . $entry->getMediaType() . "]");
         return;
     }
     $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;
     }
     $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 = assetParamsPeer::retrieveFlavorsByPKs($assetParamsIds);
         foreach ($flavorParamsObjects as $flavorParams) {
             if ($flavorParams->hasTag(flavorParams::TAG_SOURCE)) {
                 $alternateFlavorParamsId = $flavorParams->getId();
             }
         }
         if (is_null($alternateFlavorParamsId)) {
             $srcFlavorAsset = assetPeer::retrieveHighestBitrateByEntryId($entryId);
             if ($srcFlavorAsset) {
                 $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 = assetPeer::retrieveThumbnailsByEntryId($entryId);
     if (count($thumbAssets)) {
         foreach ($thumbAssets as $thumbAsset) {
             if (!is_null($thumbAsset->getFlavorParamsId())) {
                 $thumbAssetsList[$thumbAsset->getFlavorParamsId()] = $thumbAsset;
             }
         }
     }
     $thumbParamsObjects = assetParamsPeer::retrieveThumbnailsByPKs($assetParamsIds);
     foreach ($thumbParamsObjects as $thumbParams) {
         if (isset($thumbAssetsList[$thumbParams->getId()])) {
             KalturaLog::log("Thumbnail asset already created [" . $thumbAssetsList[$thumbParams->getId()]->getId() . "]");
             continue;
         }
         if (is_null($srcParamsId) && is_null($thumbParams->getSourceParamsId())) {
             // alternative should be used
             $thumbParams->setSourceParamsId($alternateFlavorParamsId);
         } elseif ($thumbParams->getSourceParamsId() != $srcParamsId) {
             KalturaLog::log("Only thumbnails that uses source params [{$srcParamsId}] should be generated for now");
             continue;
         }
         kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams, $parentJob);
     }
 }
 public static function setAsDefaultThumbAsset($thumbAsset)
 {
     /* @var $thumbAsset thumbAsset */
     $entry = $thumbAsset->getentry();
     if (!$entry) {
         throw new kCoreException("Could not retrieve entry ID [" . $thumbAsset->getEntryId() . "] from ThumbAsset ID [" . $thumbAsset->getId() . "]", KalturaErrors::ENTRY_ID_NOT_FOUND);
     }
     $entryThumbAssets = assetPeer::retrieveThumbnailsByEntryId($thumbAsset->getEntryId());
     foreach ($entryThumbAssets as $entryThumbAsset) {
         if ($entryThumbAsset->getId() == $thumbAsset->getId()) {
             continue;
         }
         if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
             continue;
         }
         $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB));
         $entryThumbAsset->save();
     }
     if (!$thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
         /* @var $thumbAsset KalturaThumbAsset */
         $thumbAsset->addTags(array(thumbParams::TAG_DEFAULT_THUMB));
         $thumbAsset->save();
         KalturaLog::debug("Setting entry [" . $thumbAsset->getEntryId() . "] default ThumbAsset to [" . $thumbAsset->getId() . "]");
     }
     $entry->setThumbnail(".jpg");
     $entry->setCreateThumb(false);
     $entry->save();
     $thumbSyncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $thumbSyncKey);
 }