<commit_before><commit_msg>Create dependency between cloud transcoding and live-plus permission PLAT-1254 #time 1h<commit_after><?php
/**
 * @package deployment
 * @subpackage live.liveParams
 *
 * Create dependency between cloud transcoding and FEATURE_KALTURA_LIVE_STREAM_TRANSCODE permission
 *
 * No need to re-run after server code deploy
 */

chdir(__DIR__);
require_once (__DIR__ . '/../../bootstrap.php');

$realRun = isset($argv[1]) && $argv[1] == 'realrun';
KalturaStatement::setDryRun(!$realRun);

function handleCloudTranscodeProfiles($partnerId, $isTemplate)
{
	$c = new Criteria();
	$c->add(conversionProfile2Peer::STATUS, ConversionProfileStatus::ENABLED);
	$c->add(conversionProfile2Peer::PARTNER_ID, $partnerId);
	$c->add(conversionProfile2Peer::SYSTEM_NAME, 'Default_Live');
	
	$conversionProfiles = conversionProfile2Peer::doSelect($c);
	foreach($conversionProfiles as $conversionProfile)
	{
		/* @var $conversionProfile conversionProfile2 */
		if($isTemplate)
		{
			$conversionProfile->setRequiredCopyTemplatePermissions(PermissionName::FEATURE_KALTURA_LIVE_STREAM_TRANSCODE);
		}
		elseif(!PermissionPeer::isValidForPartner(PermissionName::FEATURE_KALTURA_LIVE_STREAM_TRANSCODE, $partnerId))
		{
			$conversionProfile->setStatus(ConversionProfileStatus::DELETED);
		}
		$conversionProfile->save();
	}
}

function handleLivePartners($partnerIds)
{
	$c = new Criteria();
	$c->add(PartnerPeer::STATUS, Partner::PARTNER_STATUS_ACTIVE);
	$c->add(PartnerPeer::ID, $partnerIds, Criteria::IN);
	
	$partners = PartnerPeer::doSelect($c);
	foreach($partners as $partner)
	{
		/* @var $partner Partner */
		handleCloudTranscodeProfiles($partner->getId(), $partner->getPartnerGroupType() == PartnerGroupType::TEMPLATE);
	}
}

$c = new Criteria();
$c->add(PermissionPeer::STATUS, PermissionStatus::ACTIVE);
$c->add(PermissionPeer::NAME, PermissionName::FEATURE_LIVE_STREAM);
$c->addAscendingOrderByColumn(PermissionPeer::ID);
$c->setLimit(100);

$offset = 0;
$permissions = PermissionPeer::doSelect($c);
while(count($permissions))
{
	$partnerIds = array();
	foreach($permissions as $permission)
	{
		/* @var $permission Permission */
		$partnerIds[] = $permission->getPartnerId();
	}
	
	handleLivePartners($partnerIds);
	
	$offset += count($permissions);
	$c->setOffset($offset);
	$permissions = PermissionPeer::doSelect($c);
}
{'fraction_non_alphanumeric': 0.15203426124197003, 'fraction_numerical': 0.006852248394004282, 'mean_word_length': 7.525547445255475, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4231921', 'n_tokens_mistral': 793, 'n_tokens_neox': 763, 'n_words': 117}