Skip to content

Commit

Permalink
Merge pull request kaltura#6543 from kaltura/master-merge-Mercury-13.9.0
Browse files Browse the repository at this point in the history
Master merge mercury 13.9.0
  • Loading branch information
MosheMaorKaltura authored Dec 18, 2017
2 parents 63487cd + 4cd050f commit 236e260
Show file tree
Hide file tree
Showing 139 changed files with 5,524 additions and 3,691 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Mercury-13.8.0
Mercury-13.9.0
5 changes: 4 additions & 1 deletion alpha/apps/kaltura/lib/batch/myBatchPartnerUsage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function __construct($partnerId = null, $partnerPackage = PartnerPackages
if($partnerPackage == PartnerPackages::PARTNER_PACKAGE_FREE)
{
myPartnerUtils::doPartnerUsage($partner, true);
if(myPartnerUtils::isPartnerCreatedAsMonitoredFreeTrial($partner))
myPartnerUtils::handleDayInFreeTrial($partner);
}
else if($partnerPackage == PartnerPackages::PARTNER_PACKAGE_DEVELOPER)
{
Expand All @@ -50,7 +52,8 @@ public function __construct($partnerId = null, $partnerPackage = PartnerPackages
}
}
$partner = end($partners);
$highest_partner_id = $partner->getId();
if($partner)
$highest_partner_id = $partner->getId();
unset($partners);
PartnerPeer::clearInstancePool();
}
Expand Down
16 changes: 8 additions & 8 deletions alpha/apps/kaltura/lib/batch2/bcdl/kBusinessPreConvertDL.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,15 @@ private static function generateThumbnail(asset $srcAsset, thumbParamsOutput $de
if($srcAsset->getType() == assetType::FLAVOR)
{
/* @var $srcAsset flavorAsset */
$dar = null;
$params = array();
$mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
if($mediaInfo)
$dar = $mediaInfo->getVideoDar();

if($mediaInfo){
$params['dar'] = $mediaInfo->getVideoDar();
$params['scanType'] = $mediaInfo->getScanType();
}
// generates the thumbnail
$thumbMaker = new KFFMpegThumbnailMaker($srcPath, $destPath, kConf::get('bin_path_ffmpeg'));
$created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), null, null, $dar);
$created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), $params);
if(!$created || !file_exists($destPath))
{
$errDescription = "Thumbnail not captured";
Expand Down Expand Up @@ -1110,10 +1111,9 @@ public static function bypassConversion(flavorAsset $originalFlavorAsset, entry
$offset = $entry->getThumbOffset(); // entry getThumbOffset now takes the partner DefThumbOffset into consideration

$srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
$srcFileSyncLocalPath = kFileSyncUtils::getLocalFilePathForKey($srcSyncKey);


$postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_BYPASS;
return kJobsManager::addPostConvertJob($convertProfileJob, $postConvertAssetType, $srcFileSyncLocalPath, $originalFlavorAsset->getId(), null, true, $offset);
return kJobsManager::addPostConvertJob($convertProfileJob, $postConvertAssetType, $srcSyncKey, $originalFlavorAsset->getId(), null, true, $offset);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions alpha/apps/kaltura/lib/batch2/kFlowHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private static function createReplacigEntry($recordedEntry, $liveSegmentCount)
return $replacingEntry;
}

public static function getReplacingEntry($recordedEntry, $asset, $liveSegmentCount)
public static function getReplacingEntry($recordedEntry, $asset = null, $liveSegmentCount, $flavorParamsId = null)
{
//Reload entry before tryign to get the replacing entry id from it to avoid creating 2 different replacing entries for different flavors
$recordedEntry->reload();
Expand All @@ -415,7 +415,8 @@ public static function getReplacingEntry($recordedEntry, $asset, $liveSegmentCou
}
else
{
$replacingAsset = assetPeer::retrieveByEntryIdAndParams($replacingEntryId, $asset->getFlavorParamsId());
$flavorParamsId = $asset ? $asset->getFlavorParamsId() : $flavorParamsId;
$replacingAsset = assetPeer::retrieveByEntryIdAndParams($replacingEntryId, $flavorParamsId);
if($replacingAsset)
{
KalturaLog::debug("Entry in replacement, deleting - [".$replacingEntryId."]");
Expand Down Expand Up @@ -772,7 +773,7 @@ public static function handleConvertFinished(BatchJob $dbBatchJob, kConvertJobDa
$nextJob = self::createNextJob($flavorParamsOutput, $dbBatchJob, $data, $syncKey); //todo validate sync key
if(!$nextJob)
{
self::handleOperatorsProcessingFinished($flavorAsset, $flavorParamsOutput, $entry, $dbBatchJob, $data, $rootBatchJob);
self::handleOperatorsProcessingFinished($flavorAsset, $flavorParamsOutput, $entry, $dbBatchJob, $data, $rootBatchJob, $syncKey);
}
// this logic decide when a thumbnail should be created
if($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD)
Expand Down Expand Up @@ -840,7 +841,7 @@ private static function createNextJob(flavorParamsOutput $flavorParamsOutput, Ba

return $nextJob;
}
private static function handleOperatorsProcessingFinished(flavorAsset $flavorAsset, flavorParamsOutput $flavorParamsOutput, entry $entry, BatchJob $dbBatchJob, kConvertJobData $data, $rootBatchJob = null)
private static function handleOperatorsProcessingFinished(flavorAsset $flavorAsset, flavorParamsOutput $flavorParamsOutput, entry $entry, BatchJob $dbBatchJob, kConvertJobData $data, $rootBatchJob = null, $syncKey = null)
{
$offset = $entry->getThumbOffset(); // entry getThumbOffset now takes the partner DefThumbOffset into consideration

Expand Down Expand Up @@ -886,7 +887,7 @@ private static function handleOperatorsProcessingFinished(flavorAsset $flavorAss
if($flavorAsset->getIsOriginal())
$postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_SOURCE;

kJobsManager::addPostConvertJob($dbBatchJob, $postConvertAssetType, $data->getDestFileSyncLocalPath(), $data->getFlavorAssetId(), $flavorParamsOutput->getId(), $createThumb, $offset);
kJobsManager::addPostConvertJob($dbBatchJob, $postConvertAssetType, $syncKey, $data->getFlavorAssetId(), $flavorParamsOutput->getId(), $createThumb, $offset);
}
else // no need to run post convert
{
Expand Down Expand Up @@ -1363,7 +1364,7 @@ public static function handleConvertCollectionFinished(BatchJob $dbBatchJob, kCo

// creating post convert job (without thumb)
$postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR;
kJobsManager::addPostConvertJob($dbBatchJob, $postConvertAssetType, $flavor->getDestFileSyncLocalPath(), $flavor->getFlavorAssetId(), $flavor->getFlavorParamsOutputId(), file_exists($thumbPath), $offset);
kJobsManager::addPostConvertJob($dbBatchJob, $postConvertAssetType, $syncKey, $flavor->getFlavorAssetId(), $flavor->getFlavorParamsOutputId(), file_exists($thumbPath), $offset);

$finalFlavors[] = $flavor;
$addedFlavorParamsOutputsIds[] = $flavor->getFlavorParamsOutputId();
Expand Down Expand Up @@ -1733,11 +1734,10 @@ public static function handlePostConvertFinished(BatchJob $dbBatchJob, kPostConv
$syncKey = $currentFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
if(kFileSyncUtils::fileSync_exists($syncKey))
{
$path = kFileSyncUtils::getLocalFilePathForKey($syncKey);

$fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey, false);
$entry = $dbBatchJob->getEntry();
if($entry)
kJobsManager::addConvertProfileJob(null, $entry, $currentFlavorAsset->getId(), $path);
kJobsManager::addConvertProfileJob(null, $entry, $currentFlavorAsset->getId(), $fileSync);
}
$currentFlavorAsset = null;
}
Expand Down
22 changes: 5 additions & 17 deletions alpha/apps/kaltura/lib/batch2/kFlowManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,8 @@ public function objectAdded(BaseObject $object, BatchJob $raisedJob = null)

if (kFileSyncUtils::fileSync_exists($syncKey))
{
// Get the asset fileSync.
// For URL typed sync - assume remote and use the relative file path.
// For the other types - use the ordinary kFileSyncUtils::getLocalFilePathForKey.
$fsArr = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
$fs = $fsArr[0];
if ($fs && $fs->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL)
{
$path = $fs->getFilePath();
} else
{
$path = kFileSyncUtils::getLocalFilePathForKey($syncKey);
}
kJobsManager::addConvertProfileJob($raisedJob, $entry, $object->getId(), $path);
$fileSync = reset(kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false));
kJobsManager::addConvertProfileJob($raisedJob, $entry, $object->getId(), $fileSync);
}
}

Expand Down Expand Up @@ -662,10 +651,9 @@ public function objectChanged(BaseObject $object, array $modifiedColumns)
$fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey, false);
if(!$fileSync)
return true;

$srcFileSyncLocalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
if($srcFileSyncLocalPath)
kJobsManager::addPostConvertJob(null, $postConvertAssetType, $srcFileSyncLocalPath, $object->getId(), null, $entry->getCreateThumb(), $offset);

if(kFileSyncUtils::getLocalFilePathForKey($syncKey))
kJobsManager::addPostConvertJob(null, $postConvertAssetType, $syncKey, $object->getId(), null, $entry->getCreateThumb(), $offset);
}
elseif ($object->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY)
{
Expand Down
80 changes: 59 additions & 21 deletions alpha/apps/kaltura/lib/batch2/kJobsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ public static function addFlavorConvertJob(array $srcSyncKeys, flavorParamsOutpu
}
$partner = PartnerPeer::retrieveByPK($flavorAsset->getPartnerId());
$srcFileSyncs = array();
$firstValidFileSync = null;

foreach ($srcSyncKeys as $srcSyncKey)
{
Expand Down Expand Up @@ -499,19 +500,16 @@ public static function addFlavorConvertJob(array $srcSyncKeys, flavorParamsOutpu
$srcFileSyncDescriptor->setAssetParamsId($srcFlavorAsset->getFlavorParamsId());
$srcFileSyncDescriptor->setFileSyncObjectSubType($srcSyncKey->getObjectSubType());
$srcFileSyncs[] = $srcFileSyncDescriptor;
$firstValidFileSync = $firstValidFileSync ? $firstValidFileSync : $fileSync;
}
}

if (!self::shouldExeConvertJob($firstValidFileSync))
return null;

// creates convert data
$convertData = new kConvertJobData();
$convertData->setSrcFileSyncs($srcFileSyncs);
$sourcePath = $convertData->getSrcFileSyncLocalPath();
if(kFile::isFileTypeText($sourcePath))
{
KalturaLog::err("Source file is of type text for flavor id [$flavorAssetId]");
return null;
}

$convertData->setMediaInfoId($mediaInfoId);
$convertData->setFlavorParamsOutputId($flavor->getId());
$convertData->setFlavorAssetId($flavorAssetId);
Expand Down Expand Up @@ -804,19 +802,19 @@ public static function addCapturaThumbJob(BatchJob $parentJob = null, $partnerId
/**
* @param BatchJob $parentJob
* @param int $postConvertAssetType
* @param string $srcFileSyncLocalPath
* @param FileSyncKey $fileSyncKey
* @param int $flavorAssetId
* @param int $flavorParamsOutputId
* @param bool $createThumb
* @param int $thumbOffset
* @param string $customData
* @return BatchJob
*/
public static function addPostConvertJob(BatchJob $parentJob = null, $postConvertAssetType, $srcFileSyncLocalPath, $flavorAssetId, $flavorParamsOutputId, $createThumb = false, $thumbOffset = 3)
public static function addPostConvertJob(BatchJob $parentJob = null, $postConvertAssetType, $fileSyncKey, $flavorAssetId, $flavorParamsOutputId, $createThumb = false, $thumbOffset = 3)
{
$postConvertData = new kPostConvertJobData();
$postConvertData->setPostConvertAssetType($postConvertAssetType);
$postConvertData->setSrcFileSyncLocalPath($srcFileSyncLocalPath);
$postConvertData->setSrcFileSyncLocalPath(kFileSyncUtils::getResolveLocalFileSyncForKey($fileSyncKey));
$postConvertData->setFlavorParamsOutputId($flavorParamsOutputId);
$postConvertData->setFlavorAssetId($flavorAssetId);
$postConvertData->setThumbOffset($thumbOffset);
Expand Down Expand Up @@ -1212,19 +1210,19 @@ public static function addBulkDownloadJob($partnerId, $puserId, $entryIds, $flav
}

/**
* @param BatchJob $batchJob
* @param BatchJob $parentJob
* @param entry $entry
* @param string $flavorAssetId
* @param string $inputFileSyncLocalPath
* @param FileSync $fileSync
* @return BatchJob
*/
public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath)
public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $fileSync)
{
if(kFile::isFileTypeText($inputFileSyncLocalPath))
if (!self::shouldExeConvertJob($fileSync))
{
KalturaLog::notice('Source of type text will not be converted');
$entry->setStatus(entryStatus::ERROR_CONVERTING);
$entry->save();
myEntryUtils::addTrackEntryInfo($entry,"Source file for conversion is not supported");
return null;
}
if($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE)
Expand All @@ -1235,7 +1233,10 @@ public static function addConvertProfileJob(BatchJob $parentJob = null, entry $e
KalturaLog::notice('Entry should not be converted');
return null;
}


$inputFileSyncLocalPath = $fileSync->getFullPath();
if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL)
$inputFileSyncLocalPath = $fileSync->getFilePath();
$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)
Expand Down Expand Up @@ -1389,16 +1390,16 @@ public static function addConvertProfileJob(BatchJob $parentJob = null, entry $e
* @param string $entryId
* @param int $partnerId
* @param StorageProfile $externalStorage
* @param SyncFile $fileSync
* @param string $srcFileSyncLocalPath
* @param FileSync $fileSync
* @param FileSync $srcFileSync
* @param bool $force
*
* @return BatchJob
*/
public static function addStorageExportJob(BatchJob $parentJob = null, $entryId, $partnerId, StorageProfile $externalStorage, FileSync $fileSync, $srcFileSyncLocalPath, $force = false, $dc = null)
public static function addStorageExportJob(BatchJob $parentJob = null, $entryId, $partnerId, StorageProfile $externalStorage, FileSync $fileSync, FileSync $srcFileSync, $force = false, $dc = null)
{
$netStorageExportData = kStorageExportJobData::getInstance($externalStorage->getProtocol());
$netStorageExportData->setStorageExportJobData($externalStorage, $fileSync, $srcFileSyncLocalPath);
$netStorageExportData->setStorageExportJobData($externalStorage, $fileSync, $srcFileSync);

$batchJob = null;
if($parentJob)
Expand Down Expand Up @@ -1782,7 +1783,7 @@ public static function addExportLiveReportJob($reportType, KalturaLiveReportExpo
return self::addJob( $job, $jobData, BatchJobType::LIVE_REPORT_EXPORT, $reportType);
}

protected static function getFileContainer(FileSyncKey $syncKey)
public static function getFileContainer(FileSyncKey $syncKey)
{

$fileSync = kFileSyncUtils::getResolveLocalFileSyncForKey($syncKey);
Expand All @@ -1800,4 +1801,41 @@ protected static function getFileContainerByFileSync(FileSync $fileSync)
}
return $fileContainer;
}

/**
* @param FileSync $fileSync
* @return bool
*/
private static function shouldExeConvertJob($fileSync)
{
if (!$fileSync)
{
KalturaLog::notice('No file-sync supplied for conversion');
return false;
}
if (self::shouldBlockFileConversion($fileSync))
{
KalturaLog::notice('Source of type text will not be converted - FileSyncId [' . $fileSync->getId() . ']');
return false;
}
return true;
}

/**
* @param FileSync $fileSync
* @return bool
*/
private static function shouldBlockFileConversion($fileSync)
{
if($fileSync->isEncrypted())
$filePath = $fileSync->createTempClear();
else
$filePath = $fileSync->getFullPath();
$actualFileDescription = trim(kFile::getFileDescription($filePath));
$blackList = kconf::get('file_descriptions_black_list');
$shouldBlock = in_array($actualFileDescription,$blackList['fileDescriptions']);
if($fileSync->isEncrypted())
$fileSync->deleteTempClear();
return $shouldBlock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class kAmazonS3StorageExportJobData extends kStorageExportJobData
*/
private $endPoint;

public function setStorageExportJobData(StorageProfile $externalStorage, FileSync $fileSync, $srcFileSyncLocalPath, $force = false)
public function setStorageExportJobData(StorageProfile $externalStorage, FileSync $fileSync, $srcFileSync, $force = false)
{
parent::setStorageExportJobData($externalStorage, $fileSync, $srcFileSyncLocalPath);
parent::setStorageExportJobData($externalStorage, $fileSync, $srcFileSync);
$this->setFilesPermissionInS3($externalStorage->getFilesPermissionInS3());
$this->setS3Region($externalStorage->getS3Region());
$this->setSseType($externalStorage->getSseType());
Expand Down
8 changes: 4 additions & 4 deletions alpha/apps/kaltura/lib/batch2/model/kConvartableJobData.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,21 @@ public function setFlavorParamsOutput($flavorParamsOutput)
}

/**
* @param $srcFileSyncLocalPath the $srcFileSyncLocalPath to set
* @param FileSync $fileSync
*/
public function setSrcFileSyncLocalPath($srcFileSyncLocalPath)
public function setSrcFileSyncLocalPath($fileSync)
{
$srcDescriptor = (is_array($this->srcFileSyncs) && count($this->srcFileSyncs) ? reset($this->srcFileSyncs) : null);

if(!$srcDescriptor)
{
$srcDescriptor = new kSourceFileSyncDescriptor();
$srcDescriptor->setFileSyncLocalPath($srcFileSyncLocalPath);
$srcDescriptor->setPathAndKeyByFileSync($fileSync);
$this->srcFileSyncs = array($srcDescriptor);
}
else
{
$srcDescriptor->setFileSyncLocalPath($srcFileSyncLocalPath);
$srcDescriptor->setPathAndKeyByFileSync($fileSync);
}
}

Expand Down
5 changes: 3 additions & 2 deletions alpha/apps/kaltura/lib/batch2/model/kStorageExportJobData.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function getInstance($protocol)
return $data;
}

public function setStorageExportJobData(StorageProfile $externalStorage, FileSync $fileSync, $srcFileSyncLocalPath, $force = false)
public function setStorageExportJobData(StorageProfile $externalStorage, FileSync $fileSync, FileSync $srcFileSync, $force = false)
{
$this->setServerUrl($externalStorage->getStorageUrl());
$this->setServerUsername($externalStorage->getStorageUsername());
Expand All @@ -42,7 +42,8 @@ public function setStorageExportJobData(StorageProfile $externalStorage, FileSyn
$this->setServerPublicKey($externalStorage->getPublicKey());
$this->setServerPassPhrase($externalStorage->getPassPhrase());
$this->setFtpPassiveMode($externalStorage->getStorageFtpPassiveMode());
$this->setSrcFileSyncLocalPath($srcFileSyncLocalPath);
$this->setSrcFileSyncLocalPath($srcFileSync->getFullPath());
$this->setSrcFileEncryptionKey($srcFileSync->getEncryptionKey());
$this->setSrcFileSyncId($fileSync->getId());
$this->setForce($force);
$this->setDestFileSyncStoredPath($externalStorage->getStorageBaseDir() . '/' . $fileSync->getFilePath());
Expand Down
Loading

0 comments on commit 236e260

Please sign in to comment.