本文整理汇总了PHP中kFileSyncUtils::moveFromFile方法的典型用法代码示例。如果您正苦于以下问题:PHP kFileSyncUtils::moveFromFile方法的具体用法?PHP kFileSyncUtils::moveFromFile怎么用?PHP kFileSyncUtils::moveFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kFileSyncUtils
的用法示例。
在下文中一共展示了kFileSyncUtils::moveFromFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addParseCaptionAssetJob
/**
* @param CaptionAsset $captionAsset
* @param BatchJob $parentJob
* @throws kCoreException FILE_NOT_FOUND
* @return BatchJob
*/
public function addParseCaptionAssetJob(CaptionAsset $captionAsset, BatchJob $parentJob = null)
{
$syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
$fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
if (!$fileSync) {
if (!PermissionPeer::isValidForPartner(CaptionPermissionName::IMPORT_REMOTE_CAPTION_FOR_INDEXING, $captionAsset->getPartnerId())) {
throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
}
$fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
if (!$fileSync) {
throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
}
$fullPath = myContentStorage::getFSUploadsPath() . '/' . $captionAsset->getId() . '.tmp';
if (!kFile::downloadUrlToFile($fileSync->getExternalUrl($captionAsset->getEntryId()), $fullPath)) {
throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
}
kFileSyncUtils::moveFromFile($fullPath, $syncKey, true, false, true);
}
$jobData = new kParseCaptionAssetJobData();
$jobData->setCaptionAssetId($captionAsset->getId());
$batchJob = null;
if ($parentJob) {
$batchJob = $parentJob->createChild();
} else {
$batchJob = new BatchJob();
$batchJob->setEntryId($captionAsset->getEntryId());
$batchJob->setPartnerId($captionAsset->getPartnerId());
}
return kJobsManager::addJob($batchJob, $jobData, CaptionSearchPlugin::getBatchJobTypeCoreValue(CaptionSearchBatchJobType::PARSE_CAPTION_ASSET));
}
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:36,代码来源:kCaptionSearchFlowManager.php
示例2: syncAction
/**
* @action sync
* @param int $fileSyncId
* @param file $fileData
* @return KalturaFileSync
*/
function syncAction($fileSyncId, $fileData)
{
$dbFileSync = FileSyncPeer::retrieveByPK($fileSyncId);
if (!$dbFileSync) {
throw new APIException(APIErrors::INVALID_FILE_SYNC_ID, $fileSyncId);
}
$key = kFileSyncUtils::getKeyForFileSync($dbFileSync);
kFileSyncUtils::moveFromFile($fileData['tmp_name'], $key, false);
list($file_root, $real_path) = kPathManager::getFilePathArr($key);
$full_path = $file_root . $real_path;
chmod($full_path, 0644);
if (file_exists($full_path)) {
$dbFileSync->setFileRoot($file_root);
$dbFileSync->setFilePath($real_path);
$dbFileSync->setFileSizeFromPath($full_path);
$dbFileSync->setStatus(FileSync::FILE_SYNC_STATUS_READY);
} else {
$dbFileSync->setFileSize(-1);
$dbFileSync->setStatus(FileSync::FILE_SYNC_STATUS_ERROR);
}
$dbFileSync->save();
$fileSync = new KalturaFileSync();
$fileSync->fromObject($dbFileSync);
return $fileSync;
}
示例3: addFromUploadedFileAction
/**
* Add new document entry after the specific document file was uploaded and the upload token id exists
*
* @action addFromUploadedFile
* @param KalturaDocumentEntry $documentEntry Document entry metadata
* @param string $uploadTokenId Upload token id
* @return KalturaDocumentEntry The new document entry
*
* @throws KalturaErrors::PROPERTY_VALIDATION_MIN_LENGTH
* @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
* @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
*/
function addFromUploadedFileAction(KalturaDocumentEntry $documentEntry, $uploadTokenId)
{
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)) {
$remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId());
if ($remoteDCHost) {
kFile::dumpApiRequest($remoteDCHost);
} else {
throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
}
}
$dbEntry = $this->prepareEntryForInsert($documentEntry);
$dbEntry->setSource(KalturaSourceType::FILE);
$dbEntry->setSourceLink("file:{$entryFullPath}");
$dbEntry->save();
$te = new TrackEntry();
$te->setEntryId($dbEntry->getId());
$te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY);
$te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_FILE");
TrackEntry::addTrackEntry($te);
$msg = null;
$flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId(), $msg);
if (!$flavorAsset) {
KalturaLog::err("Flavor asset not created for entry [" . $dbEntry->getId() . "] reason [{$msg}]");
$dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
$dbEntry->save();
} else {
$ext = pathinfo($entryFullPath, PATHINFO_EXTENSION);
KalturaLog::info("Uploaded file extension: {$ext}");
$flavorAsset->setFileExt($ext);
$flavorAsset->save();
$syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
kFileSyncUtils::moveFromFile($entryFullPath, $syncKey);
kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
}
kUploadTokenMgr::closeUploadTokenById($uploadTokenId);
myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry);
$documentEntry->fromObject($dbEntry);
return $documentEntry;
}
示例4: handleJobFinished
public static function handleJobFinished(BatchJob $job, kScheduledTaskJobData $data)
{
$resultFilePath = $data->getResultsFilePath();
if (!file_exists($resultFilePath)) {
return self::finishJobWithError($job, 'Results file was not found');
}
// we are using the bulk upload sync key, as this should actually be a generic sync key for batch job object
$syncKey = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD);
try {
kFileSyncUtils::moveFromFile($resultFilePath, $syncKey, true);
} catch (Exception $ex) {
KalturaLog::err($ex);
return self::finishJobWithError($job, 'Failed to move file: ' . $ex->getMessage());
}
return $job;
}
示例5: addAction
/**
* Add new bulk upload batch job
* Conversion profile id can be specified in the API or in the CSV file, the one in the CSV file will be stronger.
* If no conversion profile was specified, partner's default will be used
*
* @action add
* @param int $conversionProfileId Convertion profile id to use for converting the current bulk (-1 to use partner's default)
* @param file $csvFileData CSV File
* @return KalturaBulkUpload
*/
function addAction($conversionProfileId, $csvFileData)
{
// first we copy the file to "content/batchfiles/[partner_id]/"
$origFilename = $csvFileData["name"];
$fileInfo = pathinfo($origFilename);
$extension = strtolower($fileInfo["extension"]);
if ($extension != "csv") {
throw new KalturaAPIException(KalturaErrors::INVALID_FILE_EXTENSION);
}
$job = new BatchJob();
$job->setPartnerId($this->getPartnerId());
$job->save();
$syncKey = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADCSV);
// kFileSyncUtils::file_put_contents($syncKey, file_get_contents($csvFileData["tmp_name"]));
try {
kFileSyncUtils::moveFromFile($csvFileData["tmp_name"], $syncKey, true);
} catch (Exception $e) {
throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR);
}
$csvPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
$data = new KalturaBulkUploadJobData();
$data->csvFilePath = $csvPath;
$data->userId = $this->getKuser()->getPuserId();
$data->uploadedBy = $this->getKuser()->getScreenName();
if ($conversionProfileId === -1) {
$conversionProfileId = $this->getPartner()->getDefaultConversionProfileId();
}
$kmcVersion = $this->getPartner()->getKmcVersion();
$check = null;
if ($kmcVersion < 2) {
$check = ConversionProfilePeer::retrieveByPK($conversionProfileId);
} else {
$check = conversionProfile2Peer::retrieveByPK($conversionProfileId);
}
if (!$check) {
throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId);
}
$data->conversionProfileId = $conversionProfileId;
$dbJob = kJobsManager::addJob($job, $data->toObject(), KalturaBatchJobType::BULKUPLOAD);
$bulkUpload = new KalturaBulkUpload();
$bulkUpload->fromObject($dbJob);
return $bulkUpload;
}
示例6: objectChanged
public function objectChanged(BaseObject $object, array $modifiedColumns)
{
// replacing the ismc file name in the ism file
$ismPrevVersionFileSyncKey = $object->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
$ismContents = kFileSyncUtils::file_get_contents($ismPrevVersionFileSyncKey);
$ismcPrevVersionFileSyncKey = $object->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
$ismcContents = kFileSyncUtils::file_get_contents($ismcPrevVersionFileSyncKey);
$ismcPrevVersionFilePath = kFileSyncUtils::getLocalFilePathForKey($ismcPrevVersionFileSyncKey);
$object->incrementVersion();
$object->save();
$ismcFileSyncKey = $object->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
kFileSyncUtils::moveFromFile($ismcPrevVersionFilePath, $ismcFileSyncKey);
$ismcNewName = basename(kFileSyncUtils::getLocalFilePathForKey($ismcFileSyncKey));
KalturaLog::debug("Editing ISM set content to [{$ismcNewName}]");
$ismXml = new SimpleXMLElement($ismContents);
$ismXml->head->meta['content'] = $ismcNewName;
$tmpPath = kFileSyncUtils::getLocalFilePathForKey($ismPrevVersionFileSyncKey) . '.tmp';
file_put_contents($tmpPath, $ismXml->asXML());
kFileSyncUtils::moveFromFile($tmpPath, $object->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET));
return true;
}
示例7: executeImpl
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
{
$fileField = "csv_file";
$profileId = $this->getP("profile_id");
if (count($_FILES) == 0) {
$this->addError(APIErrors::NO_FILES_RECEIVED);
return;
}
if (!@$_FILES[$fileField]) {
$this->addError(APIErrors::INVALID_FILE_FIELD, $fileField);
return;
}
// first we copy the file to "content/batchfiles/[partner_id]/"
$origFilename = $_FILES[$fileField]['name'];
$fileInfo = pathinfo($origFilename);
$extension = strtolower($fileInfo['extension']);
if ($extension != "csv") {
$this->addError(APIErrors::INVALID_FILE_EXTENSION);
return;
}
$job = new BatchJob();
$job->setPartnerId($partner_id);
$job->save();
$syncKey = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADCSV);
// kFileSyncUtils::file_put_contents($syncKey, file_get_contents($csvFileData["tmp_name"]));
try {
kFileSyncUtils::moveFromFile($_FILES[$fileField]['tmp_name'], $syncKey, true);
} catch (Exception $e) {
throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR);
}
$csvPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
$data = new kBulkUploadJobData();
$data->setCsvFilePath($csvPath);
$data->setUserId($puser_kuser->getPuserId());
$data->setUploadedBy($puser_kuser->getPuserName());
$data->setConversionProfileId($profileId);
kJobsManager::addJob($job, $data, BatchJobType::BULKUPLOAD);
$this->addMsg("status", "ok");
}
示例8: onBulkUploadJobStatusUpdated
private function onBulkUploadJobStatusUpdated(BatchJob $dbBatchJob)
{
$xmlDropFolderFile = DropFolderFilePeer::retrieveByPK($dbBatchJob->getObjectId());
if (!$xmlDropFolderFile) {
return;
}
KalturaLog::debug('object id ' . $dbBatchJob->getObjectId());
switch ($dbBatchJob->getStatus()) {
case BatchJob::BATCHJOB_STATUS_QUEUED:
$jobData = $dbBatchJob->getData();
if (!is_null($jobData->getFilePath())) {
$syncKey = $dbBatchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD);
try {
kFileSyncUtils::moveFromFile($jobData->getFilePath(), $syncKey, true);
} catch (Exception $e) {
KalturaLog::err($e);
throw new APIException(APIErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR);
}
$filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
$jobData->setFilePath($filePath);
//save new info on the batch job
$dbBatchJob->setData($jobData);
$dbBatchJob->save();
}
break;
case BatchJob::BATCHJOB_STATUS_FINISHED:
case BatchJob::BATCHJOB_STATUS_FINISHED_PARTIALLY:
KalturaLog::debug("Handling Bulk Upload finished");
$xmlDropFolderFile->setStatus(DropFolderFileStatus::HANDLED);
$xmlDropFolderFile->save();
break;
case BatchJob::BATCHJOB_STATUS_FAILED:
case BatchJob::BATCHJOB_STATUS_FATAL:
KalturaLog::debug("Handling Bulk Upload failed");
$relatedFiles = DropFolderFilePeer::retrieveByLeadIdAndStatuses($xmlDropFolderFile->getId(), array(DropFolderFileStatus::PROCESSING));
foreach ($relatedFiles as $relatedFile) {
$this->setFileError($relatedFile, DropFolderFileStatus::ERROR_HANDLING, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::ERROR_IN_BULK_UPLOAD), DropFolderXmlBulkUploadPlugin::ERROR_IN_BULK_UPLOAD_MESSAGE);
}
break;
}
}
示例9: addFromImageAction
/**
* @action addFromImage
* @param string $entryId
* @param file $fileData
* @return KalturaThumbAsset
*
* @throws KalturaErrors::ENTRY_ID_NOT_FOUND
*/
public function addFromImageAction($entryId, $fileData)
{
$dbEntry = entryPeer::retrieveByPK($entryId);
if (!$dbEntry) {
throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
}
$ext = pathinfo($fileData["name"], PATHINFO_EXTENSION);
$dbThumbAsset = new thumbAsset();
$dbThumbAsset->setPartnerId($dbEntry->getPartnerId());
$dbThumbAsset->setEntryId($dbEntry->getId());
$dbThumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_QUEUED);
$dbThumbAsset->setFileExt($ext);
$dbThumbAsset->incrementVersion();
$dbThumbAsset->save();
$syncKey = $dbThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
kFileSyncUtils::moveFromFile($fileData["tmp_name"], $syncKey);
$finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
list($width, $height, $type, $attr) = getimagesize($finalPath);
$dbThumbAsset->setWidth($width);
$dbThumbAsset->setHeight($height);
$dbThumbAsset->setSize(filesize($finalPath));
$dbThumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
$dbThumbAsset->save();
$thumbAssets = new KalturaThumbAsset();
$thumbAssets->fromObject($dbThumbAsset);
return $thumbAssets;
}
示例10: die
// ---------------------------------------------------------------------------
$xsltFilePath = '';
//TODO: change to valid xslt file path
$metadataProfileId = null;
//TODO: change to a valid metadata profile id
// ---------------------------------------------------------------------------
if (!$xsltFilePath) {
die('ERROR - Missing parameter [$xsltFilePath]' . PHP_EOL);
}
if (!$metadataProfileId) {
die('ERROR - Missing parameter [$metadataProfileId]' . PHP_EOL);
}
if (!file_exists($xsltFilePath)) {
die('ERROR - Cannot find file at [' . $xsltFilePath . ']' . PHP_EOL);
}
require_once dirname(__FILE__) . '/../bootstrap.php';
require_once dirname(__FILE__) . '/../../api_v3/bootstrap.php';
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*"));
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "metadata", "*"));
KAutoloader::setClassMapFilePath(kConf::get("cache_root_path") . '/scripts/' . basename(__FILE__) . '.cache');
KAutoloader::register();
KalturaPluginManager::addPlugin('MetadataPlugin');
$dbMetadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId);
if (!$dbMetadataProfile) {
die('ERROR - Cannot find metadata profile with id [' . $metadataProfileId . ']' . PHP_EOL);
}
$dbMetadataProfile->incrementXsltVersion();
$dbMetadataProfile->save();
$key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT);
kFileSyncUtils::moveFromFile($xsltFilePath, $key, true, true);
echo 'Done' . PHP_EOL;
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:31,代码来源:syncXsltOnMetadataProfile.php
示例11: decideThumbGenerate
/**
* decideThumbGenerate is the decision layer for a single thumbnail generation
*
* @param entry $entry
* @param thumbParams $destThumbParams
* @param BatchJob $parentJob
* @return thumbAsset
*/
public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false)
{
$srcAsset = null;
assetPeer::resetInstanceCriteriaFilter();
if ($sourceAssetId) {
$srcAsset = assetPeer::retrieveById($sourceAssetId);
} else {
if ($destThumbParams->getSourceParamsId()) {
KalturaLog::debug("Look for flavor params [" . $destThumbParams->getSourceParamsId() . "]");
$srcAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getSourceParamsId());
}
if (is_null($srcAsset)) {
KalturaLog::debug("Look for original flavor");
$srcAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId());
}
if (is_null($srcAsset) || $srcAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
KalturaLog::debug("Look for highest bitrate flavor");
$srcAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entry->getId());
}
}
if (is_null($srcAsset)) {
throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY);
}
$errDescription = null;
$mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
$destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription);
$thumbAsset = thumbAssetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId());
if ($thumbAsset) {
$description = $thumbAsset->getDescription() . "\n" . $errDescription;
$thumbAsset->setDescription($description);
} else {
$thumbAsset = new thumbAsset();
$thumbAsset->setPartnerId($entry->getPartnerId());
$thumbAsset->setEntryId($entry->getId());
$thumbAsset->setDescription($errDescription);
$thumbAsset->setFlavorParamsId($destThumbParams->getId());
}
$thumbAsset->incrementVersion();
$thumbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING);
$thumbAsset->setTags($destThumbParamsOutput->getTags());
$thumbAsset->setFileExt($destThumbParamsOutput->getFileExt());
if (!$destThumbParamsOutput) {
$thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
$thumbAsset->save();
return null;
}
$thumbAsset->save();
// save flavor params
$destThumbParamsOutput->setPartnerId($entry->getPartnerId());
$destThumbParamsOutput->setEntryId($entry->getId());
$destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId());
$destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion());
$destThumbParamsOutput->save();
$srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
$srcAssetType = $srcAsset->getType();
if (!$runSync) {
$job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAssetType, $destThumbParamsOutput);
return $thumbAsset;
}
$errDescription = null;
$capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription);
// failed
if (!$capturedPath) {
$thumbAsset->incrementVersion();
$thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
$thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}");
$thumbAsset->save();
return $thumbAsset;
}
$thumbAsset->incrementVersion();
$thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
if (file_exists($capturedPath)) {
list($width, $height, $type, $attr) = getimagesize($capturedPath);
$thumbAsset->setWidth($width);
$thumbAsset->setHeight($height);
$thumbAsset->setSize(filesize($capturedPath));
}
$logPath = $capturedPath . '.log';
if (file_exists($logPath)) {
$thumbAsset->incLogFileVersion();
$thumbAsset->save();
// creats the file sync
$logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
kFileSyncUtils::moveFromFile($logPath, $logSyncKey);
KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey));
} else {
$thumbAsset->save();
}
$syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
kFileSyncUtils::moveFromFile($capturedPath, $syncKey);
KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey));
if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
//.........这里部分代码省略.........
示例12: attachFile
/**
* @param string $entryFullPath
* @param entry $dbEntry
* @param asset $dbAsset
* @return asset
* @throws KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY
* @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
*/
protected function attachFile($entryFullPath, entry $dbEntry, asset $dbAsset = null, $copyOnly = false)
{
// TODO - move image handling to media service
if ($dbEntry->getMediaType() == KalturaMediaType::IMAGE) {
$exifImageType = @exif_imagetype($entryFullPath);
$validTypes = array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM, IMAGETYPE_IFF, IMAGETYPE_PNG);
if (in_array($exifImageType, $validTypes)) {
$exifData = @exif_read_data($entryFullPath);
if ($exifData && isset($exifData["DateTimeOriginal"]) && $exifData["DateTimeOriginal"]) {
$mediaDate = $exifData["DateTimeOriginal"];
$ts = strtotime($mediaDate);
// handle invalid dates either due to bad format or out of range
if ($ts === -1 || $ts === false || $ts < strtotime('2000-01-01') || $ts > strtotime('2015-01-01')) {
$mediaDate = null;
}
$dbEntry->setMediaDate($mediaDate);
}
}
list($width, $height, $type, $attr) = getimagesize($entryFullPath);
$dbEntry->setDimensions($width, $height);
$dbEntry->setData(".jpg");
// this will increase the data version
$dbEntry->save();
$syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
try {
kFileSyncUtils::moveFromFile($entryFullPath, $syncKey, true, $copyOnly);
} catch (Exception $e) {
if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) {
$dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
$dbEntry->save();
}
throw $e;
}
$dbEntry->setStatus(entryStatus::READY);
$dbEntry->save();
return null;
}
$isNewAsset = false;
if (!$dbAsset) {
$isNewAsset = true;
$dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId());
}
if (!$dbAsset && $dbEntry->getStatus() == entryStatus::NO_CONTENT) {
$dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
$dbEntry->save();
}
$ext = pathinfo($entryFullPath, PATHINFO_EXTENSION);
$dbAsset->setFileExt($ext);
$dbAsset->save();
if ($dbAsset && $dbAsset instanceof thumbAsset) {
list($width, $height, $type, $attr) = getimagesize($entryFullPath);
$dbAsset->setWidth($width);
$dbAsset->setHeight($height);
$dbAsset->save();
}
$syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
try {
kFileSyncUtils::moveFromFile($entryFullPath, $syncKey, true, $copyOnly);
} catch (Exception $e) {
if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) {
$dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
$dbEntry->save();
}
$dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
$dbAsset->save();
throw $e;
}
if ($dbAsset && !$dbAsset instanceof flavorAsset) {
$dbAsset->setStatusLocalReady();
if ($dbAsset->getFlavorParamsId()) {
$dbFlavorParams = assetParamsPeer::retrieveByPK($dbAsset->getFlavorParamsId());
if ($dbFlavorParams) {
$dbAsset->setTags($dbFlavorParams->getTags());
}
}
$dbAsset->save();
}
if ($isNewAsset) {
kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset));
}
kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset));
return $dbAsset;
}
示例13: decideThumbGenerate
/**
* decideThumbGenerate is the decision layer for a single thumbnail generation
*
* @param entry $entry
* @param thumbParams $destThumbParams
* @param BatchJob $parentJob
* @return thumbAsset
*/
public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false, $srcAsset = null)
{
if (is_null($srcAsset)) {
$srcAsset = self::getSourceAssetForGenerateThumbnail($sourceAssetId, $destThumbParams->getSourceParamsId(), $entry->getId());
if (is_null($srcAsset)) {
throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY);
}
}
$errDescription = null;
$mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
$destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription);
if ($srcAsset->getType() == assetType::FLAVOR && is_null($destThumbParamsOutput->getVideoOffset())) {
$destThumbParamsOutput->setVideoOffset($entry->getThumbOffset());
}
$destThumbParamsOutput->setVideoOffset(min($destThumbParamsOutput->getVideoOffset(), $entry->getDuration()));
if (!$destThumbParamsOutput->getDensity()) {
$partner = $entry->getPartner();
if (!is_null($partner)) {
$destThumbParamsOutput->setDensity($partner->getDefThumbDensity());
}
}
$thumbAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId());
if ($thumbAsset) {
$description = $thumbAsset->getDescription() . "\n" . $errDescription;
$thumbAsset->setDescription($description);
} else {
$thumbAsset = new thumbAsset();
$thumbAsset->setPartnerId($entry->getPartnerId());
$thumbAsset->setEntryId($entry->getId());
$thumbAsset->setDescription($errDescription);
$thumbAsset->setFlavorParamsId($destThumbParams->getId());
}
$thumbAsset->incrementVersion();
$thumbAsset->setTags($destThumbParamsOutput->getTags());
$thumbAsset->setFileExt($destThumbParamsOutput->getFileExt());
if ($thumbAsset->getStatus() != asset::ASSET_STATUS_READY) {
$thumbAsset->setStatus(asset::ASSET_STATUS_CONVERTING);
}
//Sets the default thumb if this the only default thumb
kBusinessPreConvertDL::setIsDefaultThumb($thumbAsset);
if (!$destThumbParamsOutput) {
$thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
$thumbAsset->save();
return null;
}
$thumbAsset->save();
// save flavor params
$destThumbParamsOutput->setPartnerId($entry->getPartnerId());
$destThumbParamsOutput->setEntryId($entry->getId());
$destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId());
$destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion());
$destThumbParamsOutput->save();
$srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
$srcAssetType = $srcAsset->getType();
if (!$runSync) {
$job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAsset->getId(), $srcAssetType, $destThumbParamsOutput);
return $thumbAsset;
}
$errDescription = null;
// Since this method is called when trying to crop an existing thumbnail, need to add this check - thumbAssets have no mediaInfo.
$capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription, $mediaInfo ? $mediaInfo->getVideoRotation() : null);
// failed
if (!$capturedPath) {
$thumbAsset->incrementVersion();
$thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
$thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}");
$thumbAsset->save();
return $thumbAsset;
}
$thumbAsset->incrementVersion();
$thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
if (file_exists($capturedPath)) {
list($width, $height, $type, $attr) = getimagesize($capturedPath);
$thumbAsset->setWidth($width);
$thumbAsset->setHeight($height);
$thumbAsset->setSize(filesize($capturedPath));
}
$logPath = $capturedPath . '.log';
if (file_exists($logPath)) {
$thumbAsset->incLogFileVersion();
$thumbAsset->save();
// creats the file sync
$logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
kFileSyncUtils::moveFromFile($logPath, $logSyncKey);
KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey));
} else {
$thumbAsset->save();
}
$syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
kFileSyncUtils::moveFromFile($capturedPath, $syncKey);
KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey));
if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
//.........这里部分代码省略.........
示例14: addBulkUploadJob
/**
* Function adds bulk upload job to the queue
* @param Partner $partner
* @param kBulkUploadJobData $jobData
* @param string $bulkUploadType
* @throws APIException
* @return BatchJob
*/
public static function addBulkUploadJob(Partner $partner, kBulkUploadJobData $jobData, $bulkUploadType = null, $objectId = null, $objectType = null)
{
KalturaLog::debug("adding BulkUpload job");
$job = new BatchJob();
$job->setPartnerId($partner->getId());
$job->setJobType(BatchJobType::BULKUPLOAD);
$job->setJobSubType($bulkUploadType);
if (!is_null($objectId) && !is_null($objectType)) {
$job->setObjectId($objectId);
$job->setObjectType($objectType);
}
if (is_null($jobData)) {
throw new APIException(APIErrors::BULK_UPLOAD_BULK_UPLOAD_TYPE_NOT_VALID, $bulkUploadType);
}
$job->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
$job = kJobsManager::addJob($job, $jobData, BatchJobType::BULKUPLOAD, $bulkUploadType);
if (!is_null($jobData->getFilePath())) {
$syncKey = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD);
// kFileSyncUtils::file_put_contents($syncKey, file_get_contents($csvFileData["tmp_name"]));
try {
kFileSyncUtils::moveFromFile($jobData->getFilePath(), $syncKey, true);
} catch (Exception $e) {
KalturaLog::err($e);
throw new APIException(APIErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR);
}
$filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
$jobData->setFilePath($filePath);
}
if (!$jobData->getBulkUploadObjectType()) {
$jobData->setBulkUploadObjectType(BulkUploadObjectType::ENTRY);
}
if ($jobData->getBulkUploadObjectType() == BulkUploadObjectType::ENTRY && !$jobData->getObjectData()->getConversionProfileId()) {
$jobData->setConversionProfileId($partner->getDefaultConversionProfileId());
$kmcVersion = $partner->getKmcVersion();
$check = null;
if ($kmcVersion < 2) {
$check = ConversionProfilePeer::retrieveByPK($jobData->getConversionProfileId());
} else {
$check = conversionProfile2Peer::retrieveByPK($jobData->getConversionProfileId());
}
if (!$check) {
throw new APIException(APIErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $jobData->getConversionProfileId());
}
}
$job->setData($jobData);
return kJobsManager::updateBatchJob($job, BatchJob::BATCHJOB_STATUS_PENDING);
}
示例15: attachFile
/**
* @param flavorAsset $flavorAsset
* @param string $fullPath
* @param bool $copyOnly
*/
protected function attachFile(flavorAsset $flavorAsset, $fullPath, $copyOnly = false)
{
$ext = pathinfo($fullPath, PATHINFO_EXTENSION);
$flavorAsset->setFileExt($ext);
$flavorAsset->setSize(kFile::fileSize($fullPath));
$flavorAsset->incrementVersion();
$flavorAsset->save();
$syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
try {
kFileSyncUtils::moveFromFile($fullPath, $syncKey, true, $copyOnly);
} catch (Exception $e) {
if ($flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_QUEUED || $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE) {
$flavorAsset->setDescription($e->getMessage());
$flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
$flavorAsset->save();
}
throw $e;
}
if (!$flavorAsset->isLocalReadyStatus()) {
$flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED);
}
$flavorAsset->save();
}