<commit_before><commit_msg>fwr: new permission migration script<commit_after><?php
require_once(dirname(__FILE__).'/../../bootstrap.php');

$permissionName = 'FEATURE_MIX_TAB';
$startUpdatedAt = null;
$startPartnerId = 0;
$limit = null;
$page = 200;

$dryRun = false;
if($argc == 1 || strtolower($argv[1]) != 'realrun')
{
	$dryRun = true;
	KalturaLog::alert('Using dry run mode');
}

if($argc > 2)
	$startUpdatedAt = $argv[2];
	
if($argc > 3)
	$limit = $argv[3];
	
$criteria = new Criteria();
$criteria->add(PartnerPeer::ID, $startPartnerId, Criteria::GREATER_THAN);
$criteria->addAscendingOrderByColumn(PartnerPeer::ID);

if($startUpdatedAt)
	$criteria->add(PartnerPeer::UPDATED_AT, $startUpdatedAt, Criteria::GREATER_THAN);
	
if($limit)
	$criteria->setLimit(min($page, $limit));
else
	$criteria->setLimit($page);

$partners = PartnerPeer::doSelect($criteria);
$migrated = 0;
while(count($partners) && (!$limit || $migrated < $limit))
{
	KalturaLog::info("Migrating [" . count($partners) . "] partners.");
	$migrated += count($partners);
	foreach($partners as $partner)
	{
		/* @var $partner Partner */

		$permission = PermissionPeer::getByNameAndPartner($permissionName, array($partner->getId(), 0));
		if(!$permission)
		{
			$permission = new Permission();
			$permission->setName($permissionName);
			$permission->setType(PermissionType::SPECIAL_FEATURE);
			$permission->setPartnerId($partner->getId());
		}
		$permission->setStatus(PermissionStatus::ACTIVE);
		KalturaStatement::setDryRun($dryRun);
		$permission->save();
		KalturaStatement::setDryRun(false);
		
		$startUpdatedAt = $partner->getUpdatedAt(null);
		$startPartnerId = $partner->getId();
		KalturaLog::info("Migrated partner [" . $partner->getId() . "] with updated at [$startUpdatedAt: " . $partner->getUpdatedAt() . "].");
	}
	kMemoryManager::clearMemory();

	$nextCriteria = clone $criteria;
	$nextCriteria->add(PartnerPeer::ID, $startPartnerId, Criteria::GREATER_THAN);
	$partners = PartnerPeer::doSelect($nextCriteria);
}

KalturaLog::info("Done");

{'fraction_non_alphanumeric': 0.18377088305489261, 'fraction_numerical': 0.005727923627684964, 'mean_word_length': 5.313253012048193, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '4437083', 'n_tokens_mistral': 767, 'n_tokens_neox': 732, 'n_words': 108}