/** * Upload a file to the current upload token * @param file $fileData * @param bool $resume * @param bool $finalChunk * @param int $resumeAt */ public function uploadFileToToken($fileData, $resume = false, $finalChunk = true, $resumeAt = -1) { $allowedStatuses = array(UploadToken::UPLOAD_TOKEN_PENDING, UploadToken::UPLOAD_TOKEN_PARTIAL_UPLOAD); if (!in_array($this->_uploadToken->getStatus(), $allowedStatuses, true)) { throw new kUploadTokenException("Invalid upload token status", kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS); } $this->updateFileName($fileData); try { $this->checkIfFileIsValid($fileData); } catch (kUploadTokenException $ex) { if (!$resume && $finalChunk) { kFlowHelper::handleUploadFailed($this->_uploadToken); } $this->tryMoveToErrors($fileData); throw $ex; } if ($resume) { $this->handleResume($fileData, $resumeAt); } else { $this->handleMoveFile($fileData); } $fileSize = kFile::fileSize($this->_uploadToken->getUploadTempPath()); if ($finalChunk) { $this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_FULL_UPLOAD); } else { $this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_PARTIAL_UPLOAD); } $this->_uploadToken->setUploadedFileSize($fileSize); $this->_uploadToken->setDc(kDataCenterMgr::getCurrentDcId()); $this->_uploadToken->save(); $this->addTrackEntry(); }
public function crop($quality, $cropType, $width = 0, $height = 0, $cropX = 0, $cropY = 0, $cropWidth = 0, $cropHeight = 0, $scaleWidth = 1, $scaleHeight = 1, $bgcolor = 0xffffff, $density = 0, $forceRotation = null, $strip = false) { if (is_null($quality)) { $quality = 100; } if (is_null($cropType)) { $cropType = 1; } if (is_null($width)) { $width = 0; } if (is_null($height)) { $height = 0; } if (is_null($cropX)) { $cropX = 0; } if (is_null($cropY)) { $cropY = 0; } if (is_null($cropWidth)) { $cropWidth = 0; } if (is_null($cropHeight)) { $cropHeight = 0; } if (is_null($scaleWidth)) { $scaleWidth = 1; } if (is_null($scaleHeight)) { $scaleHeight = 1; } if (is_null($bgcolor)) { $bgcolor = 0; } $cmd = $this->getCommand($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor, $density, $forceRotation, $strip); if ($cmd) { KalturaLog::info("Executing: {$cmd}"); $returnValue = null; $output = system($cmd, $returnValue); KalturaLog::debug("Returned value: '{$returnValue}'"); if ($returnValue) { return false; } // Support animated gifs - KImageMagick generates multiple images with a postfix of '-<frame num>' if (!kFile::fileSize($this->targetPath)) { $targetFiledir = pathinfo($this->targetPath, PATHINFO_DIRNAME); $targetFilename = pathinfo($this->targetPath, PATHINFO_FILENAME); $targetFileext = pathinfo($this->targetPath, PATHINFO_EXTENSION); $firstFrameTargetFile = "{$targetFiledir}/{$targetFilename}-0.{$targetFileext}"; if (kFile::fileSize($firstFrameTargetFile)) { kFile::moveFile($firstFrameTargetFile, $this->targetPath); } } return true; } KalturaLog::info("No conversion required, copying source[{$this->srcPath}] to target[{$this->targetPath}]"); return copy($this->srcPath, $this->targetPath); }
/** * @param KalturaBatchJob $job * @param KalturaConcatJobData $data * @param string $localTempFilePath * @param string $sharedTempFilePath * @return KalturaBatchJob */ protected function moveFile(KalturaBatchJob $job, KalturaConvertLiveSegmentJobData $data, $localTempFilePath, $sharedTempFilePath) { $this->updateJob($job, "Moving file from [{$localTempFilePath}] to [{$sharedTempFilePath}]", KalturaBatchJobStatus::MOVEFILE); kFile::moveFile($localTempFilePath, $sharedTempFilePath, true); clearstatcache(); $fileSize = kFile::fileSize($sharedTempFilePath); $this->setFilePermissions($sharedTempFilePath); if (!$this->checkFileExists($sharedTempFilePath, $fileSize)) { return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, 'File not moved correctly', KalturaBatchJobStatus::RETRY); } $data->destFilePath = $sharedTempFilePath; return $this->closeJob($job, null, null, 'Succesfully moved file', KalturaBatchJobStatus::FINISHED, $data); }
protected function moveFile(KalturaBatchJob $job, KalturaLiveReportExportJobData $data, $partnerId) { $fileName = basename($data->outputPath); $sharedLocation = self::$taskConfig->params->sharedPath . DIRECTORY_SEPARATOR . $partnerId . "_" . $fileName; $fileSize = kFile::fileSize($data->outputPath); rename($data->outputPath, $sharedLocation); $data->outputPath = $sharedLocation; $this->setFilePermissions($sharedLocation); if (!$this->checkFileExists($sharedLocation, $fileSize)) { return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, 'Failed to move report file', KalturaBatchJobStatus::RETRY); } return $this->closeJob($job, null, null, 'CSV created successfully', KalturaBatchJobStatus::FINISHED, $data); }
protected function doPutFile($remote_file, $local_file, $ftp_mode, $http_field_name = null, $http_file_name = null) { list($bucket, $remote_file) = explode("/", ltrim($remote_file, "/"), 2); KalturaLog::debug("remote_file: " . $remote_file); $res = $this->s3->putObjectFile($local_file, $bucket, $remote_file); if ($res) { $info = $this->s3->getObjectInfo($bucket, $remote_file); if ($info && $info['size'] == kFile::fileSize($local_file)) { KalturaLog::debug("File uploaded to Amazon, info: " . print_r($info, true)); return true; } else { KalturaLog::debug("error uploading file " . $local_file . " s3 info " . print_r($info, true)); return false; } } }
/** * * @action getUploadedFileTokenByFileName * @param string $fileName * @return KalturaUploadResponse */ function getUploadedFileTokenByFileNameAction($fileName) { KalturaResponseCacher::disableConditionalCache(); $res = new KalturaUploadResponse(); $ksUnique = md5($this->getKs()->toSecureString()); $uniqueId = md5($fileName); $ext = pathinfo($fileName, PATHINFO_EXTENSION); $token = $ksUnique . "_" . $uniqueId . "." . $ext; $entryFullPath = myUploadUtils::getUploadPath($token, "", null, strtolower($ext)); // filesync ok if (!file_exists($entryFullPath)) { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } $res->uploadTokenId = $token; $res->fileSize = kFile::fileSize($entryFullPath); return $res; }
public function __construct($filePath, $mimeType, $xSendFileAllowed, $maxAge = 8640000, $limitFileSize = 0) { $this->filePath = $filePath; $this->mimeType = $mimeType; $this->maxAge = $maxAge; $this->fileExt = pathinfo($filePath, PATHINFO_EXTENSION); if ($limitFileSize) { $this->fileSize = $limitFileSize; $this->xSendFileAllowed = false; } else { clearstatcache(); $this->fileSize = kFile::fileSize($filePath); $this->xSendFileAllowed = $xSendFileAllowed; } if ($this->fileSize && $this->fileSize < self::CACHE_FILE_CONTENTS_MAX_SIZE) { $this->fileData = file_get_contents($this->filePath, false, null, -1, $limitFileSize); } }
public function execute() { //entitlement should be disabled to serveFlavor action as we do not get ks on this action. KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); requestUtils::handleConditionalGet(); $flavorId = $this->getRequestParameter("flavorId"); $shouldProxy = $this->getRequestParameter("forceproxy", false); $fileName = $this->getRequestParameter("fileName"); $fileParam = $this->getRequestParameter("file"); $fileParam = basename($fileParam); $pathOnly = $this->getRequestParameter("pathOnly", false); $referrer = base64_decode($this->getRequestParameter("referrer")); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ''; } $flavorAsset = assetPeer::retrieveById($flavorId); if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $entryId = $this->getRequestParameter("entryId"); if (!is_null($entryId) && $flavorAsset->getEntryId() != $entryId) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } if ($fileName) { header("Content-Disposition: attachment; filename=\"{$fileName}\""); header("Content-Type: application/force-download"); header("Content-Description: File Transfer"); } $clipTo = null; $entry = $flavorAsset->getentry(); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveFlavor', $flavorAsset->getPartnerId()); myPartnerUtils::enforceDelivery($entry, $flavorAsset); $version = $this->getRequestParameter("v"); if (!$version) { $version = $flavorAsset->getVersion(); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, $version); if ($pathOnly && kIpAddressUtils::isInternalIp($_SERVER['REMOTE_ADDR'])) { $path = null; list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, false, false); if ($file_sync) { $parent_file_sync = kFileSyncUtils::resolve($file_sync); $path = $parent_file_sync->getFullPath(); if ($fileParam && is_dir($path)) { $path .= "/{$fileParam}"; } } $renderer = new kRendererString('{"sequences":[{"clips":[{"type":"source","path":"' . $path . '"}]}]}', 'application/json'); if ($path) { $this->storeCache($renderer, $flavorAsset->getPartnerId()); } $renderer->output(); KExternalErrors::dieGracefully(); } if (kConf::hasParam('serve_flavor_allowed_partners') && !in_array($flavorAsset->getPartnerId(), kConf::get('serve_flavor_allowed_partners'))) { KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED); } if (!kFileSyncUtils::file_exists($syncKey, false)) { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } // always dump remote urls so they will be cached by the cdn transparently $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); kFileUtils::dumpUrl($remoteUrl); } $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); $isFlv = false; if (!$shouldProxy) { $flvWrapper = new myFlvHandler($path); $isFlv = $flvWrapper->isFlv(); } $clipFrom = $this->getRequestParameter("clipFrom", 0); // milliseconds if (is_null($clipTo)) { $clipTo = $this->getRequestParameter("clipTo", self::NO_CLIP_TO); } // milliseconds if ($clipTo == 0) { $clipTo = self::NO_CLIP_TO; } if (!is_numeric($clipTo) || $clipTo < 0) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'clipTo must be a positive number'); } $seekFrom = $this->getRequestParameter("seekFrom", -1); if ($seekFrom <= 0) { $seekFrom = -1; } $seekFromBytes = $this->getRequestParameter("seekFromBytes", -1); if ($seekFromBytes <= 0) { $seekFromBytes = -1; } if ($fileParam && is_dir($path)) { $path .= "/{$fileParam}"; kFileUtils::dumpFile($path, null, null); KExternalErrors::dieGracefully(); } else { if (!$isFlv || $clipTo == self::NO_CLIP_TO && $seekFrom < 0 && $seekFromBytes < 0) { $limit_file_size = 0; if ($clipTo != self::NO_CLIP_TO) { if (strtolower($flavorAsset->getFileExt()) == 'mp4' && PermissionPeer::isValidForPartner(PermissionName::FEATURE_ACCURATE_SERVE_CLIPPING, $flavorAsset->getPartnerId())) { $contentPath = myContentStorage::getFSContentRootPath(); $tempClipName = $version . '_' . $clipTo . '.mp4'; $tempClipPath = $contentPath . myContentStorage::getGeneralEntityPath("entry/tempclip", $flavorAsset->getIntId(), $flavorAsset->getId(), $tempClipName); if (!file_exists($tempClipPath)) { kFile::fullMkdir($tempClipPath); $clipToSec = round($clipTo / 1000, 3); $cmdLine = kConf::get("bin_path_ffmpeg") . " -i {$path} -vcodec copy -acodec copy -f mp4 -t {$clipToSec} -y {$tempClipPath} 2>&1"; KalturaLog::log("Executing {$cmdLine}"); $output = array(); $return_value = ""; exec($cmdLine, $output, $return_value); KalturaLog::log("ffmpeg returned {$return_value}, output:" . implode("\n", $output)); } if (file_exists($tempClipPath)) { KalturaLog::log("Dumping {$tempClipPath}"); kFileUtils::dumpFile($tempClipPath); } else { KalturaLog::err('Failed to clip the file using ffmpeg, falling back to rough clipping'); } } $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) { $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration()); $limit_file_size = floor(@kFile::fileSize($path) * ($clipTo / $duration) * 1.2); } } $renderer = kFileUtils::getDumpFileRenderer($path, null, null, $limit_file_size); if (!$fileName) { $this->storeCache($renderer, $flavorAsset->getPartnerId()); } $renderer->output(); KExternalErrors::dieGracefully(); } } $audioOnly = $this->getRequestParameter("audioOnly"); // milliseconds if ($audioOnly === '0') { // audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flvWrapper->getFirstVideoTimestamp() < 0) { $audioOnly = true; } $bytes = 0; if ($seekFrom !== -1 && $seekFrom !== 0) { list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly); list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly); $seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte; } else { list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly); } $metadataSize = $flvWrapper->getMetadataSize($audioOnly); $dataOffset = $metadataSize + myFlvHandler::getHeaderSize(); $totalLength = $dataOffset + $bytes; list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly); list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength); if ($totalLength < 1000) { // (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache requestUtils::sendCdnHeaders("flv", $rangeLength, 0); } else { requestUtils::sendCdnHeaders("flv", $rangeLength); } // dont inject cuepoint into the stream $cuepointTime = 0; $cuepointPos = 0; try { Propel::close(); } catch (Exception $e) { $this->logMessage("serveFlavor: error closing db {$e}"); } header("Content-Type: video/x-flv"); $flvWrapper->dump(self::CHUNK_SIZE, $fromByte, $toByte, $audioOnly, $seekFromBytes, $rangeFrom, $rangeTo, $cuepointTime, $cuepointPos); KExternalErrors::dieGracefully(); }
/** * Validates if the resource is valid * @param KalturaResource $resource * @param SimpleXMLElement $elementToSearchIn */ protected function validateResource(KalturaResource $resource = null, SimpleXMLElement $elementToSearchIn) { if (!$resource) { return; } //We only check for filesize and check sum in local files if ($resource instanceof KalturaServerFileResource) { $filePath = $resource->localFilePath; if (is_null($filePath)) { throw new KalturaBulkUploadXmlException("Can't validate file as file path is null", KalturaBatchJobAppErrors::BULK_ITEM_VALIDATION_FAILED); } if (isset($elementToSearchIn->serverFileContentResource->fileChecksum)) { KalturaLog::debug("Validating checksum"); if ($elementToSearchIn->serverFileContentResource->fileChecksum['type'] == 'sha1') { $checksum = sha1_file($filePath); } else { $checksum = md5_file($filePath); } $xmlChecksum = (string) $elementToSearchIn->serverFileContentResource->fileChecksum; if ($xmlChecksum != $checksum) { throw new KalturaBulkUploadXmlException("File checksum is invalid for file [{$filePath}], Xml checksum [{$xmlChecksum}], actual checksum [{$checksum}]", KalturaBatchJobAppErrors::BULK_ITEM_VALIDATION_FAILED); } } if (isset($elementToSearchIn->serverFileContentResource->fileSize)) { KalturaLog::debug("Validating file size"); $fileSize = kFile::fileSize($filePath); $xmlFileSize = (int) $elementToSearchIn->serverFileContentResource->fileSize; if ($xmlFileSize != $fileSize) { throw new KalturaBulkUploadXmlException("File size is invalid for file [{$filePath}], Xml size [{$xmlFileSize}], actual size [{$fileSize}]", KalturaBatchJobAppErrors::BULK_ITEM_VALIDATION_FAILED); } } } }
/** * @param KalturaBatchJob $job * @param string $destFile * @param int $fileSize * @return KalturaBatchJob */ private function moveFile(KalturaBatchJob $job, $destFile, $fileSize = null) { KalturaLog::debug("moveFile({$job->id}, {$destFile}, {$fileSize})"); try { // creates a shared file path $rootPath = $this->taskConfig->params->sharedTempPath; $res = self::createDir($rootPath); if (!$res) { KalturaLog::err("Cannot continue import without shared directory"); die; } $uniqid = uniqid('import_'); $sharedFile = realpath($rootPath) . "/{$uniqid}"; $ext = pathinfo($destFile, PATHINFO_EXTENSION); if (strlen($ext)) { $sharedFile .= ".{$ext}"; } KalturaLog::debug("rename('{$destFile}', '{$sharedFile}')"); rename($destFile, $sharedFile); if (!file_exists($sharedFile)) { KalturaLog::err("Error: renamed file doesn't exist"); die; } clearstatcache(); if ($fileSize) { if (kFile::fileSize($sharedFile) != $fileSize) { KalturaLog::err("Error: renamed file have a wrong size"); die; } } else { $fileSize = kFile::fileSize($sharedFile); } @chmod($sharedFile, 0777); $data = $job->data; $data->destFileLocalPath = $sharedFile; if ($this->checkFileExists($sharedFile, $fileSize)) { $this->closeJob($job, null, null, 'Succesfully moved file', KalturaBatchJobStatus::FINISHED, $data); } else { $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, 'File not moved correctly', KalturaBatchJobStatus::RETRY); } } catch (Exception $ex) { $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED); } return $job; }
/** * Put an object * * @param mixed $input Input data * @param string $bucket Bucket name * @param string $uri Object URI * @param constant $acl ACL constant * @param array $metaHeaders Array of x-amz-meta-* headers * @param array $requestHeaders Array of request headers or content type as a string * @param constant $storageClass Storage class constant * @return boolean */ public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD) { if ($input === false) { return false; } $rest = new S3Request('PUT', $bucket, $uri, self::$endpoint); if (is_string($input)) { $input = array('data' => $input, 'size' => strlen($input), 'md5sum' => base64_encode(md5($input, true))); } // Data if (isset($input['fp'])) { $rest->fp =& $input['fp']; } elseif (isset($input['file'])) { $rest->fp = @fopen($input['file'], 'rb'); } elseif (isset($input['data'])) { $rest->data = $input['data']; } // Content-Length (required) if (isset($input['size']) && $input['size'] >= 0) { $rest->size = $input['size']; } else { if (isset($input['file'])) { $rest->size = kFile::fileSize($input['file']); } elseif (isset($input['data'])) { $rest->size = strlen($input['data']); } } // Custom request headers (Content-Type, Content-Disposition, Content-Encoding) if (is_array($requestHeaders)) { foreach ($requestHeaders as $h => $v) { $rest->setHeader($h, $v); } } elseif (is_string($requestHeaders)) { // Support for legacy contentType parameter $input['type'] = $requestHeaders; } // Content-Type if (!isset($input['type'])) { if (isset($requestHeaders['Content-Type'])) { $input['type'] =& $requestHeaders['Content-Type']; } elseif (isset($input['file'])) { $input['type'] = self::__getMimeType($input['file']); } else { $input['type'] = 'application/octet-stream'; } } if ($storageClass !== self::STORAGE_CLASS_STANDARD) { // Storage class $rest->setAmzHeader('x-amz-storage-class', $storageClass); } // We need to post with Content-Length and Content-Type, MD5 is optional if ($rest->size >= 0 && ($rest->fp !== false || $rest->data !== false)) { $rest->setHeader('Content-Type', $input['type']); if (isset($input['md5sum'])) { $rest->setHeader('Content-MD5', $input['md5sum']); } $rest->setAmzHeader('x-amz-acl', $acl); foreach ($metaHeaders as $h => $v) { $rest->setAmzHeader('x-amz-meta-' . $h, $v); } $rest->getResponse(); } else { $rest->response->error = array('code' => 0, 'message' => 'Missing input parameters'); } if ($rest->response->error === false && $rest->response->code !== 200) { $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status'); } if ($rest->response->error !== false) { self::__triggerError(sprintf("S3::putObject(): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__); return false; } return true; }
/** * @param string $file * @param int $size * @return bool */ protected function checkFileExists($file, $size = null, $directorySync = null) { $this->setFilePermissions($file); if ($this->isUnitTest) { KalturaLog::debug("Is in unit test"); return true; } // If this is not a file but a directory, certain operations should be done diffrently: // - size calcultions // - the response from the client (to check the client size beaviour) if (is_null($directorySync)) { $directorySync = is_dir($file); } KalturaLog::info("Check File Exists[{$file}] size[{$size}] isDir[{$directorySync}]"); if (is_null($size)) { clearstatcache(); if ($directorySync) { $size = KBatchBase::foldersize($file); } else { $size = kFile::fileSize($file); } if ($size === false) { KalturaLog::debug("Size not found on file [{$file}]"); return false; } } $retries = self::$taskConfig->fileExistReties ? self::$taskConfig->fileExistReties : 1; $interval = self::$taskConfig->fileExistInterval ? self::$taskConfig->fileExistInterval : 5; while ($retries > 0) { $check = self::$kClient->batch->checkFileExists($file, $size); // In case of directorySync - do not check client sizeOk - to be revised if ($check->exists && ($check->sizeOk || $directorySync)) { $this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_EXISTS); return true; } $this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_DOESNT_EXIST); sleep($interval); $retries--; } KalturaLog::log("Passed max retries"); return false; }
public function execute() { requestUtils::handleConditionalGet(); $entry_id = $this->getRequestParameter("entry_id"); $ks_str = $this->getRequestParameter("ks"); $base64_referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($base64_referrer); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ""; } $clip_from = $this->getRequestParameter("clip_from", 0); // milliseconds $clip_to = $this->getRequestParameter("clip_to", 2147483647); // milliseconds if ($clip_to == 0) { $clip_to = 2147483647; } $request = $_SERVER["REQUEST_URI"]; // remove dynamic fields from the url so we'll request a single url from the cdn $request = str_replace("/referrer/{$base64_referrer}", "", $request); $request = str_replace("/ks/{$ks_str}", "", $request); $entry = null; if ($ks_str) { try { kCurrentContext::initKsPartnerUser($ks_str); } catch (Exception $ex) { KExternalErrors::dieError(KExternalErrors::INVALID_KS); } } else { $entry = kCurrentContext::initPartnerByEntryId($entry_id); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } kEntitlementUtils::initEntitlementEnforcement(); // workaround the filter which hides all the deleted entries - // now that deleted entries are part of xmls (they simply point to the 'deleted' templates), we should allow them here if (!$entry) { $entry = entryPeer::retrieveByPKNoFilter($entry_id); } else { if (!kEntitlementUtils::isEntryEntitled($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } KalturaMonitorClient::initApiMonitor(false, 'keditorservices.flvclipper', $entry->getPartnerId()); myPartnerUtils::blockInactivePartner($entry->getPartnerId()); if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_BLOCK_FLVCLIPPER_ACTION, $entry->getPartnerId())) { KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED); } // set the memory size to be able to serve big files in a single chunk ini_set("memory_limit", "64M"); // set the execution time to be able to serve big files in a single chunk ini_set("max_execution_time", 240); if ($entry->getType() == entryType::MIX && $entry->getStatus() == entryStatus::DELETED) { // because the fiter was turned off - a manual check for deleted entries must be done. KExternalErrors::dieGracefully(); } else { if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $version = $this->getRequestParameter("version", null); $width = $this->getRequestParameter("width", -1); $height = $this->getRequestParameter("height", -1); $crop_provider = $this->getRequestParameter("crop_provider", null); $bgcolor = $this->getRequestParameter("bgcolor", "ffffff"); $type = $this->getRequestParameter("type", 1); $quality = $this->getRequestParameter("quality", 0); $src_x = $this->getRequestParameter("src_x", 0); $src_y = $this->getRequestParameter("src_y", 0); $src_w = $this->getRequestParameter("src_w", 0); $src_h = $this->getRequestParameter("src_h", 0); $vid_sec = $this->getRequestParameter("vid_sec", -1); $vid_slice = $this->getRequestParameter("vid_slice", -1); $vid_slices = $this->getRequestParameter("vid_slices", -1); if ($width == -1 && $height == -1) { $width = 640; $height = 480; } 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; } } } $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); kFileUtils::dumpFile($tempThumbPath, null, strpos($tempThumbPath, "_NOCACHE_") === false ? null : 0); } } $audio_only = $this->getRequestParameter("audio_only"); // milliseconds $flavor = $this->getRequestParameter("flavor", 1); // $flavor_param_id = $this->getRequestParameter("flavor_param_id", null); // $streamer = $this->getRequestParameter("streamer"); // if (substr($streamer, 0, 4) == "rtmp") { // the fms may add .mp4 to the end of the url $streamer = "rtmp"; } // grab seek_from_bytes parameter and normalize url $seek_from_bytes = $this->getRequestParameter("seek_from_bytes", -1); $request = str_replace("/seek_from_bytes/{$seek_from_bytes}", "", $request); if ($seek_from_bytes <= 0) { $seek_from_bytes = -1; } // grab seek_from parameter and normalize url $seek_from = $this->getRequestParameter("seek_from", -1); $request = str_replace("/seek_from/{$seek_from}", "", $request); if ($seek_from <= 0) { $seek_from = -1; } $this->dump_from_byte = 0; // reset accurate seek from timestamp $seek_from_timestamp = -1; // backward compatibility if ($flavor === "0") { // for edit version $flavor = "edit"; } if ($flavor === "1" || $flavor === 1) { // for play version $flavor = null; } // when flavor is null, we will get a default flavor if ($flavor == "edit") { $flavorAsset = assetPeer::retrieveBestEditByEntryId($entry->getId()); } elseif (!is_null($flavor)) { $flavorAsset = assetPeer::retrieveById($flavor); // when specific asset was request, we don't validate its tags if ($flavorAsset && ($flavorAsset->getEntryId() != $entry->getId() || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY)) { $flavorAsset = null; } // we will throw an error later } elseif (is_null($flavor) && !is_null($flavor_param_id)) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor_param_id); if ($flavorAsset && $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { $flavorAsset = null; } // we will throw an error later } else { if ($entry->getSource() == entry::ENTRY_MEDIA_SOURCE_WEBCAM) { $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry->getId()); } else { $flavorAsset = assetPeer::retrieveBestPlayByEntryId($entry->getId()); } if (!$flavorAsset) { $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryIdAndTag($entry->getId(), flavorParams::TAG_WEB); if (count($flavorAssets) > 0) { $flavorAsset = $flavorAssets[0]; } } } if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::file_exists($syncKey, false)) { $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); } else { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) { $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $flavorAsset->getEntryId()), null, $flavorAsset); if (!$urlManager) { KalturaLog::log("Error - failed to find an HTTP delivery for storage profile [" . $fileSync->getDc() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $url = rtrim($urlManager->getUrl(), '/') . '/' . ltrim($urlManager->getFileSyncUrl($fileSync), '/'); header('location: ' . $url); die; } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); $this->redirect($remoteUrl); } $flv_wrapper = new myFlvHandler($path); $isFlv = $flv_wrapper->isFlv(); // scrubbing is not allowed within mp4 files if (!$isFlv) { $seek_from = $seek_from_bytes = -1; } if ($seek_from !== -1 && $seek_from !== 0) { if ($audio_only === '0') { // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) { $audio_only = true; } list($bytes, $duration, $first_tag_byte, $to_byte) = $flv_wrapper->clip(0, -1, $audio_only); list($bytes, $duration, $from_byte, $to_byte, $seek_from_timestamp) = $flv_wrapper->clip($seek_from, -1, $audio_only); $seek_from_bytes = myFlvHandler::FLV_HEADER_SIZE + $flv_wrapper->getMetadataSize($audio_only) + $from_byte - $first_tag_byte; } // the direct path without a cdn is "http://s3kaltura.s3.amazonaws.com".$entry->getDataPath(); $extStorageUrl = $entry->getExtStorageUrl(); if ($extStorageUrl && substr_count($extStorageUrl, 's3kaltura')) { // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $request_host = parse_url($extStorageUrl, PHP_URL_HOST); $akamai_url = str_replace($request_host, "cdns3akmi.kaltura.com", $extStorageUrl); $akamai_url .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$akamai_url}"); KExternalErrors::dieGracefully(); } elseif ($extStorageUrl) { // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $extStorageUrl .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$extStorageUrl}"); KExternalErrors::dieGracefully(); } // use headers to detect cdn $cdn_name = ""; $via_header = @$_SERVER["HTTP_VIA"]; if (strpos($via_header, "llnw.net") !== false) { $cdn_name = "limelight"; } else { if (strpos($via_header, "akamai") !== false) { $cdn_name = "akamai"; } else { if (strpos($via_header, "Level3") !== false) { $cdn_name = "level3"; } } } // setting file extension - first trying frrom flavor asset $ext = $flavorAsset->getFileExt(); // if failed, set extension according to file type (isFlv) if (!$ext) { $ext = $isFlv ? "flv" : "mp4"; } $flv_extension = $streamer == "rtmp" ? "?" : "/a.{$ext}?novar=0"; // dont check for rtmp / and for an already redirect url if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) { // check security using ks $securyEntryHelper = new KSecureEntryHelper($entry, $ks_str, $referrer, ContextType::PLAY); if ($securyEntryHelper->shouldPreview()) { $this->checkForPreview($securyEntryHelper, $clip_to); } else { $securyEntryHelper->validateForPlay($entry, $ks_str); } } else { // if needs security check using cdn authentication mechanism // for now assume this is a cdn request and don't check for security } // use limelight mediavault if either security policy requires it or if we're trying to seek within the video if ($entry->getSecurityPolicy() || $seek_from_bytes !== -1) { // we have three options: // arrived through limelight mediavault url - the url is secured // arrived directly through limelight (not secured through mediavault) - enforce ks and redirect to mediavault url // didnt use limelight - enforce ks // the cdns are configured to authenticate request for /s/.... // check if we're already in a redirected secure link using the "/s/" prefix $secure_request = substr($request, 0, 3) == "/s/"; if ($secure_request && ($cdn_name == "limelight" || $cdn_name == "level3")) { // request was validated by cdn let it through } else { // extract ks $ks_str = $this->getRequestParameter("ks", ""); if ($entry->getSecurityPolicy()) { if (!$ks_str) { $this->logMessage("flvclipper - no KS"); KExternalErrors::dieGracefully(); } $ks = kSessionUtils::crackKs($ks_str); if (!$ks) { $this->logMessage("flvclipper - invalid ks [{$ks_str}]"); KExternalErrors::dieGracefully(); } $matched_privs = $ks->verifyPrivileges("sview", $entry_id); $this->logMessage("flvclipper - verifyPrivileges name [sview], priv [{$entry_id}] [{$matched_privs}]"); if (!$matched_privs) { $this->logMessage("flvclipper - doesnt not match required privlieges [{$ks_str}]"); KExternalErrors::dieGracefully(); } } if ($cdn_name == "limelight") { $ll_url = requestUtils::getCdnHost() . "/s{$request}" . $flv_extension; $secret = kConf::get("limelight_madiavault_password"); $expire = "&e=" . (time() + 120); $ll_url .= $expire; $fs = $seek_from_bytes == -1 ? "" : "&fs={$seek_from_bytes}"; $ll_url .= "&h=" . md5("{$secret}{$ll_url}") . $fs; //header("Location: $ll_url"); $this->redirect($ll_url); } else { if ($cdn_name == "level3") { $level3_url = $request . $flv_extension; if ($entry->getSecurityPolicy()) { $level3_url = "/s{$level3_url}"; // set expire time in GMT hence the date("Z") offset $expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30); $level3_url .= $expire; $secret = kConf::get("level3_authentication_key"); $hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20); $level3_url .= "&h={$hash}"; } $level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}"; header("Location: {$level3_url}"); KExternalErrors::dieGracefully(); } else { if ($cdn_name == "akamai") { $akamai_url = $request . $flv_extension; // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$akamai_url}"); KExternalErrors::dieGracefully(); } } } // a seek request without a supporting cdn - we need to send the answer from our server if ($seek_from_bytes !== -1 && $via_header === null) { $this->dump_from_byte = $seek_from_bytes; } } } // always add the file suffix to the request (needed for scrubbing by some cdns, // and also breaks without extension on some corporate antivirus). // we add the the novar paramter since a leaving a trailing "?" will be trimmed // and then the /seek_from request will result in another url which level3 // will try to refetch from the origin // note that for streamer we dont add the file extension if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) { // a seek request without a supporting cdn - we need to send the answer from our server if ($seek_from_bytes !== -1 && $via_header === null) { $request .= "/seek_from_bytes/{$seek_from_bytes}"; } requestUtils::sendCdnHeaders("flv", 0); header("Location: {$request}" . $flv_extension); KExternalErrors::dieGracefully(); } // mp4 if (!$isFlv) { $limit_file_size = 0; if ($clip_to != 2147483647) { $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) { $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration()); $limit_file_size = floor(@kFile::fileSize($path) * ($clip_to / $duration) * 1.2); } } KalturaLog::info("serving file [{$path}] entry id [{$entry_id}] limit file size [{$limit_file_size}] clip_to [{$clip_to}]"); kFileUtils::dumpFile($path, null, null, $limit_file_size); } $this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning"); if ($audio_only === '0') { // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) { $audio_only = true; } //$start = microtime(true); list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only); $metadata_size = $flv_wrapper->getMetadataSize($audio_only); $this->from_byte = $from_byte; $this->to_byte = $to_byte; //$end1 = microtime(true); //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" ); //$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]"); $data_offset = $metadata_size + myFlvHandler::getHeaderSize(); // if we're returning a partial file adjust the total size: // substract the metadata and bytes which are not delivered if ($this->dump_from_byte >= $data_offset && !$audio_only) { $bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset); } $this->total_length = $data_offset + $bytes; //echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die; $this->cuepoint_time = 0; $this->cuepoint_pos = 0; if ($streamer == "chunked" && $clip_to != 2147483647) { $this->cuepoint_time = $clip_to - 1; $this->cuepoint_pos = $cuepoint_pos; $this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE; } //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" ); $this->flv_wrapper = $flv_wrapper; $this->audio_only = $audio_only; try { Propel::close(); } catch (Exception $e) { $this->logMessage("flvclipperAction: error closing db {$e}"); } KExternalErrors::terminateDispatch(); return sfView::SUCCESS; }
/** * @param string $srcFileSyncRemoteUrl * @param string $srcFileSyncLocalPath * @param string $errDescription * @return string */ private function fetchFile($srcFileSyncRemoteUrl, $srcFileSyncLocalPath, &$errDescription = null) { KalturaLog::debug("fetchFile({$srcFileSyncRemoteUrl}, {$srcFileSyncLocalPath})"); try { $curlWrapper = new KCurlWrapper($srcFileSyncRemoteUrl); $curlHeaderResponse = $curlWrapper->getHeader(true); if (!$curlHeaderResponse || $curlWrapper->getError()) { $errDescription = "Error: " . $curlWrapper->getError(); return false; } if ($curlHeaderResponse->code != KCurlHeaderResponse::HTTP_STATUS_OK) { $errDescription = "HTTP Error: " . $curlHeaderResponse->code . " " . $curlHeaderResponse->codeName; return false; } $fileSize = null; KalturaLog::debug("Headers:\n" . print_r($curlHeaderResponse->headers, true)); if (isset($curlHeaderResponse->headers['content-length'])) { $fileSize = $curlHeaderResponse->headers['content-length']; } $curlWrapper->close(); if ($fileSize && file_exists($srcFileSyncLocalPath)) { clearstatcache(); $actualFileSize = kFile::fileSize($srcFileSyncLocalPath); if ($actualFileSize == $fileSize) { KalturaLog::log("File [{$srcFileSyncLocalPath}] already exists with right size[{$fileSize}]"); return true; } KalturaLog::log("File [{$srcFileSyncLocalPath}] already exists with wrong size[{$actualFileSize}] expected size[{$fileSize}]"); KalturaLog::debug("Unlink file[{$srcFileSyncLocalPath}]"); unlink($srcFileSyncLocalPath); } KalturaLog::debug("Executing curl"); $curlWrapper = new KCurlWrapper($srcFileSyncRemoteUrl); $res = $curlWrapper->exec($srcFileSyncLocalPath); KalturaLog::debug("Curl results: {$res}"); if (!$res || $curlWrapper->getError()) { $errDescription = "Error: " . $curlWrapper->getError(); $curlWrapper->close(); return false; } $curlWrapper->close(); if (!file_exists($srcFileSyncLocalPath)) { $errDescription = "Error: output file[{$srcFileSyncLocalPath}] doesn't exist"; return false; } clearstatcache(); $actualFileSize = kFile::fileSize($srcFileSyncLocalPath); KalturaLog::debug("Fetched file to [{$srcFileSyncLocalPath}] size[{$actualFileSize}]"); if ($fileSize) { if ($actualFileSize != $fileSize) { $errDescription = "Error: output file[{$srcFileSyncLocalPath}] have a wrong size[{$actualFileSize}] expected size[{$fileSize}]"; return false; } } } catch (Exception $ex) { $errDescription = "Error: " . $ex->getMessage(); return false; } return true; }
private function moveFiles(KalturaBatchJob $job, KalturaConvertCollectionJobData $data) { KalturaLog::debug("moveFiles(destDirLocalPath [{$data->destDirLocalPath}])"); clearstatcache(); $files2move = array(); $fileNames = array($data->destFileName . '.log', $data->destFileName . '.ism', $data->destFileName . '.ismc', $data->destFileName . '_Thumb.jpg'); foreach ($fileNames as $fileName) { $srcPath = $data->destDirLocalPath . DIRECTORY_SEPARATOR . $fileName; if (!file_exists($srcPath)) { continue; } $destPath = $this->sharedTempPath . DIRECTORY_SEPARATOR . $fileName; $sharedPath = $this->translateLocalPath2Shared($destPath); $fileSize = kFile::fileSize($srcPath); KalturaLog::debug("add to move list file[{$srcPath}] to[{$destPath}] size[{$fileSize}] shared path[{$sharedPath}]"); $files2move[] = array('from' => $srcPath, 'to' => $destPath, 'path' => $sharedPath, 'size' => $fileSize); } foreach ($data->flavors as $flavor) { $srcPath = $flavor->destFileSyncLocalPath; if (!file_exists($srcPath)) { continue; } $destPath = $this->sharedTempPath . DIRECTORY_SEPARATOR . basename($srcPath); $sharedPath = $this->translateLocalPath2Shared($destPath); $fileSize = kFile::fileSize($srcPath); $flavor->destFileSyncLocalPath = $sharedPath; if ($this->taskConfig->params->isRemoteOutput) { $flavor->destFileSyncRemoteUrl = $this->distributedFileManager->getRemoteUrl($sharedPath); } KalturaLog::debug("add to move list file[{$srcPath}] to[{$destPath}] size[{$fileSize}] shared path[{$sharedPath}]"); $files2move[] = array('from' => $srcPath, 'to' => $destPath, 'path' => $sharedPath, 'size' => $fileSize); } foreach ($files2move as $file2move) { $srcPath = $file2move['from']; $destPath = $file2move['to']; $fileSize = $file2move['size']; KalturaLog::debug("moving file[{$srcPath}] to[{$destPath}] size[{$fileSize}]"); if (file_exists($destPath)) { KalturaLog::debug("delete existing file[{$destPath}]"); unlink($destPath); } KalturaLog::debug("rename({$srcPath}, {$destPath})"); rename($srcPath, $destPath); if (!file_exists($destPath) || kFile::fileSize($destPath) != $fileSize) { KalturaLog::err("Error: moving file [{$srcPath}] failed"); die; } @chmod($destPath, 0777); } $data->destDirLocalPath = $this->translateLocalPath2Shared($this->sharedTempPath); if ($this->taskConfig->params->isRemoteOutput) { $data->destDirRemoteUrl = $this->distributedFileManager->getRemoteUrl($data->destDirLocalPath); $job->status = KalturaBatchJobStatus::ALMOST_DONE; $job->message = "Files ready for download"; } elseif ($this->checkFilesArrayExist($files2move)) { $job->status = KalturaBatchJobStatus::FINISHED; $job->message = "Files moved to shared"; } else { $job->status = KalturaBatchJobStatus::RETRY; $job->message = "Files not moved correctly"; } return $this->closeJob($job, null, null, $job->message, $job->status, $data); }
private function moveFile(KalturaBatchJob $job, KalturaConvertJobData $data) { KalturaLog::debug("moveFile({$job->id}, {$data->destFileSyncLocalPath})"); $uniqid = uniqid("convert_{$job->entryId}_"); $sharedFile = "{$this->sharedTempPath}/{$uniqid}"; if (!$data->flavorParamsOutput->sourceRemoteStorageProfileId) { clearstatcache(); $fileSize = kFile::fileSize($data->destFileSyncLocalPath); kFile::moveFile($data->destFileSyncLocalPath, $sharedFile); // directory sizes may differ on different devices if (!file_exists($sharedFile) || is_file($sharedFile) && kFile::fileSize($sharedFile) != $fileSize) { KalturaLog::err("Error: moving file failed"); die; } @chmod($sharedFile, 0777); $data->destFileSyncLocalPath = $this->translateLocalPath2Shared($sharedFile); if ($this->taskConfig->params->isRemoteOutput) { $data->destFileSyncRemoteUrl = $this->distributedFileManager->getRemoteUrl($data->destFileSyncLocalPath); $job->status = KalturaBatchJobStatus::ALMOST_DONE; $job->message = "File ready for download"; } elseif ($this->checkFileExists($data->destFileSyncLocalPath, $fileSize)) { $job->status = KalturaBatchJobStatus::FINISHED; $job->message = "File moved to shared"; } else { $job->status = KalturaBatchJobStatus::RETRY; $job->message = "File not moved correctly"; } } else { $job->status = KalturaBatchJobStatus::FINISHED; $job->message = "File is ready in the remote storage"; } if ($data->logFileSyncLocalPath && file_exists($data->logFileSyncLocalPath)) { kFile::moveFile($data->logFileSyncLocalPath, "{$sharedFile}.log"); @chmod("{$sharedFile}.log", 0777); $data->logFileSyncLocalPath = $this->translateLocalPath2Shared("{$sharedFile}.log"); if ($this->taskConfig->params->isRemoteOutput) { // for remote conversion $data->logFileSyncRemoteUrl = $this->distributedFileManager->getRemoteUrl($data->logFileSyncLocalPath); } } else { $data->logFileSyncLocalPath = ''; } return $this->closeJob($job, null, null, $job->message, $job->status, $data); }
/** * batch checkFileExists action check if the file exists * * @action checkFileExists * @param string $localPath * @param float $size * @return KalturaFileExistsResponse */ function checkFileExistsAction($localPath, $size) { $ret = new KalturaFileExistsResponse(); $ret->exists = file_exists($localPath); $ret->sizeOk = false; if ($ret->exists) { clearstatcache(); $ret->sizeOk = kFile::fileSize($localPath) == $size; } return $ret; }
/** * * Creates an upload token and uploads the file using the token. * @param KalturaEmailIngestionProfile $profile * @param string $filename */ private function createUploadTokenAndUpload($profile, $filename) { self::impersonate($profile->partnerId); $this->getClient()->startMultiRequest(); $uploadToken = new KalturaUploadToken(); $uploadToken->fileName = $filename; $uploadToken->fileSize = kFile::fileSize($filename); $uploadToken = $this->getClient()->uploadToken->add($uploadToken); $this->getClient()->uploadToken->upload($uploadToken->id, realpath($filename)); return $this->getClient()->doMultiRequest(); }
private function setObjectContent($assetObject, $content, $accuracy = null, $format = null, $shouldSetTranscriptFileName = false) { $assetObject->incrementVersion(); $ext = "txt"; if ($format) { if ($format == "DFXP") { $ext = "xml"; } if ($format == "SRT") { $ext = "srt"; } } $assetObject->setFileExt($ext); $assetObject->save(); $syncKey = $assetObject->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::file_put_contents($syncKey, $content); $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey); $assetObject->setSize(kFile::fileSize($finalPath)); if ($shouldSetTranscriptFileName && !$assetObject->getFileName()) { $language = str_replace(" ", "", $assetObject->getLanguage()); $patterns = array("{entryId}", "{language}"); $replacements = array($assetObject->getEntryId(), $language); $fileName = str_replace($patterns, $replacements, self::FILE_NAME_PATTERN); $assetObject->setFileName($fileName); } if (!$accuracy) { $accuracy = self::DEFAULT_ACCURACY; } $assetObject->setAccuracy($accuracy); $assetObject->setStatus(AttachmentAsset::ASSET_STATUS_READY); $assetObject->save(); }
/** * @param AttachmentAsset $attachmentAsset * @param FileSyncKey $srcSyncKey */ protected function attachFileSync(AttachmentAsset $attachmentAsset, FileSyncKey $srcSyncKey) { $attachmentAsset->incrementVersion(); $attachmentAsset->save(); $newSyncKey = $attachmentAsset->getSyncKey(AttachmentAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::createSyncFileLinkForKey($newSyncKey, $srcSyncKey); $finalPath = kFileSyncUtils::getLocalFilePathForKey($newSyncKey); list($width, $height, $type, $attr) = getimagesize($finalPath); $attachmentAsset->setWidth($width); $attachmentAsset->setHeight($height); $attachmentAsset->setSize(kFile::fileSize($finalPath)); $attachmentAsset->setStatus(AttachmentAsset::ASSET_STATUS_READY); $attachmentAsset->save(); }
private function moveExtraFiles(KalturaConvertJobData &$data, $sharedFile) { $i = 0; foreach ($data->extraDestFileSyncs as $destFileSync) { $i++; clearstatcache(); $directorySync = is_dir($destFileSync->fileSyncLocalPath); if ($directorySync) { $fileSize = KBatchBase::foldersize($destFileSync->fileSyncLocalPath); } else { $fileSize = kFile::fileSize($destFileSync->fileSyncLocalPath); } $ext = pathinfo($destFileSync->fileSyncLocalPath, PATHINFO_EXTENSION); if ($ext) { $newName = $sharedFile . '.' . $ext; } else { $newName = $sharedFile . '.' . $i; } kFile::moveFile($destFileSync->fileSyncLocalPath, $newName); // directory sizes may differ on different devices if (!file_exists($newName) || is_file($newName) && kFile::fileSize($newName) != $fileSize) { KalturaLog::err("Error: moving file failed"); die; } $destFileSync->fileSyncLocalPath = $this->translateLocalPath2Shared($newName); if (self::$taskConfig->params->isRemoteOutput) { $destFileSync->fileSyncRemoteUrl = $this->distributedFileManager->getRemoteUrl($destFileSync->fileSyncLocalPath); } } }
public static function handleImportContent($curlInfo, $importData, $params) { if (!($curlInfo->headers['content-length'] < 16000 && $curlInfo->headers['content-type'] == 'text/html')) { return $importData; } KalturaLog::debug('content-length [' . $curlInfo->headers['content-length'] . '] content-type [' . $curlInfo->headers['content-type'] . ']'); KalturaLog::info('Handle Import data: Webex Plugin'); $matches = null; $recordId = null; if (isset($curlInfo->headers['set-cookie'])) { $recordId = $curlInfo->getCookieValue($curlInfo->headers['set-cookie'], 'recordId'); if ($recordId == null) { throw new Exception('recordId value not found'); } } else { throw new Exception('set-cookie was not found in header'); } $data = file_get_contents($importData->destFileLocalPath); KalturaLog::info("data:\n\n{$data}\n\n"); if (!preg_match("/href='([^']+)';/", $data, $matches)) { throw new Exception('Starting URL not found'); } $url2 = $matches[1]; $curlWrapper = new KCurlWrapper(); $curlWrapper->setOpt(CURLOPT_COOKIE, 'DetectionBrowserStatus=3|1|32|1|11|2;' . $curlInfo->headers["set-cookie"]); $result = $curlWrapper->exec($url2); KalturaLog::info("result:\n\n{$result}\n\n"); if (!preg_match("/var prepareTicket = '([^']+)';/", $result, $matches)) { throw new Exception('prepareTicket parameter not found'); } $prepareTicket = $matches[1]; if (!preg_match('/function (download\\(\\).+prepareTicket;)/s', $result, $matches)) { throw new Exception('download function not found'); } if (!preg_match('/http.+prepareTicket/', $matches[0], $matches)) { throw new Exception('prepareTicket URL not found'); } $url3 = $matches[0]; $url3 = str_replace(array('"', ' ', '+', 'recordId', 'prepareTicket=prepareTicket'), array('', '', '', $recordId, "prepareTicket={$prepareTicket}"), $url3); if (!preg_match("/var downloadUrl = '(http[^']+)' \\+ ticket;/", $result, $matches)) { throw new Exception('Download URL not found'); } $url4 = $matches[1]; $status = null; $iterations = isset($params->webex->iterations) && !is_null($params->webex->iterations) ? intval($params->webex->iterations) : 10; $sleep = isset($params->webex->sleep) && !is_null($params->webex->sleep) ? intval($params->webex->sleep) : 3; for ($i = 0; $i < $iterations; $i++) { $result = $curlWrapper->exec($url3); KalturaLog::info("result ({$i}):\n\n{$result}\n\n"); if (!preg_match("/window\\.parent\\.func_prepare\\('([^']+)','([^']*)','([^']*)'\\);/", $result, $matches)) { KalturaLog::err("Invalid result returned for prepareTicket request - should contain call to the func_prepare method\n {$result}"); throw new Exception('Invalid result: func_prepare function not found'); } $status = $matches[1]; if ($status == 'OKOK') { break; } sleep($sleep); } if ($status != 'OKOK') { KalturaLog::info("Invalid result returned for prepareTicket request. Last result:\n " . $result); throw new kTemporaryException('Invalid result returned for prepareTicket request'); } $ticket = $matches[3]; $url4 .= $ticket; $curlWrapper->setOpt(CURLOPT_RETURNTRANSFER, false); $fileName = pathinfo($importData->destFileLocalPath, PATHINFO_FILENAME); $destFileLocalPath = preg_replace("/{$fileName}\\.[\\w\\d]+/", "{$fileName}.arf", $importData->destFileLocalPath); $importData->destFileLocalPath = $destFileLocalPath; KalturaLog::info('destination: ' . $importData->destFileLocalPath); $result = $curlWrapper->exec($url4, $importData->destFileLocalPath); if (!$result) { $code = $curlWrapper->getErrorNumber(); $message = $curlWrapper->getError(); throw new Exception($message, $code); } $curlWrapper->close(); $importData->fileSize = kFile::fileSize($importData->destFileLocalPath); return $importData; }
/** * @param string $remotePath * @param string $localPath * @param string $errDescription * @return boolean */ private function fetchFile($remotePath, $localPath, &$errDescription) { KalturaLog::debug("Fetch url [{$remotePath}] to file [{$localPath}]"); try { $folder = substr($localPath, 0, strrpos($localPath, '/')); if (!file_exists($folder)) { mkdir($folder, 777, true); } $curlWrapper = new KCurlWrapper(); $curlHeaderResponse = $curlWrapper->getHeader($remotePath, true); $removeServer = isset($curlHeaderResponse->headers['X-Me']) ? $curlHeaderResponse->headers['X-Me'] : "unknown"; if (!$curlHeaderResponse || $curlWrapper->getError()) { $errDescription = "Error: ({$removeServer}) " . $curlWrapper->getError(); return false; } if (!$curlHeaderResponse->isGoodCode()) { $errDescription = "HTTP Error: ({$removeServer}) " . $curlHeaderResponse->code . " " . $curlHeaderResponse->codeName; return false; } $fileSize = null; if (isset($curlHeaderResponse->headers['content-length'])) { $fileSize = $curlHeaderResponse->headers['content-length']; } $curlWrapper->close(); KalturaLog::debug("Executing curl"); // overcome a 32bit issue with curl fetching >=4gb files if (intval("9223372036854775807") == 2147483647 && $fileSize >= 4 * 1024 * 1024 * 1024) { unlink($localPath); $cmd = "curl -s {$remotePath} -o {$localPath}"; KalturaLog::debug($cmd); exec($cmd); } else { $curlWrapper = new KCurlWrapper(); $res = $curlWrapper->exec($remotePath, $localPath); KalturaLog::debug("Curl results: {$res}"); if (!$res || $curlWrapper->getError()) { $errDescription = "Error: ({$removeServer}) " . $curlWrapper->getError(); $curlWrapper->close(); return false; } $curlWrapper->close(); } if (!file_exists($localPath)) { $errDescription = "Error: output file doesn't exist"; return false; } if ($fileSize) { clearstatcache(); if (kFile::fileSize($localPath) != $fileSize) { $errDescription = "Error: output file have a wrong size"; return false; } } } catch (Exception $ex) { $errDescription = "Error: " . $ex->getMessage(); return false; } return true; }
/** * @param string $srcFileSyncRemoteUrl * @param string $srcFileSyncLocalPath * @param string $errDescription * @return string */ private function fetchFile($srcFileSyncRemoteUrl, $srcFileSyncLocalPath, &$errDescription = null) { KalturaLog::debug("fetchFile({$srcFileSyncRemoteUrl}, {$srcFileSyncLocalPath})"); try { $curlWrapper = new KCurlWrapper($srcFileSyncRemoteUrl); $curlHeaderResponse = $curlWrapper->getHeader(true); if (!$curlHeaderResponse || $curlWrapper->getError()) { $errDescription = "Error: " . $curlWrapper->getError(); return false; } if ($curlHeaderResponse->code != KCurlHeaderResponse::HTTP_STATUS_OK) { $errDescription = "HTTP Error: " . $curlHeaderResponse->code . " " . $curlHeaderResponse->codeName; return false; } $fileSize = null; if (isset($curlHeaderResponse->headers['content-length'])) { $fileSize = $curlHeaderResponse->headers['content-length']; } $curlWrapper->close(); KalturaLog::debug("Executing curl"); $curlWrapper = new KCurlWrapper($srcFileSyncRemoteUrl); $res = $curlWrapper->exec($srcFileSyncLocalPath); KalturaLog::debug("Curl results: {$res}"); if (!$res || $curlWrapper->getError()) { $errDescription = "Error: " . $curlWrapper->getError(); $curlWrapper->close(); return false; } $curlWrapper->close(); if (!file_exists($srcFileSyncLocalPath)) { $errDescription = "Error: output file doesn't exist"; return false; } if ($fileSize) { clearstatcache(); if (kFile::fileSize($srcFileSyncLocalPath) != $fileSize) { $errDescription = "Error: output file have a wrong size"; return false; } } } catch (Exception $ex) { $errDescription = "Error: " . $ex->getMessage(); return false; } return true; }
/** * Checks downloaded file. * Changes the file mode and owner if required. * * @param string $destFile * @param int $fileSize */ private function checkFile($destFile, $fileSize = null) { KalturaLog::debug("checkFile({$destFile}, {$fileSize})"); if (!file_exists($destFile)) { // destination file does not exist KalturaLog::err("file [{$destFile}] doesn't exist"); return false; } $actualSize = kFile::fileSize($destFile); if (!$fileSize) { $fileSize = $actualSize; } else { if ($actualSize != $fileSize) { // destination file size is wrong KalturaLog::err("file [{$destFile}] has a wrong size. file size: [{$actualSize}] should be [{$fileSize}]"); return false; } } // set file owner $chown_name = self::$taskConfig->params->fileOwner; if ($chown_name) { KalturaLog::debug("Changing owner of file [{$destFile}] to [{$chown_name}]"); @chown($destFile, $chown_name); } // set file mode $chmod_perm = octdec(self::$taskConfig->params->fileChmod); if (!$chmod_perm) { $chmod_perm = 0644; } KalturaLog::debug("Changing mode of file [{$destFile}] to [{$chmod_perm}]"); @chmod($destFile, $chmod_perm); // IMPORTANT - check's if file is seen by apache if (!$this->checkFileExists($destFile, $fileSize)) { return false; } return true; }
protected function moveDataFile(KalturaConvertLiveSegmentJobData $data, $localTempAmfFilePath, $sharedTempAmfFilePath) { KalturaLog::debug('moving file from ' . $localTempAmfFilePath . ' to ' . $sharedTempAmfFilePath); kFile::moveFile($localTempAmfFilePath, $sharedTempAmfFilePath, true); clearstatcache(); $fileSize = kFile::fileSize($sharedTempAmfFilePath); $this->setFilePermissions($sharedTempAmfFilePath); if (!$this->checkFileExists($sharedTempAmfFilePath, $fileSize)) { KalturaLog::warning('failed to move file to ' . $sharedTempAmfFilePath); } else { $data->destDataFilePath = $sharedTempAmfFilePath; } }
public function crop($quality, $cropType, $width = 0, $height = 0, $cropX = 0, $cropY = 0, $cropWidth = 0, $cropHeight = 0, $scaleWidth = 1, $scaleHeight = 1, $bgcolor = 0xffffff, $density = 0, $forceRotation = null, $strip = false) { if (is_null($quality)) { $quality = 100; } if (is_null($cropType)) { $cropType = 1; } if (is_null($width)) { $width = 0; } if (is_null($height)) { $height = 0; } if (is_null($cropX)) { $cropX = 0; } if (is_null($cropY)) { $cropY = 0; } if (is_null($cropWidth)) { $cropWidth = 0; } if (is_null($cropHeight)) { $cropHeight = 0; } if (is_null($scaleWidth)) { $scaleWidth = 1; } if (is_null($scaleHeight)) { $scaleHeight = 1; } if (is_null($bgcolor)) { $bgcolor = 0; } $cmd = $this->getCommand($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor, $density, $forceRotation, $strip); if ($cmd) { KalturaLog::info("Executing: {$cmd}"); $returnValue = null; exec($cmd, $output, $returnValue); KalturaLog::debug("Returned value: {$returnValue} Output: " . print_r($output, true)); //Avoid certain images the image magic throws "no pixels defined in cache ... @ cache.c/OpenPixelCache/3789" exception but still generates the cropped image $outputAsString = implode(" ", $output); if ($returnValue && strpos($outputAsString, "no pixels defined in cache") === false && strpos($outputAsString, "cache.c/OpenPixelCache") === false) { return false; } // Support animated gifs - KImageMagick generates multiple images with a postfix of '-<frame num>' if (!file_exists($this->targetPath) || !kFile::fileSize($this->targetPath)) { $targetFiledir = pathinfo($this->targetPath, PATHINFO_DIRNAME); $targetFilename = pathinfo($this->targetPath, PATHINFO_FILENAME); $targetFileext = pathinfo($this->targetPath, PATHINFO_EXTENSION); $firstFrameTargetFile = "{$targetFiledir}/{$targetFilename}-0.{$targetFileext}"; if (file_exists($firstFrameTargetFile) && kFile::fileSize($firstFrameTargetFile)) { kFile::moveFile($firstFrameTargetFile, $this->targetPath); } } return true; } KalturaLog::info("No conversion required, copying source[{$this->srcPath}] to target[{$this->targetPath}]"); return copy($this->srcPath, $this->targetPath); }
/** * @param KalturaBatchJob $job * @param KalturaPostConvertJobData $data * @return KalturaBatchJob */ private function moveFile(KalturaBatchJob $job, KalturaPostConvertJobData $data) { // creates a temp file path $rootPath = KBatchBase::$taskConfig->params->sharedTempPath; if (!is_dir($rootPath)) { if (!file_exists($rootPath)) { KalturaLog::info("Creating temp thumbnail directory [{$rootPath}]"); mkdir($rootPath); } else { // already exists but not a directory $err = "Cannot create temp thumbnail directory [{$rootPath}] due to an error. Please fix and restart"; throw new Exception($err, -1); } } $uniqid = uniqid('thumb_'); $sharedFile = realpath($rootPath) . DIRECTORY_SEPARATOR . $uniqid; clearstatcache(); $fileSize = kFile::fileSize($data->thumbPath); rename($data->thumbPath, $sharedFile); if (!file_exists($sharedFile) || kFile::fileSize($sharedFile) != $fileSize) { $err = 'moving file failed'; throw new Exception($err, -1); } $this->setFilePermissions($sharedFile); $data->thumbPath = $sharedFile; $job->data = $data; return $job; }
public function getSize() { return kFile::fileSize($this->info_file_name); }
/** * @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); }