public function validateEntry(entry $dbEntry) { parent::validateEntry($dbEntry); $this->validatePropertyNotNull('resources'); $dc = null; foreach ($this->resources as $resource) { $resource->validateEntry($dbEntry); if (!$resource instanceof KalturaDataCenterContentResource) { continue; } $theDc = $resource->getDc(); if (is_null($theDc)) { continue; } if (is_null($dc)) { $dc = $theDc; } elseif ($dc != $theDc) { throw new KalturaAPIException(KalturaErrors::RESOURCES_MULTIPLE_DATA_CENTERS); } } if (!is_null($dc) && $dc != kDataCenterMgr::getCurrentDcId()) { $remoteHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($dc); kFileUtils::dumpApiRequest($remoteHost); } }
/** * Creates perioding metadata sync-point events on a live stream * * @action createPeriodicSyncPoints * @actionAlias liveStream.createPeriodicSyncPoints * @param string $entryId Kaltura live-stream entry id * @param int $interval Events interval in seconds * @param int $duration Duration in seconds * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::NO_MEDIA_SERVER_FOUND * @throws KalturaErrors::MEDIA_SERVER_SERVICE_NOT_FOUND */ function createPeriodicSyncPoints($entryId, $interval, $duration) { $entryDc = substr($entryId, 0, 1); if ($entryDc != kDataCenterMgr::getCurrentDcId()) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($entryDc); kFileUtils::dumpApiRequest($remoteDCHost, true); } $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::LIVE_STREAM || !in_array($dbEntry->getSource(), array(KalturaSourceType::LIVE_STREAM, KalturaSourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } /* @var $dbEntry LiveStreamEntry */ $mediaServers = $dbEntry->getMediaServers(); if (!count($mediaServers)) { throw new KalturaAPIException(KalturaErrors::NO_MEDIA_SERVER_FOUND, $entryId); } foreach ($mediaServers as $key => $kMediaServer) { if ($kMediaServer && $kMediaServer instanceof kLiveMediaServer) { $mediaServer = $kMediaServer->getMediaServer(); $mediaServerCuePointsService = $mediaServer->getWebService(MediaServer::WEB_SERVICE_CUE_POINTS); KalturaLog::debug("Sending sync points for DC [" . $mediaServer->getDc() . "] "); if ($mediaServerCuePointsService && $mediaServerCuePointsService instanceof KalturaMediaServerCuePointsService) { KalturaLog::debug("Call createTimeCuePoints on DC [" . $mediaServer->getDc() . "] "); $mediaServerCuePointsService->createTimeCuePoints($entryId, $interval, $duration); } else { KalturaLog::debug("Media server service not found on DC: [" . $mediaServer->getDc() . "] "); } } } }
function dumpApiRequest($entryId, $onlyIfAvailable = true) { $entryDc = substr($entryId, 0, 1); if ($entryDc != kDataCenterMgr::getCurrentDcId()) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($entryDc); kFileUtils::dumpApiRequest($remoteDCHost, $onlyIfAvailable); } }
public function validateEntry(entry $dbEntry) { parent::validateEntry($dbEntry); $dc = $this->getDc(); if ($dc == kDataCenterMgr::getCurrentDcId()) { return; } $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($dc); if ($remoteDCHost) { kFile::dumpApiRequest($remoteDCHost); } throw new KalturaAPIException(KalturaErrors::REMOTE_DC_NOT_FOUND, $dc); }
public function validateForUsage($sourceObject, $propertiesToSkip = array()) { parent::validateForUsage($sourceObject, $propertiesToSkip); $dc = $this->getDc(); if ($dc == kDataCenterMgr::getCurrentDcId()) { return; } $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($dc); if ($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } throw new KalturaAPIException(KalturaErrors::REMOTE_DC_NOT_FOUND, $dc); }
/** * will create thumbnail according to the entry type * @return the thumbnail path. */ public function getLocalThumbFilePath($version, $width, $height, $type, $bgcolor = "ffffff", $crop_provider = null, $quality = 0, $src_x = 0, $src_y = 0, $src_w = 0, $src_h = 0, $vid_sec = -1, $vid_slice = 0, $vid_slices = -1, $density = 0, $stripProfiles = false, $flavorId = null, $fileName = null) { $contentPath = myContentStorage::getFSContentRootPath(); // if entry type is audio - serve generic thumb: if ($this->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) { if ($this->getStatus() == entryStatus::DELETED || $this->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK) { KalturaLog::log("rejected audio entry - not serving thumbnail"); KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED); } $audioEntryExist = false; $audioThumbEntry = null; $audioThumbEntryId = null; $partner = $this->getPartner(); if ($partner) { $audioThumbEntryId = $partner->getAudioThumbEntryId(); } if ($audioThumbEntryId) { $audioThumbEntry = entryPeer::retrieveByPK($audioThumbEntryId); } if ($audioThumbEntry && $audioThumbEntry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $fileSyncVersion = $partner->getAudioThumbEntryVersion(); $audioEntryKey = $audioThumbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $fileSyncVersion); $contentPath = kFileSyncUtils::getLocalFilePathForKey($audioEntryKey); if ($contentPath) { $msgPath = $contentPath; $audioEntryExist = true; } else { KalturaLog::err('no local file sync for entry id'); } } if (!$audioEntryExist) { $msgPath = $contentPath . "content/templates/entry/thumbnail/audio_thumb.jpg"; } return myEntryUtils::resizeEntryImage($this, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $msgPath, $density, $stripProfiles); } elseif ($this->getMediaType() == entry::ENTRY_MEDIA_TYPE_SHOW) { // roughcut without any thumbnail, probably just created $msgPath = $contentPath . "content/templates/entry/thumbnail/auto_edit.jpg"; return myEntryUtils::resizeEntryImage($this, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $msgPath, $density, $stripProfiles); } elseif ($this->getType() == entryType::MEDIA_CLIP) { try { return myEntryUtils::resizeEntryImage($this, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices); } catch (Exception $ex) { if ($ex->getCode() == kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) { // get original flavor asset $origFlavorAsset = assetPeer::retrieveOriginalByEntryId($this->getId()); if ($origFlavorAsset) { $syncKey = $origFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); list($readyFileSync, $isLocal) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, TRUE, FALSE); if ($readyFileSync) { if ($isLocal) { KalturaLog::err('Trying to redirect to myself - stop here.'); KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } //Ready fileSync is on the other DC - dumping kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId())); } KalturaLog::err('No ready fileSync found on any DC.'); KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } } } } }
/** * * Will serve a requested report * @action serveReport * * * @param string $id - the requested id * @return string */ public function serveReportAction($id) { $fileNameRegex = "/^(?<dc>[01]+)_(?<fileName>\\d+_Export_[a-zA-Z0-9]+_[\\w\\-]+.csv)\$/"; // KS verification - we accept either admin session or download privilege of the file $ks = $this->getKs(); if (!$ks || !($ks->isAdmin() || $ks->verifyPrivileges(ks::PRIVILEGE_DOWNLOAD, $id))) { KExternalErrors::dieError(KExternalErrors::ACCESS_CONTROL_RESTRICTED); } if (!preg_match($fileNameRegex, $id, $matches)) { KalturaLog::err("Report Id Format doesn't match the file name format"); throw new KalturaAPIException(KalturaErrors::REPORT_NOT_FOUND, $id); } // Check if the request should be handled by the other DC $curerntDc = kDataCenterMgr::getCurrentDcId(); if ($matches['dc'] == 1 - $curerntDc) { kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - $curerntDc)); } // Serve report $filePath = $this->getReportDirectory($this->getPartnerId()) . DIRECTORY_SEPARATOR . $matches['fileName']; return $this->dumpFile($filePath, 'text/csv'); }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2; requestUtils::handleConditionalGet(); ignore_user_abort(); $entry_id = $this->getRequestParameter("entry_id"); $widget_id = $this->getRequestParameter("widget_id", 0); $upload_token_id = $this->getRequestParameter("upload_token_id"); $version = $this->getIntRequestParameter("version", null, 0, 10000000); $type = $this->getIntRequestParameter("type", 1, 1, 5); //Hack: if KMS sends thumbnail request containing "!" char, the type should be treated as 5. $width = $this->getRequestParameter("width", -1); $height = $this->getRequestParameter("height", -1); if (strpos($width, "!") || strpos($height, "!")) { $type = 5; } $width = $this->getFloatRequestParameter("width", -1, -1, 10000); $height = $this->getFloatRequestParameter("height", -1, -1, 10000); $crop_provider = $this->getRequestParameter("crop_provider", null); $quality = $this->getIntRequestParameter("quality", 0, 0, 100); $src_x = $this->getFloatRequestParameter("src_x", 0, 0, 10000); $src_y = $this->getFloatRequestParameter("src_y", 0, 0, 10000); $src_w = $this->getFloatRequestParameter("src_w", 0, 0, 10000); $src_h = $this->getFloatRequestParameter("src_h", 0, 0, 10000); $vid_sec = $this->getFloatRequestParameter("vid_sec", -1, -1); $vid_slice = $this->getRequestParameter("vid_slice", -1); $vid_slices = $this->getRequestParameter("vid_slices", -1); $density = $this->getFloatRequestParameter("density", 0, 0); $stripProfiles = $this->getRequestParameter("strip", null); $flavor_id = $this->getRequestParameter("flavor_id", null); $file_name = $this->getRequestParameter("file_name", null); $file_name = basename($file_name); // actual width and height of image from which the src_* values were taken. // these will be used to multiply the src_* parameters to make them relate to the original image size. $rel_width = $this->getFloatRequestParameter("rel_width", -1, -1, 10000); $rel_height = $this->getFloatRequestParameter("rel_height", -1, -1, 10000); if ($width == -1 && $height == -1) { $width = 120; $height = 90; } else { if ($width == -1) { // if only either width or height is missing reset them to zero, and convertImage will handle them $width = 0; } else { if ($height == -1) { $height = 0; } } } $bgcolor = $this->getRequestParameter("bgcolor", "ffffff"); $partner = null; // validating the inputs if (!is_numeric($quality) || $quality < 0 || $quality > 100) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'quality must be between 20 and 100'); } if (!is_numeric($src_x) || $src_x < 0 || $src_x > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_x must be between 0 and 10000'); } if (!is_numeric($src_y) || $src_y < 0 || $src_y > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_y must be between 0 and 10000'); } if (!is_numeric($src_w) || $src_w < 0 || $src_w > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_w must be between 0 and 10000'); } if (!is_numeric($src_h) || $src_h < 0 || $src_h > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_h must be between 0 and 10000'); } if (!is_numeric($width) || $width < 0 || $width > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'width must be between 0 and 10000'); } if (!is_numeric($height) || $height < 0 || $height > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'height must be between 0 and 10000'); } if (!is_numeric($density) || $density < 0) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'density must be positive'); } if (!is_numeric($vid_sec) || $vid_sec < -1) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'vid_sec must be positive'); } if (!preg_match('/^[0-9a-fA-F]{1,6}$/', $bgcolor)) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'bgcolor must be six hexadecimal characters'); } if ($upload_token_id) { $upload_token = UploadTokenPeer::retrieveByPK($upload_token_id); if ($upload_token) { $partnerId = $upload_token->getPartnerId(); $partner = PartnerPeer::retrieveByPK($partnerId); if ($density == 0) { $density = $partner->getDefThumbDensity(); } if (is_null($stripProfiles)) { $stripProfiles = $partner->getStripThumbProfile(); } $thumb_full_path = myContentStorage::getFSCacheRootPath() . myContentStorage::getGeneralEntityPath("uploadtokenthumb", $upload_token->getIntId(), $upload_token->getId(), $upload_token->getId() . ".jpg"); kFile::fullMkdir($thumb_full_path); if (file_exists($upload_token->getUploadTempPath())) { $src_full_path = $upload_token->getUploadTempPath(); $valid_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_WBMP); $image_type = exif_imagetype($src_full_path); if (!in_array($image_type, $valid_image_types)) { // capture full frame myFileConverter::captureFrame($src_full_path, $thumb_full_path, 1, "image2", -1, -1, 3); if (!file_exists($thumb_full_path)) { myFileConverter::captureFrame($src_full_path, $thumb_full_path, 1, "image2", -1, -1, 0); } $src_full_path = $thumb_full_path; } // and resize it myFileConverter::convertImage($src_full_path, $thumb_full_path, $width, $height, $type, $bgcolor, true, $quality, $src_x, $src_y, $src_w, $src_h, $density, $stripProfiles); kFile::dumpFile($thumb_full_path); } else { KalturaLog::debug("token_id [{$upload_token_id}] not found in DC [" . kDataCenterMgr::getCurrentDcId() . "]. dump url to romote DC"); $remoteUrl = kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()) . $_SERVER['REQUEST_URI']; kFile::dumpUrl($remoteUrl); } } } if ($entry_id) { $entry = entryPeer::retrieveByPKNoFilter($entry_id); if (!$entry) { // problem could be due to replication lag kFile::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId())); } } else { // get the widget $widget = widgetPeer::retrieveByPK($widget_id); if (!$widget) { KExternalErrors::dieError(KExternalErrors::ENTRY_AND_WIDGET_NOT_FOUND); } // get the kshow $kshow_id = $widget->getKshowId(); $kshow = kshowPeer::retrieveByPK($kshow_id); if ($kshow) { $entry_id = $kshow->getShowEntryId(); } else { $entry_id = $widget->getEntryId(); } $entry = entryPeer::retrieveByPKNoFilter($entry_id); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } $partner = $entry->getPartner(); if ($density == 0) { $density = $partner->getDefThumbDensity(); } $thumbParams = new kThumbnailParameters(); $thumbParams->setSupportAnimatedThumbnail($partner->getSupportAnimatedThumbnails()); if (is_null($stripProfiles)) { $stripProfiles = $partner->getStripThumbProfile(); } //checks whether the thumbnail display should be restricted by KS $base64Referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($base64Referrer); if (!is_string($referrer)) { $referrer = ""; } // base64_decode can return binary data if (!$referrer) { $referrer = kApiCache::getHttpReferrer(); } $ksStr = $this->getRequestParameter("ks"); $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer, accessControlContextType::THUMBNAIL); $securyEntryHelper->validateForPlay(); // multiply the passed $src_* values so that they will relate to the original image size, according to $src_display_* if ($rel_width != -1) { $widthRatio = $entry->getWidth() / $rel_width; $src_x = $src_x * $widthRatio; $src_w = $src_w * $widthRatio; } if ($rel_height != -1) { $heightRatio = $entry->getHeight() / $rel_height; $src_y = $src_y * $heightRatio; $src_h = $src_h * $heightRatio; } $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB; if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA; } KalturaLog::debug("get thumbnail filesyncs"); $dataKey = $entry->getSyncKey($subType); list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($dataKey, true, false); $tempThumbPath = null; $entry_status = $entry->getStatus(); // both 640x480 and 0x0 requests are probably coming from the kdp // 640x480 - old kdp version requesting thumbnail // 0x0 - new kdp version requesting the thumbnail of an unready entry // we need to distinguish between calls from the kdp and calls from a browser: <img src=...> // that can't handle swf input if (($width == 640 && $height == 480 || $width == 0 && $height == 0) && ($entry_status == entryStatus::PRECONVERT || $entry_status == entryStatus::IMPORT || $entry_status == entryStatus::ERROR_CONVERTING || $entry_status == entryStatus::DELETED)) { $contentPath = myContentStorage::getFSContentRootPath(); $msgPath = $contentPath . "content/templates/entry/bigthumbnail/"; if ($entry_status == entryStatus::DELETED) { $msgPath .= $entry->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK ? "entry_blocked.swf" : "entry_deleted.swf"; } else { $msgPath .= $entry_status == entryStatus::ERROR_CONVERTING ? "entry_error.swf" : "entry_converting.swf"; } kFile::dumpFile($msgPath, null, 0); } if (!$file_sync) { $tempThumbPath = $entry->getLocalThumbFilePath($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $density, $stripProfiles, $flavor_id, $file_name); if (!$tempThumbPath) { KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } } if (!$local && !$tempThumbPath && $file_sync) { if (!in_array($file_sync->getDc(), kDataCenterMgr::getDcIds())) { $remoteUrl = $file_sync->getExternalUrl($entry->getId()); header("Location: {$remoteUrl}"); die; } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($file_sync, $_SERVER['REQUEST_URI']); kFile::dumpUrl($remoteUrl); } // if we didnt return a template for the player die and dont return the original deleted thumb if ($entry_status == entryStatus::DELETED) { KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED); } if (!$tempThumbPath) { try { $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, null, $density, $stripProfiles, $thumbParams); } catch (Exception $ex) { if ($ex->getCode() != kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) { KalturaLog::log("Error - resize image failed"); KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } // get original flavor asset $origFlavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id); if (!$origFlavorAsset) { KalturaLog::log("Error - no original flavor for entry [{$entry_id}]"); KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $syncKey = $origFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $remoteFileSync = kFileSyncUtils::getOriginFileSyncForKey($syncKey, false); if (!$remoteFileSync) { // file does not exist on any DC - die KalturaLog::log("Error - no FileSync for entry [{$entry_id}]"); KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } if ($remoteFileSync->getDc() == kDataCenterMgr::getCurrentDcId()) { KalturaLog::log("ERROR - Trying to redirect to myself - stop here."); KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } if (!in_array($remoteFileSync->getDc(), kDataCenterMgr::getDcIds())) { KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($remoteFileSync); kFile::dumpUrl($remoteUrl); } } $nocache = strpos($tempThumbPath, "_NOCACHE_") !== false; if ($securyEntryHelper->shouldDisableCache() || kApiCache::hasExtraFields() || !$securyEntryHelper->isKsWidget() && $securyEntryHelper->hasRules()) { $nocache = true; } // notify external proxy, so it'll cache this url if (!$nocache && requestUtils::getHost() == kConf::get("apphome_url") && file_exists($tempThumbPath)) { self::notifyProxy($_SERVER["REQUEST_URI"]); } // cache result if (!$nocache) { $requestKey = $_SERVER["REQUEST_URI"]; $cache = new myCache("thumb", 86400 * 30); // 30 days $cache->put($requestKey, $tempThumbPath); } kFile::dumpFile($tempThumbPath, null, $nocache ? 0 : null); // TODO - can delete from disk assuming we caneasily recreate it and it will anyway be cached in the CDN // however dumpfile dies at the end so we cant just write it here (maybe register a shutdown callback) }
/** * Update media entry. Only the properties that were set will be updated. * * @action update * @param string $entryId Media entry id to update * @param KalturaMediaEntry $mediaEntry Media entry metadata to update * @return KalturaMediaEntry The updated media entry * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @validateUser entry entryId edit */ function updateAction($entryId, KalturaMediaEntry $mediaEntry) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { $dcIndex = kDataCenterMgr::getDCByObjectId($entryId, true); if ($dcIndex != kDataCenterMgr::getCurrentDcId()) { KalturaLog::debug("EntryID [{$entryId}] wasn't found on current DC. dumping the request to DC id [{$dcIndex}]"); kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId($dcIndex)); } } if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MEDIA_CLIP) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $mediaEntry = $this->updateEntry($entryId, $mediaEntry, KalturaEntryType::MEDIA_CLIP); return $mediaEntry; }
/** * get DC host for remote upload token * * @param $uploadTokenId * @param $localDcId * @return string */ public static function getRemoteHostForUploadToken($uploadTokenId, $localDcId = null) { $uploadToken = UploadTokenPeer::retrieveByPK($uploadTokenId); if (!$uploadToken) { return FALSE; } if ($localDcId !== null && $localDcId == $uploadToken->getDc()) { // return FALSE if token's DC is not remote, but the same as $localDcId return FALSE; } return kDataCenterMgr::getRemoteDcExternalUrlByDcId($uploadToken->getDc()); }
/** * Generic add entry using an uploaded file, should be used when the uploaded entry type is not known. * * @action addFromUploadedFile * @param KalturaBaseEntry $entry * @param string $uploadTokenId * @param KalturaEntryType $type * @return KalturaBaseEntry */ function addFromUploadedFileAction(KalturaBaseEntry $entry, $uploadTokenId, $type = -1) { try { // check that the uploaded file exists $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId); } catch (kCoreException $ex) { if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) { } throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY); throw $ex; } if (!file_exists($entryFullPath)) { // Backward compatability - support case in which the required file exist in the other DC kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId())); /* $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId()); if($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } else { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } */ } // validate the input object //$entry->validatePropertyMinLength("name", 1); if (!$entry->name) { $entry->name = $this->getPartnerId() . '_' . time(); } // first copy all the properties to the db entry, then we'll check for security stuff $dbEntry = $entry->toInsertableObject(new entry()); $dbEntry->setType($type); $dbEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_AUTOMATIC); $this->checkAndSetValidUserInsert($entry, $dbEntry); $this->checkAdminOnlyInsertProperties($entry); $this->validateAccessControlId($entry); $this->validateEntryScheduleDates($entry, $dbEntry); $dbEntry->setPartnerId($this->getPartnerId()); $dbEntry->setSubpId($this->getPartnerId() * 100); $dbEntry->setSourceId($uploadTokenId); $dbEntry->setSourceLink($entryFullPath); myEntryUtils::setEntryTypeAndMediaTypeFromFile($dbEntry, $entryFullPath); $dbEntry->setDefaultModerationStatus(); // hack due to KCW of version from KMC if (!is_null(parent::getConversionQualityFromRequest())) { $dbEntry->setConversionQuality(parent::getConversionQualityFromRequest()); } $dbEntry->save(); $kshow = $this->createDummyKShow(); $kshowId = $kshow->getId(); // setup the needed params for my insert entry helper $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags()); $token = $this->getKsUniqueString(); $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray); $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100); $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry); $dbEntry = $insert_entry_helper->getEntry(); kUploadTokenMgr::closeUploadTokenById($uploadTokenId); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry); $entry->fromObject($dbEntry, $this->getResponseProfile()); return $entry; }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { KExternalErrors::setResponseErrorCode(KExternalErrors::HTTP_STATUS_NOT_FOUND); myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2; requestUtils::handleConditionalGet(); ignore_user_abort(); $entry_id = $this->getRequestParameter("entry_id"); $widget_id = $this->getRequestParameter("widget_id", 0); $upload_token_id = $this->getRequestParameter("upload_token_id"); $version = $this->getIntRequestParameter("version", null, 0, 10000000); $type = $this->getIntRequestParameter("type", 1, 1, 5); //Hack: if KMS sends thumbnail request containing "!" char, the type should be treated as 5. $width = $this->getRequestParameter("width", -1); $height = $this->getRequestParameter("height", -1); if (strpos($width, "!") || strpos($height, "!")) { $type = 5; } $width = $this->getFloatRequestParameter("width", -1, -1, 10000); $height = $this->getFloatRequestParameter("height", -1, -1, 10000); $nearest_aspect_ratio = $this->getIntRequestParameter("nearest_aspect_ratio", 0, 0, 1); $imageFilePath = null; $crop_provider = $this->getRequestParameter("crop_provider", null); $quality = $this->getIntRequestParameter("quality", 0, 0, 100); $src_x = $this->getFloatRequestParameter("src_x", 0, 0, 10000); $src_y = $this->getFloatRequestParameter("src_y", 0, 0, 10000); $src_w = $this->getFloatRequestParameter("src_w", 0, 0, 10000); $src_h = $this->getFloatRequestParameter("src_h", 0, 0, 10000); $vid_sec = $this->getFloatRequestParameter("vid_sec", -1, -1); $vid_slice = $this->getRequestParameter("vid_slice", -1); $vid_slices = $this->getRequestParameter("vid_slices", -1); $density = $this->getFloatRequestParameter("density", 0, 0); $stripProfiles = $this->getRequestParameter("strip", null); $flavor_id = $this->getRequestParameter("flavor_id", null); $file_name = $this->getRequestParameter("file_name", null); $file_name = basename($file_name); // actual width and height of image from which the src_* values were taken. // these will be used to multiply the src_* parameters to make them relate to the original image size. $rel_width = $this->getFloatRequestParameter("rel_width", -1, -1, 10000); $rel_height = $this->getFloatRequestParameter("rel_height", -1, -1, 10000); $def_width = $this->getFloatRequestParameter("def_width", -1, -1, 10000); $def_height = $this->getFloatRequestParameter("def_height", -1, -1, 10000); if ($width == -1 && $height == -1) { if ($def_width == -1) { $width = 120; } else { $width = $def_width; } if ($def_height == -1) { $height = 90; } else { $height = $def_height; } } else { if ($width == -1) { $width = 0; } else { if ($height == -1) { $height = 0; } } } $bgcolor = $this->getRequestParameter("bgcolor", "ffffff"); $partner = null; $format = $this->getRequestParameter("format", null); // validating the inputs if (!is_numeric($quality) || $quality < 0 || $quality > 100) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'quality must be between 20 and 100'); } if (!is_numeric($src_x) || $src_x < 0 || $src_x > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_x must be between 0 and 10000'); } if (!is_numeric($src_y) || $src_y < 0 || $src_y > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_y must be between 0 and 10000'); } if (!is_numeric($src_w) || $src_w < 0 || $src_w > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_w must be between 0 and 10000'); } if (!is_numeric($src_h) || $src_h < 0 || $src_h > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_h must be between 0 and 10000'); } if (!is_numeric($width) || $width < 0 || $width > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'width must be between 0 and 10000'); } if (!is_numeric($height) || $height < 0 || $height > 10000) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'height must be between 0 and 10000'); } if (!is_numeric($density) || $density < 0) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'density must be positive'); } if (!is_numeric($vid_sec) || $vid_sec < -1) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'vid_sec must be positive'); } if (!preg_match('/^[0-9a-fA-F]{1,6}$/', $bgcolor)) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'bgcolor must be six hexadecimal characters'); } if ($vid_slices != -1 && $vid_slices <= 0 || !is_numeric($vid_slices)) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'vid_slices must be positive'); } if ($upload_token_id) { $upload_token = UploadTokenPeer::retrieveByPK($upload_token_id); if ($upload_token) { $partnerId = $upload_token->getPartnerId(); $partner = PartnerPeer::retrieveByPK($partnerId); if ($partner) { KalturaMonitorClient::initApiMonitor(false, 'extwidget.thumbnail', $partner->getId()); if ($quality == 0) { $quality = $partner->getDefThumbQuality(); } if ($density == 0) { $density = $partner->getDefThumbDensity(); } if (is_null($stripProfiles)) { $stripProfiles = $partner->getStripThumbProfile(); } } $thumb_full_path = myContentStorage::getFSCacheRootPath() . myContentStorage::getGeneralEntityPath("uploadtokenthumb", $upload_token->getIntId(), $upload_token->getId(), $upload_token->getId() . ".jpg"); kFile::fullMkdir($thumb_full_path); if (file_exists($upload_token->getUploadTempPath())) { $src_full_path = $upload_token->getUploadTempPath(); $valid_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_WBMP); $image_type = exif_imagetype($src_full_path); if (!in_array($image_type, $valid_image_types)) { // capture full frame myFileConverter::captureFrame($src_full_path, $thumb_full_path, 1, "image2", -1, -1, 3); if (!file_exists($thumb_full_path)) { myFileConverter::captureFrame($src_full_path, $thumb_full_path, 1, "image2", -1, -1, 0); } $src_full_path = $thumb_full_path; } // and resize it myFileConverter::convertImage($src_full_path, $thumb_full_path, $width, $height, $type, $bgcolor, true, $quality, $src_x, $src_y, $src_w, $src_h, $density, $stripProfiles, null, $format); kFileUtils::dumpFile($thumb_full_path); } else { KalturaLog::info("token_id [{$upload_token_id}] not found in DC [" . kDataCenterMgr::getCurrentDcId() . "]. dump url to romote DC"); $remoteUrl = kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()) . $_SERVER['REQUEST_URI']; kFileUtils::dumpUrl($remoteUrl); } } } if ($entry_id) { $entry = entryPeer::retrieveByPKNoFilter($entry_id); if (!$entry) { // problem could be due to replication lag kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId())); } } else { // get the widget $widget = widgetPeer::retrieveByPK($widget_id); if (!$widget) { KExternalErrors::dieError(KExternalErrors::ENTRY_AND_WIDGET_NOT_FOUND); } // get the kshow $kshow_id = $widget->getKshowId(); $kshow = kshowPeer::retrieveByPK($kshow_id); if ($kshow) { $entry_id = $kshow->getShowEntryId(); } else { $entry_id = $widget->getEntryId(); } $entry = entryPeer::retrieveByPKNoFilter($entry_id); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } KalturaMonitorClient::initApiMonitor(false, 'extwidget.thumbnail', $entry->getPartnerId()); if ($nearest_aspect_ratio) { // Get the entry's default thumbnail path (if any) $defaultThumbnailPath = myEntryUtils::getLocalImageFilePathByEntry($entry, $version); // Get the file path of the thumbnail with the nearest $selectedThumbnailDescriptor = kThumbnailUtils::getNearestAspectRatioThumbnailDescriptorByEntryId($entry_id, $width, $height, $defaultThumbnailPath); if ($selectedThumbnailDescriptor) { $imageFilePath = $selectedThumbnailDescriptor->getImageFilePath(); $thumbWidth = $selectedThumbnailDescriptor->getWidth(); $thumbHeight = $selectedThumbnailDescriptor->getHeight(); // The required width and height will serve as the final crop values $src_w = $width; $src_h = $height; // Base on the thumbnail's dimensions kThumbnailUtils::scaleDimensions($thumbWidth, $thumbHeight, $width, $height, kThumbnailUtils::SCALE_UNIFORM_SMALLER_DIM, $width, $height); // Set crop type $type = KImageMagickCropper::CROP_AFTER_RESIZE; } } $partner = $entry->getPartner(); // not allow capturing frames if the partner has FEATURE_DISALLOW_FRAME_CAPTURE permission if ($vid_sec != -1 || $vid_slice != -1 || $vid_slices != -1) { if ($partner->getEnabledService(PermissionName::FEATURE_BLOCK_THUMBNAIL_CAPTURE)) { KExternalErrors::dieError(KExternalErrors::NOT_ALLOWED_PARAMETER); } } if ($partner) { if ($quality == 0) { $quality = $partner->getDefThumbQuality(); } if ($density == 0) { $density = $partner->getDefThumbDensity(); } } $thumbParams = new kThumbnailParameters(); $thumbParams->setSupportAnimatedThumbnail($partner->getSupportAnimatedThumbnails()); if (is_null($stripProfiles)) { $stripProfiles = $partner->getStripThumbProfile(); } //checks whether the thumbnail display should be restricted by KS $base64Referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($base64Referrer); if (!is_string($referrer)) { $referrer = ""; } // base64_decode can return binary data if (!$referrer) { $referrer = kApiCache::getHttpReferrer(); } $ksStr = $this->getRequestParameter("ks"); $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer, ContextType::THUMBNAIL); $securyEntryHelper->validateForPlay(); // multiply the passed $src_* values so that they will relate to the original image size, according to $src_display_* if ($rel_width != -1 && $rel_width) { $widthRatio = $entry->getWidth() / $rel_width; $src_x = $src_x * $widthRatio; $src_w = $src_w * $widthRatio; } if ($rel_height != -1 && $rel_height) { $heightRatio = $entry->getHeight() / $rel_height; $src_y = $src_y * $heightRatio; $src_h = $src_h * $heightRatio; } $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB; if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA; } $dataKey = $entry->getSyncKey($subType); list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($dataKey, true, false); $tempThumbPath = null; $entry_status = $entry->getStatus(); // both 640x480 and 0x0 requests are probably coming from the kdp // 640x480 - old kdp version requesting thumbnail // 0x0 - new kdp version requesting the thumbnail of an unready entry // we need to distinguish between calls from the kdp and calls from a browser: <img src=...> // that can't handle swf input if (($width == 640 && $height == 480 || $width == 0 && $height == 0) && ($entry_status == entryStatus::PRECONVERT || $entry_status == entryStatus::IMPORT || $entry_status == entryStatus::ERROR_CONVERTING || $entry_status == entryStatus::DELETED)) { $contentPath = myContentStorage::getFSContentRootPath(); $msgPath = $contentPath . "content/templates/entry/bigthumbnail/"; if ($entry_status == entryStatus::DELETED) { $msgPath .= $entry->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK ? "entry_blocked.swf" : "entry_deleted.swf"; } else { $msgPath .= $entry_status == entryStatus::ERROR_CONVERTING ? "entry_error.swf" : "entry_converting.swf"; } kFileUtils::dumpFile($msgPath, null, 0); } if (!$file_sync) { $tempThumbPath = $entry->getLocalThumbFilePath($version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $density, $stripProfiles, $flavor_id, $file_name); if (!$tempThumbPath) { KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } } if (!$local && !$tempThumbPath && $file_sync) { if (!in_array($file_sync->getDc(), kDataCenterMgr::getDcIds())) { $remoteUrl = $file_sync->getExternalUrl($entry->getId()); header("Location: {$remoteUrl}"); KExternalErrors::dieGracefully(); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($file_sync, $_SERVER['REQUEST_URI']); kFileUtils::dumpUrl($remoteUrl); } // if we didnt return a template for the player die and dont return the original deleted thumb if ($entry_status == entryStatus::DELETED) { KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED); } if (!$tempThumbPath) { try { $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $imageFilePath, $density, $stripProfiles, $thumbParams, $format); } catch (Exception $ex) { if ($ex->getCode() != kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) { KalturaLog::err("Resize image failed"); KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } // get original flavor asset $origFlavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id); if (!$origFlavorAsset) { KalturaLog::err("No original flavor for entry [{$entry_id}]"); KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $syncKey = $origFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $remoteFileSync = kFileSyncUtils::getOriginFileSyncForKey($syncKey, false); if (!$remoteFileSync) { // file does not exist on any DC - die KalturaLog::log("Error - no FileSync for entry [{$entry_id}]"); KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } if ($remoteFileSync->getDc() == kDataCenterMgr::getCurrentDcId()) { KalturaLog::err("Trying to redirect to myself - stop here."); KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } if (!in_array($remoteFileSync->getDc(), kDataCenterMgr::getDcIds())) { KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($remoteFileSync); kFileUtils::dumpUrl($remoteUrl); } } $nocache = false; if ($securyEntryHelper->shouldDisableCache() || kApiCache::hasExtraFields() || !$securyEntryHelper->isKsWidget() && $securyEntryHelper->hasRules(ContextType::THUMBNAIL)) { $nocache = true; } $cache = null; if (!is_null($entry->getPartner())) { $partnerCacheAge = $entry->getPartner()->getThumbnailCacheAge(); } if ($nocache) { $cacheAge = 0; } else { if ($partnerCacheAge) { $cacheAge = $partnerCacheAge; } else { if (strpos($tempThumbPath, "_NOCACHE_") !== false) { $cacheAge = 60; } else { $cacheAge = 3600; $cache = new myCache("thumb", 2592000); // 30 days, the max memcache allows } } } $lastModified = $entry->getAssetCacheTime(); $renderer = kFileUtils::getDumpFileRenderer($tempThumbPath, null, $cacheAge, 0, $lastModified); $renderer->partnerId = $entry->getPartnerId(); if ($cache) { $invalidationKey = $entry->getCacheInvalidationKeys(); $invalidationKey = kQueryCache::CACHE_PREFIX_INVALIDATION_KEY . $invalidationKey[0]; $cacheTime = time() - kQueryCache::CLOCK_SYNC_TIME_MARGIN_SEC; $cachedResponse = array($renderer, $invalidationKey, $cacheTime); $cache->put($_SERVER["REQUEST_URI"], $cachedResponse); } $renderer->output(); KExternalErrors::dieGracefully(); // TODO - can delete from disk assuming we caneasily recreate it and it will anyway be cached in the CDN // however dumpfile dies at the end so we cant just write it here (maybe register a shutdown callback) }
/** Will allow creation of multiple entries ASSUME - the prefix of the entries is entryX_ where X is the index starting at 1 */ public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { // $logger = sfLogger::getInstance(); self::$escape_text = true; /* if ( !$puser_kuser ) { $this->addError( "No such user ..." ); return; } */ // TODO - validate if the user can add entries to this kshow $kshow_id = $this->getP("kshow_id"); $show_entry_id = $this->getP("show_entry_id"); $conversion_quality = $this->getP("conversionquality"); // must be all lower case // for now - by default use quick_edit $partner = PartnerPeer::retrieveByPK($partner_id); for ($i = 0; $i <= $partner->getAddEntryMaxFiles(); ++$i) { if ($i == 0) { $prefix = $this->getObjectPrefix() . "_"; } else { $prefix = $this->getObjectPrefix() . "{$i}" . "_"; } $source = $this->getP($prefix . "source"); $filename = $this->getP($prefix . "filename"); if ($source != entry::ENTRY_MEDIA_SOURCE_WEBCAM || !$filename) { continue; } $content = myContentStorage::getFSContentRootPath(); $entryFullPath = "{$content}/content/webcam/{$filename}.flv"; if (!file_exists($entryFullPath)) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()); if ($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } $this->addError(APIErrors::INVALID_FILE_NAME, $filename); return; } } if (strpos($kshow_id, 'entry-') !== false && !$show_entry_id) { $show_entry_id = substr($kshow_id, 6); } $screen_name = $this->getP("screen_name"); $site_url = $this->getP("site_url"); $null_kshow = true; if ($show_entry_id) { // in this case we have the show_entry_id (of the relevant roughcut) - it suppresses the kshow_id $show_entry = entryPeer::retrieveByPK($show_entry_id); if ($show_entry) { $kshow_id = $show_entry->getKshowId(); } else { $kshow_id = null; } } if ($kshow_id === kshow::SANDBOX_ID) { $this->addError(APIErrors::SANDBOX_ALERT); return; } $default_kshow_name = $this->getP("entry_name", null); if (!$default_kshow_name) { $default_kshow_name = $this->getP("entry1_name", null); } if ($kshow_id == kshow::KSHOW_ID_USE_DEFAULT) { // see if the partner has some default kshow to add to $kshow = myPartnerUtils::getDefaultKshow($partner_id, $subp_id, $puser_kuser, null, false, $default_kshow_name); $null_kshow = false; if ($kshow) { $kshow_id = $kshow->getId(); } } elseif ($kshow_id == kshow::KSHOW_ID_CREATE_NEW) { // if the partner allows - create a new kshow $kshow = myPartnerUtils::getDefaultKshow($partner_id, $subp_id, $puser_kuser, null, true, $default_kshow_name); $null_kshow = false; if ($kshow) { $kshow_id = $kshow->getId(); } } else { $kshow = kshowPeer::retrieveByPK($kshow_id); } if (!$kshow) { // the partner is attempting to add an entry to some invalid or non-existing kwho $this->addError(APIErrors::INVALID_KSHOW_ID, $kshow_id); return; } // find permissions from kshow $permissions = $kshow->getPermissions(); $kuser_id = $puser_kuser->getKuserId(); // TODO - once the CW $quick_edit = myPolicyMgr::getPolicyFor("allowQuickEdit", $kshow, $partner); // let the user override the quick_edit propery if ($this->getP("quick_edit") == '0' || $this->getP("quick_edit") == "false") { $quick_edit = false; } if ($quick_edit == '0' || $quick_edit === "false" || !$quick_edit || $quick_edit == false) { KalturaLog::err('$quick_edit: [' . $quick_edit . ']'); $quick_edit = false; //$quick_edit = true; } // works in one of 2 ways: // 1. get no requested name - will create a new kshow and return its details // 2. get some name - tries to fetch by name. if already exists - return it $new_entry_count = 0; $entries = array(); $notification_ids = array(); $notifications = array(); $field_level = $this->isAdmin() ? 2 : 1; $updateable_fields = null; $imported_entries_count = 0; for ($i = 0; $i <= $partner->getAddEntryMaxFiles(); ++$i) { if ($i == 0) { $prefix = $this->getObjectPrefix() . "_"; } else { $prefix = $this->getObjectPrefix() . "{$i}" . "_"; } $file_name = $this->getP($prefix . "realFilename"); if (!($this->getP($prefix . "name") || $file_name)) { continue; } // get the new properties for the kuser from the request $entry = new entry(); $obj_wrapper = objectWrapperBase::getWrapperClass($entry, 0); if (!$updateable_fields) { $updateable_fields = $obj_wrapper->getUpdateableFields($field_level); } // fill the entry from request $fields_modified = baseObjectUtils::fillObjectFromMap($this->getInputParams(), $entry, $prefix, $updateable_fields); // check that mandatory fields were set // TODO KalturaLog::err("addentry: fields_modified: " . print_r($fields_modified, true)); $entry_source = $entry->getSource(); if (!$entry->getType()) { // this is the default for backward compatiblity $entry->setType(entryType::MEDIA_CLIP); } $token = $this->getKsUniqueString(); $entry_full_path = ""; if ($entry_source == entry::ENTRY_MEDIA_SOURCE_FILE) { $entry->setSourceLink($file_name); $file_alias = $this->getP($prefix . "filename"); $file_extension = strtolower(pathinfo($this->getP($prefix . "realFilename"), PATHINFO_EXTENSION)); $entry_full_path = myUploadUtils::getUploadPath($token, $file_alias, null, $file_extension); if (!file_exists($entry_full_path)) { KalturaLog::err("Invalid UPLOAD PATH [" . $entry_full_path . "] while trying to add entry for partner id [" . $partner_id . "] with token [" . $token . "] & original name [" . $this->getP($prefix . "name") . "]"); $this->addError(APIErrors::INVALID_FILE_NAME); continue; } myEntryUtils::setEntryTypeAndMediaTypeFromFile($entry, $entry_full_path); } // No reason to rais the error // Remarked by Tan-Tan // // // when we reached this point the type and media type must be set // if ($entry->getType() == entryType::AUTOMATIC || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUTOMATIC) // { // $this->addError ( APIErrors::CANNOT_USE_ENTRY_TYPE_AUTO_IN_IMPORT ); // continue; // } // limit two kinds of media // 1. not images - video/audio which are big files // 2. media which wasnt directly uploaded by the owner (the owner real content) if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_IMAGE && $entry_source != entry::ENTRY_MEDIA_SOURCE_FILE) { if ($imported_entries_count >= 4) { continue; } ++$imported_entries_count; } // the conversion_quality is set once for the whole list of entries if ($conversion_quality) { $entry->setConversionQuality($conversion_quality); } else { // HACK - if the conversion_quality was not set in the proper way - // see if the partner_data holds a hack - string that starts with conversionQuality= - this is set when the CW is opened in the KMC // the conversionQuality is of format conversionQuality=XXX;<the rest of the text> // if (kString::beginsWith($entry->getPartnerData(), "conversionQuality:")) { $partner_data_arr = explode(";", $entry->getPartnerData(), 2); $conversion_quality_arr = explode(":", $partner_data_arr[0]); $conversion_quality = @$conversion_quality_arr[1]; // the value of the conversion_quality $entry->setPartnerData(@$partner_data_arr[1]); // the rest of the string $entry->setConversionQuality($conversion_quality); } } $insert = true; $entry_modified = false; $create_entry = true; // I don't remember why we set the kshow to null every time ... // but when we fetched it automatically - hang on to it ! if ($null_kshow) { $kshow = null; } if ($entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_USER_CLIPS || $entry_source == "100") { if ($entry_source == "100") { $entry_id = $this->getP("media{$i}_id"); } else { $entry_id = $this->getP($prefix . "id"); } // $this->getP ( $prefix . "url" ); if ($entry_id === null) { $entry_id = $entry->getMediaId(); } if ($entry_id) { $entry = entryPeer::retrieveByPK($entry_id); if ($entry) { $create_entry = false; $insert = false; } else { $this->addError(APIErrors::INVALID_ENTRY_ID, $this->getObjectPrefix(), $entry_id); return; } } } $new_entry_count++; if ($create_entry) { $entry->setPartnerId($partner_id); $entry->setSubpId($subp_id); $entry->setKuserId($kuser_id); $entry->setCreatorKuserId($kuser_id); $entry->setKshowId($kshow_id); $entry->setSiteUrl($site_url); $entry->setScreenName($screen_name); if ($this->getGroup()) { $entry->setGroupId($this->getGroup()); } if ($entry->getPermissions() === null) { $entry->setPermissions($permissions); } // inherited from the enclosing kshow $entry->setDefaultModerationStatus(); $entry->save(); $entry_modified = true; if (!$entry->getName()) { if ($file_name) { // TODO - fix the file_name to fit $entry->setName($file_name); } else { $entry->setName($partner_prefix . $entry->getId()); } $entry_modified = true; } // TODO - decide on file naming mechanism !! // there are 3 types of insert: // 1. upload - the file is assumed to be in the upload directory and it's name is explicitly set in the fname$i param // 2. webcam - the file is assumed to be in the webcam directory and it's name is explicitly set in the fname$i param // 3. URL - the url is given in the entry_url$i param /* $media_source = $this->getParam('entry_media_source'); $media_type = $this->getParam('entry_media_type'); $entry_url = $this->getParam('entry_url'); $entry_source_link = $this->getParam('entry_source_link'); $entry_fileName = $this->getParam('entry_data'); $entry_thumbNum = $this->getParam('entry_thumb_num', 0); $entry_thumbUrl = $this->getParam('entry_thumb_url', ''); $entry_from_time = $this->getParam('entry_from_time', 0); $entry_to_time = $this->getParam('entry_to_time', 0); $should_copy = $this->getParam('should_copy' , false ); $skip_conversion = $this->getParam('skip_conversion' , false ); */ $paramsArray = array('entry_media_source' => $entry->getSource(), 'entry_media_type' => $entry->getMediaType()); // $entry_source = $entry->getSource() ; if ($entry_source == entry::ENTRY_MEDIA_SOURCE_FILE) { $paramsArray["entry_full_path"] = $entry_full_path; } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) { $file_alias = $this->getP($prefix . "filename"); $paramsArray["webcam_suffix"] = $file_alias; $paramsArray['entry_from_time'] = $this->getP($prefix . "fromTime", 0); $paramsArray['entry_to_time'] = $this->getP($prefix . "toTime", 0); } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_PARTNER || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_PARTNER_KSHOW || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_KSHOW || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_USER_CLIPS) { // optimize - no need to actually go through the import and conversion phase // find the source entry_id from the url /* $entry_url = $this->getP ( $prefix . "url" ); $entry_thumb_url = $this->getP ( $prefix . "thumbUrl" ); if ( myEntryUtils::copyData( $entry_url , $entry_thumb_url , $entry ) ) */ $source_entry_id = $this->getP("media{$i}_id"); // $this->getP ( $prefix . "url" ); if ($source_entry_id === null) { $source_entry_id = $entry->getMediaId(); } if (myEntryUtils::copyData($source_entry_id, $entry)) { // copy worked ok - no need to use insertEntryHelper //$entry->setStatus ( entryStatus::READY ); // force the data to be ready even if the policy is to moderate - this is kaltura's content and was already approved // (roman) true argument removed, so kaltura's content will be moderated according to partner's moderation settings $entry->setStatusReady(); $insert = false; $entry_modified = true; $entry->save(); } } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_URL || in_array($entry_source, myMediaSourceFactory::getAllMediaSourceProvidersIds())) { // the URL is relevant $paramsArray["entry_url"] = $this->getP($prefix . "url"); $paramsArray["entry_thumb_url"] = $this->getP($prefix . "thumbUrl"); // TODO - these fields are already set in the entry - // the code in myInsertEntryHelper is redundant $paramsArray["entry_license"] = $entry->getLicenseType(); $paramsArray["entry_credit"] = $entry->getCredit(); $paramsArray["entry_source_link"] = $entry->getSourceLink(); $paramsArray["entry_tags"] = $entry->getTags(); } else { $this->addError(APIErrors::UNKNOWN_MEDIA_SOURCE, $entry->getSource()); $insert = false; } if ($insert) { KalturaLog::err("paramsArray" . print_r($paramsArray, true)); $insert_entry_helper = new myInsertEntryHelper($this, $kuser_id, $kshow_id, $paramsArray); $insert_entry_helper->setPartnerId($partner_id, $subp_id); $insert_entry_helper->insertEntry($token, $entry->getType(), $entry->getId(), $entry->getName(), $entry->getTags(), $entry); $insert_entry_helper->getEntry(); $this->addDebug("added_entry{$i}", $entry->getName()); } } // create_entry = true KalturaLog::err('id: ' . $entry->getId() . ' $quick_edit:' . $quick_edit); if ($quick_edit) { KalturaLog::info("quick edit with kshow_id [{$kshow_id}]"); if (!$kshow) { $kshow = kshowPeer::retrieveByPK($kshow_id); } // this i if (!$kshow) { // BAD - this shount not be ! $this->addError(APIErrors::INVALID_KSHOW_ID, $kshow_id); return; } $metadata = $kshow->getMetadata(); if ($metadata !== null) { KalturaLog::info("Having metadata"); $relevant_kshow_version = 1 + $kshow->getVersion(); // the next metadata will be the first relevant version for this new entry $version_info = array(); $version_info["KuserId"] = $puser_kuser->getKuserId(); $version_info["PuserId"] = $puser_id; $version_info["ScreenName"] = $puser_kuser->getPuserName(); $new_metadata = myMetadataUtils::addEntryToMetadata($metadata, $entry, $relevant_kshow_version, $version_info); $entry_modified = true; if ($new_metadata) { // TODO - add thumbnail only for entries that are worthy - check they are not moderated ! $thumb_modified = myKshowUtils::updateThumbnail($kshow, $entry, false); if ($thumb_modified) { $new_metadata = myMetadataUtils::updateThumbUrlFromMetadata($new_metadata, $entry->getThumbnailUrl()); } // it is very important to increment the version count because even if the entry is deferred // it will be added on the next version if (!$kshow->getHasRoughcut()) { // make sure the kshow now does have a roughcut $kshow->setHasRoughcut(true); $kshow->save(); } $kshow->setMetadata($new_metadata, true); } // no need to save kshow - the modification of the metadata was done to the show_entry which will propagate any chages to the kshow in it's own save method } } if ($entry_modified) { $entry->save(); } $not_id = null; // send a synch notification @(list($not_id, $not, $url, $params, $serialized_params) = myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $entry, null, null)); if ($not_id) { $notification_ids[] = $not_id; $notifications[] = array("url" => $url, "params" => $serialized_params); } $wrapper = objectWrapperBase::getWrapperClass($entry, objectWrapperBase::DETAIL_LEVEL_REGULAR); $entries[$prefix] = $wrapper; //$this->addMsg ( $prefix , $wrapper); // because the kshow's entrys field was changes do to this update, we have to remove object from cahce // TODO - think of some reverse way to automatically remove from the cache from within the wrapper // call some - update cache where the kshow_id plays a part in the update $wrapper->removeFromCache("kshow", $kshow_id, "entrys"); $this->addDebug("added_fields", $fields_modified, $prefix); } $this->addMsg("entries", $entries); if (count($notification_ids) > 0) { $this->addMsg("notifications", $notifications); } if ($new_entry_count < 1) { $this->addError(APIErrors::NO_ENTRIES_ADDED); $this->addDebug("no_new_entries", "You have to have at least one new entry with a field called 'entry1_name'"); } $this->addMsg("new_entry_count", $new_entry_count); }
public function toObject($object_to_fill = null, $props_to_skip = array()) { $this->validateForUsage($object_to_fill, $props_to_skip); $srcEntry = entryPeer::retrieveByPK($this->entryId); if (!$srcEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryId); } if ($srcEntry->getType() == entryType::LIVE_STREAM) { /* @var $srcEntry LiveEntry */ if (!in_array($srcEntry->getSource(), array(EntrySourceType::LIVE_STREAM, EntrySourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) { throw new KalturaAPIException(KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED, get_class($this)); } $mediaServer = $srcEntry->getMediaServer(); if ($mediaServer && !is_null($mediaServer->getDc()) && $mediaServer->getDc() != kDataCenterMgr::getCurrentDcId()) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($mediaServer->getDc()); if ($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } else { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } } if ($object_to_fill && !$object_to_fill instanceof kLiveEntryResource) { throw new KalturaAPIException(KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED, get_class($object_to_fill)); } $object_to_fill = new kLiveEntryResource(); $object_to_fill->setEntry($srcEntry); return $object_to_fill; } if (!$object_to_fill) { $object_to_fill = new kFileSyncResource(); } if ($srcEntry->getMediaType() == KalturaMediaType::IMAGE) { $object_to_fill->setFileSyncObjectType(FileSyncObjectType::ENTRY); $object_to_fill->setObjectSubType(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); $object_to_fill->setObjectId($srcEntry->getId()); return $object_to_fill; } $srcFlavorAsset = null; if (is_null($this->flavorParamsId)) { $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($this->entryId); if (!$srcFlavorAsset) { throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING); } } else { $srcFlavorAsset = assetPeer::retrieveByEntryIdAndParams($this->entryId, $this->flavorParamsId); if (!$srcFlavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $this->flavorParamsId); } } $object_to_fill->setFileSyncObjectType(FileSyncObjectType::FLAVOR_ASSET); $object_to_fill->setObjectSubType(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $object_to_fill->setObjectId($srcFlavorAsset->getId()); $object_to_fill->setOriginEntryId($this->entryId); return $object_to_fill; }