Skip to content

Commit

Permalink
Merged propus-16.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yossipapi committed Jul 23, 2020
2 parents 320e28c + 85ac091 commit 0edd742
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 69 deletions.
25 changes: 12 additions & 13 deletions alpha/apps/kaltura/lib/storage/kStorageExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,28 +557,27 @@ public static function getPeriodicStorageIdsByPartner($partnerId)

do
{
$partnerIds = kConf::get('export_to_cloud_partner_ids', 'cloud_storage', array());
if (in_array($partnerId, $partnerIds) || in_array(self::ALL_PARTNERS_WILD_CHAR, $partnerIds))
if($partner && !$partner->getStorageDeleteFromKaltura())
{
break;
}
$partnerIds = kConf::get('export_to_cloud_partner_ids', 'cloud_storage', array());
if (in_array($partnerId, $partnerIds) || in_array(self::ALL_PARTNERS_WILD_CHAR, $partnerIds))
{
break;
}

$partnerPackages = kConf::get('export_to_cloud_partner_package', 'cloud_storage', array());
if ( $partner && in_array($partner->getPartnerPackage(), $partnerPackages) )
{
break;
$partnerPackages = kConf::get('export_to_cloud_partner_package', 'cloud_storage', array());
if (in_array($partner->getPartnerPackage(), $partnerPackages))
{
break;
}
}

$isPartnerValid = false;
}while(0);

if($isPartnerValid)
{
$externalStorageProfiles = StorageProfilePeer::retrieveExternalByPartnerId($partnerId);
if($partner && (!$partner->getStorageDeleteFromKaltura() || !count($externalStorageProfiles)))
{
return kConf::get('periodic_storage_ids','cloud_storage', array());
}
return kConf::get('periodic_storage_ids','cloud_storage', array());
}

return array();
Expand Down
161 changes: 161 additions & 0 deletions alpha/scripts/utils/ExportByEntryListToDifferentStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php

if (count($argv) != 5)
{
print("USAGE: <sourceDc> <storageId> <fileName> <realrun-dryrun> ");
exit(0);
}

define("BASE_DIR", dirname(__FILE__));
require_once(BASE_DIR.'/../../../alpha/scripts/bootstrap.php');

$sourceDc = $argv[1];
$storageIdDest = $argv[2];
$filePath = $argv[3];
$dryRun = $argv[4] != 'realrun';

if (!file_exists($filePath))
{
KalturaLog::warning("File $filePath Does not exists. Exiting...");
exit(0);
}

if ($dryRun)
{
KalturaLog::debug('*************** In Dry run mode ***************');
}
else
{
KalturaLog::debug('*************** In Real run mode ***************');
}
KalturaStatement::setDryRun($dryRun);

main($sourceDc, $storageIdDest, $filePath);

/**
* @param $sourceDc
* @param $storageIdDest
* @param $filePath
* @throws PropelException
*/
function main($sourceDc, $storageIdDest, $filePath)
{
KalturaLog::debug("Running for file [$filePath] and storageIdDest [$storageIdDest] and source dc $sourceDc");
$count = 0;
$entryIds = file($filePath);
if (empty($entryIds))
{
KalturaLog::warning("File is empty - Exiting.");
exit(0);
}

$externalStorage = StorageProfilePeer::retrieveByPK($storageIdDest);
if (!$externalStorage)
{
KalturaLog::warning("Storage [$storageIdDest] does not exists");
exit(0);
}

foreach ($entryIds as $entryId)
{
$c = new Criteria();
$c->add(entryPeer::ID, trim($entryId));
$c->add(entryPeer::STATUS, entryStatus::READY);
$entry = entryPeer::doSelectOne($c);
if (!$entry)
{
KalturaLog::debug("Entry not found (Or not in status READY) $entryId - skipping");
continue;
}

KalturaLog::debug('Retrieving non-source assets for entry ' . $entry->getId());
$c = new Criteria();
$c->add(assetPeer::ENTRY_ID, $entry->getId());
$c->add(assetPeer::TYPE, array(assetType::FLAVOR), Criteria::IN);
$c->add(assetPeer::STATUS, flavorAsset::FLAVOR_ASSET_STATUS_READY, Criteria::IN);
$c->addAnd(assetPeer::IS_ORIGINAL, false);
$assets = assetPeer::doSelect($c);

KalturaLog::debug('Found ' . count($assets) . ' non-source assets for entry ' . $entry->getId());

foreach ($assets as /** @var flavorAsset $asset * */ $asset)
{
KalturaLog::debug('Handling asset with id ' . $asset->getId());
if ($externalStorage->shouldExportFlavorAsset($asset))
{
$criteria = new Criteria(FileSyncPeer::DATABASE_NAME);
$criteria->add(FileSyncPeer::OBJECT_ID, $asset->getId(), Criteria::EQUAL);
$criteria->add(FileSyncPeer::OBJECT_TYPE, FileSyncObjectType::ASSET);
$criteria->add(FileSyncPeer::OBJECT_SUB_TYPE, flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
$criteria->add(FileSyncPeer::DELETED_ID, null, Criteria::ISNULL);
$criteria->add(FileSyncPeer::DC, array($sourceDc, $storageIdDest), Criteria::IN);
$criteria->add(FileSyncPeer::PARTNER_ID, $asset->getPartnerId(), Criteria::EQUAL);
$criteria->addDescendingOrderByColumn(FileSyncPeer::VERSION);
$criteria->addAscendingOrderByColumn(FileSyncPeer::DC);
$fileSyncs = FileSyncPeer::doSelect($criteria);

$remoteDcFileSyncFound = false;
$maxVersion = -1;
$fileSyncToHandle = null;
//Get the Max Version and Local fileSync to handle
foreach ($fileSyncs as /** @var FileSync $fileSync * */ $fileSync)
{
if ($fileSync->getDc() == $sourceDc && $fileSync->getFileSize() > 0 && $fileSync->getVersion() > $maxVersion)
{
$fileSyncToHandle = $fileSync;
}
}
if (!$fileSyncToHandle)
{
KalturaLog::debug('No filesync to handle for flavor asset ' . $asset->getId());
continue;
}

// look for a sibling with same version on the remote storage
foreach ($fileSyncs as /** @var FileSync $fileSync * */ $fileSync)
{
if ($fileSync->getDc() === $storageIdDest && $fileSync->getVersion() == $fileSyncToHandle->getVersion())
{
$remoteDcFileSyncFound = true;
}
}

if ($remoteDcFileSyncFound)
{
KalturaLog::debug("Found file sync in remote dc [$storageIdDest] for assetId " . $asset->getId() . " . skipping exporting asset");
continue;
}

if ($fileSyncToHandle->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY)
{
KalturaLog::debug("Filesync " . $fileSyncToHandle->getId() . " in not ready " . $fileSyncToHandle->getStatus() . " - skipping asset");
continue;
}
try
{
KalturaLog::debug("Handling filesync " . $fileSyncToHandle->getId());
$newfileSync = $fileSyncToHandle->cloneToAnotherStorage($storageIdDest);
$newfileSync->save();
KalturaLog::debug('New FileSync created ' . $newfileSync->getId());
}
catch (Exception $e)
{
KalturaLog::warning("Could not create newFileSync for fileSync [" . $fileSync->getId() . "]" . $e->getMessage());
}
}
else
{
KalturaLog::debug('Asset ' . $asset->getId() . ' should not be Exported to remote storge ' . $storageIdDest);
}
}

kMemoryManager::clearMemory();
$count++;
if ($count % 1000 == 0 )
{
KalturaLog::debug("Sleeping 60 Seconds... count is $count");
sleep(60);
}
}
KalturaLog::debug("DONE!");
}
2 changes: 1 addition & 1 deletion plugins/thumbnail/ThumbnailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function getImageFile($entry, $version, $width, $height, $type, $bgcolor,
if($this->shouldUseThumbnailAdapter($entry->getPartnerId()))
{
$adapter = kThumbnailAdapterFactory::getAdapter($entry);
$params = kThumbnailAdapterFactory::getThumbAdapterParameters($entry, $version, $width, $height, $type, $bgcolor, $quality, $src_x, $src_y, $src_w, $src_h,
$params = kThumbnailAdapterFactory::getResizeThumbAdapterParameters($entry, $version, $width, $height, $type, $bgcolor, $quality, $src_x, $src_y, $src_w, $src_h,
$vid_sec, $vid_slice, $vid_slices, $orig_image_path, $density, $stripProfiles, $format, $fileSync, $start_sec, $end_sec);
$result = $adapter->resizeEntryImage($params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ interface kThumbnailParameterName extends BaseEnum
const IMAGE_FORMAT = 'format';
const QUALITY = 'quality';
const DENSITY = 'density';
const EXTEND_VECTOR = 'extendVector';
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class kThumbnailErrorMessages
const MISSING_TEXT = 'You must supply a text for this action';
const ENTRY_SOURCE_ONLY = ' can only work on entry source';
const FAILED = ' failed';
const SECOND = 'Second cant be negative';
const SECOND = 'Second cant be negative';
const VID_SLICE_FAILED = 'Vid slice failed';
const SLICE_NUMBER = 'Slice number must be positive and can not be greater then number of slices';
const NUMBER_OF_SLICE = 'Number of slices must be positive';
const SLICE_NUMBER = 'Slice number must be a natural number and can not be greater then number of slices';
const NUMBER_OF_SLICE = 'Number of slices must be a natural number';
const START_SEC = 'Start sec must be positive';
const END_SEC = 'End sec cant be greater then the video length';
const END_SEC_START_SEC = 'End sec must be greater then start sec';
Expand All @@ -44,4 +44,6 @@ class kThumbnailErrorMessages
const DENSITY_POSITIVE = 'Density must be positive';
const QUALITY_NOT_IN_RANGE = 'Quality must be between 20 and 100';
const WIDTH_AND_HEIGHT_ARE_ZERO = 'Width and height cannot both be equal zero';
const ILLEGAL_EXTEND_VECTOR = 'extend vector need to be width or height';
const X_MUST_BE_NATURAL = 'x must be a natural number';
}
65 changes: 65 additions & 0 deletions plugins/thumbnail/lib/model/imagickAction/kExtendImageAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @package core
* @subpackage thumbnail.imagickAction
*/

class kExtendImageAction extends kImagickAction
{
protected $extendVector;
protected $x;

/**
* @return Imagick
*/
protected function doAction()
{
$newHeight = $this->image->getImageHeight();
$newWidth = $this->image->getImageWidth();
if($this->extendVector === kThumbnailParameterName::HEIGHT)
{
$newHeight = $newHeight * $this->x;
}
else
{
$newWidth = $newWidth * $this->x;
}

$this->image->extentImage($newWidth, $newHeight, 0 ,0);
return $this->image;
}

protected function initParameterAlias()
{
$parameterAlias = array(
'ev' => kThumbnailParameterName::EXTEND_VECTOR,
);

$this->parameterAlias = array_merge($this->parameterAlias, $parameterAlias);
}

/**
* @throws kThumbnailException
*/
protected function validateInput()
{
if ($this->x <= 0)
{
$data = array(kThumbnailErrorMessages::ERROR_STRING => kThumbnailErrorMessages::X_MUST_BE_NATURAL);
throw new kThumbnailException(kThumbnailException::BAD_QUERY, kThumbnailException::BAD_QUERY, $data);
}

if($this->extendVector != kThumbnailParameterName::HEIGHT && $this->extendVector != kThumbnailParameterName::WIDTH)
{
$data = array(kThumbnailErrorMessages::ERROR_STRING => kThumbnailErrorMessages::ILLEGAL_EXTEND_VECTOR);
throw new kThumbnailException(kThumbnailException::BAD_QUERY, kThumbnailException::BAD_QUERY, $data);
}

}

protected function extractActionParameters()
{
$this->x = $this->getIntActionParameter(kThumbnailParameterName::X);
$this->extendVector = $this->getActionParameter(kThumbnailParameterName::EXTEND_VECTOR);
}
}
Loading

0 comments on commit 0edd742

Please sign in to comment.