<commit_before><?php
class PartnerController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$this->_helper->redirector('list');
	}
	
	public function createAction()
	{
		$request = $this->getRequest();
		$client = Kaltura_ClientHelper::getClient();
		$form = new Form_PartnerCreate();
		Form_PackageHelper::addPackagesToForm($form, $client->systemPartner->getPackages());
		
		if ($request->isPost())
		{
			if ($form->isValid($request->getPost()))
			{
				$partner = $form->getObject("KalturaPartner", $request->getPost());
				if(is_array($partner->contentCategories))
					$partner->contentCategories = implode(',', $partner->contentCategories);
					
				$partner->adminName = $partner->name;
				$partner->description = "Admin Console";
				$client->startMultiRequest();
				
				// queue register partner without a ks, otherwise we get an exception saying partner -2 is not a VAR/GROUP
				$originalKs = $client->getKs();
				$client->setKs(null);
				$client->partner->register($partner);
				
				// queue partner package update
				$client->setKs($originalKs);
				$config = new KalturaSystemPartnerConfiguration();
				$config->partnerPackage = $form->getValue('partner_package');
				$config->storageDeleteFromKaltura = true;
				$config->storageServePriority = KalturaStorageServePriority::EXTERNAL_FIRST;
				$client->systemPartner->updateConfiguration('{1:result:id}', $config);
				
				// do multirequest
				$result = $client->doMultiRequest();
				
				// check for errors in partner.register
				if ($client->isError($result[0])) 
				{
					if (strpos($result[0]['message'], 'already exists in system') !== false)
						$form->getElement('admin_email')->addError('Email already exists');
					else
						throw new KalturaException($result[0]['message'], $result[0]['code']);
				}
				else
				{
					$this->_helper->redirector('list');
				}
			}
			else
			{
				$form->populate($request->getPost());
			}
		}
		
		$this->view->form = $form;
	}
	
	public function listAction()
	{
		$request = $this->getRequest();
		$page = $this->_getParam('page', 1);
		$pageSize = $this->_getParam('pageSize', 10);
		
		$action = $this->view->url(array('controller' => 'partner', 'action' => 'list'), null, true);

		$client = Kaltura_ClientHelper::getClient();
		
		$form = new Form_PartnerFilter();
		$form->setAction($action);
		
		// init filter
		$partnerFilter = $this->getPartnerFilterFromRequest($request);
		
		// get results and paginate
		$paginatorAdapter = new Kaltura_FilterPaginator("systemPartner", "listAction", $partnerFilter);
		$paginator = new Kaltura_Paginator($paginatorAdapter, $request);
		$paginator->setCurrentPageNumber($page);
		$paginator->setItemCountPerPage($pageSize);
		
		// popule the form
		$form->populate($request->getParams());
		
		// set view
		$this->view->form = $form;
		$this->view->paginator = $paginator;
	}
	
	public function updateStorageStatusAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$storageId = $this->_getParam('storageId');
		$status = $this->_getParam('status');
		$client = Kaltura_ClientHelper::getClient();
		$client->storageProfile->updateStatus($storageId, $status);
		echo $this->_helper->json('ok', false);
	}
	
	public function updateStatusAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$partnerId = $this->_getParam('partner_id');
		$status = $this->_getParam('status');
		$client = Kaltura_ClientHelper::getClient();
		$client->systemPartner->updateStatus($partnerId, $status);
		echo $this->_helper->json('ok', false);
	}
	
	public function kmcRedirectAction()
	{
		$partnerId = $this->_getParam('partner_id');
		$client = Kaltura_ClientHelper::getClient();
		$ks = $client->systemPartner->getAdminSession($partnerId);
		$subp_id = ((int)$partnerId)*100;
		$url = Kaltura_ClientHelper::getServiceUrl();
		$url = $url . '/index.php/kmc/extlogin?partner_id='.$partnerId.'&ks='.$ks.'&subp_id='.$subp_id;
		$this->getResponse()->setRedirect($url);
	}
	
	public function configureStorageAction()
	{
		$this->_helper->layout->disableLayout();
		$storageId = $this->_getParam('storageId');
		
		$editMode = false;
		if ($storageId)
			$editMode = true;
			
		$client = Kaltura_ClientHelper::getClient();
		$form = new Form_Partner_StorageConfiguration();
		Form_Partner_StorageHelper::addProtocolsToForm($form);
		Form_Partner_StorageHelper::addPathManagersToForm($form);
		Form_Partner_StorageHelper::addUrlManagersToForm($form);
		Form_Partner_StorageHelper::addTriggersToForm($form);
		
		$request = $this->getRequest();
		<commit_msg>Use KMC url from config<commit_after><?php
class PartnerController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$this->_helper->redirector('list');
	}
	
	public function createAction()
	{
		$request = $this->getRequest();
		$client = Kaltura_ClientHelper::getClient();
		$form = new Form_PartnerCreate();
		Form_PackageHelper::addPackagesToForm($form, $client->systemPartner->getPackages());
		
		if ($request->isPost())
		{
			if ($form->isValid($request->getPost()))
			{
				$partner = $form->getObject("KalturaPartner", $request->getPost());
				if(is_array($partner->contentCategories))
					$partner->contentCategories = implode(',', $partner->contentCategories);
					
				$partner->adminName = $partner->name;
				$partner->description = "Admin Console";
				$client->startMultiRequest();
				
				// queue register partner without a ks, otherwise we get an exception saying partner -2 is not a VAR/GROUP
				$originalKs = $client->getKs();
				$client->setKs(null);
				$client->partner->register($partner);
				
				// queue partner package update
				$client->setKs($originalKs);
				$config = new KalturaSystemPartnerConfiguration();
				$config->partnerPackage = $form->getValue('partner_package');
				$config->storageDeleteFromKaltura = true;
				$config->storageServePriority = KalturaStorageServePriority::EXTERNAL_FIRST;
				$client->systemPartner->updateConfiguration('{1:result:id}', $config);
				
				// do multirequest
				$result = $client->doMultiRequest();
				
				// check for errors in partner.register
				if ($client->isError($result[0])) 
				{
					if (strpos($result[0]['message'], 'already exists in system') !== false)
						$form->getElement('admin_email')->addError('Email already exists');
					else
						throw new KalturaException($result[0]['message'], $result[0]['code']);
				}
				else
				{
					$this->_helper->redirector('list');
				}
			}
			else
			{
				$form->populate($request->getPost());
			}
		}
		
		$this->view->form = $form;
	}
	
	public function listAction()
	{
		$request = $this->getRequest();
		$page = $this->_getParam('page', 1);
		$pageSize = $this->_getParam('pageSize', 10);
		
		$action = $this->view->url(array('controller' => 'partner', 'action' => 'list'), null, true);

		$client = Kaltura_ClientHelper::getClient();
		
		$form = new Form_PartnerFilter();
		$form->setAction($action);
		
		// init filter
		$partnerFilter = $this->getPartnerFilterFromRequest($request);
		
		// get results and paginate
		$paginatorAdapter = new Kaltura_FilterPaginator("systemPartner", "listAction", $partnerFilter);
		$paginator = new Kaltura_Paginator($paginatorAdapter, $request);
		$paginator->setCurrentPageNumber($page);
		$paginator->setItemCountPerPage($pageSize);
		
		// popule the form
		$form->populate($request->getParams());
		
		// set view
		$this->view->form = $form;
		$this->view->paginator = $paginator;
	}
	
	public function updateStorageStatusAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$storageId = $this->_getParam('storageId');
		$status = $this->_getParam('status');
		$client = Kaltura_ClientHelper::getClient();
		$client->storageProfile->updateStatus($storageId, $status);
		echo $this->_helper->json('ok', false);
	}
	
	public function updateStatusAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$partnerId = $this->_getParam('partner_id');
		$status = $this->_getParam('status');
		$client = Kaltura_ClientHelper::getClient();
		$client->systemPartner->updateStatus($partnerId, $status);
		echo $this->_helper->json('ok', false);
	}
	
	public function kmcRedirectAction()
	{
		$partnerId = $this->_getParam('partner_id');
		$client = Kaltura_ClientHelper::getClient();
		$ks = $client->systemPartner->getAdminSession($partnerId);
		$subp_id = ((int)$partnerId)*100;
		
		$url = null;
		$settings = Zend_Registry::get('config')->settings;
		if($settings->kmcUrl)
		{
			$url = $settings->kmcUrl;
		}
		else
		{
			$url = Kaltura_ClientHelper::getServiceUrl();	
			$url .= '/index.php/kmc/extlogin';
		}
		
		$url .= '?partner_id='.$partnerId.'&ks='.$ks.'&subp_id='.$subp_id;
		$this->getResponse()->setRedirect($url);
	}
	
	public function configureStorageAction()
	{
		$this->_helper->layout->disableLayout();
		$storageId = $this->_getParam('storageId');
		
		$editMode = false;
		if ($storageId)
			$editMode = true;
			
		$client = Kaltura_ClientHelper::getClient();
		$form = new Form_Partner_StorageConfiguration();
		Form_Partner_StorageHelper::addProtocolsToForm($form);
		Form_Partner_StorageHelper::addPathManagersToForm($form);
		Form_Partner_StorageHelper::addUrlManagersToForm($form);
		Form_Partner_StorageHelper::addTriggersToForm($form);
		
		$request = $this->getRequest();
		
{'fraction_non_alphanumeric': 0.1705743170574317, 'fraction_numerical': 0.002581200258120026, 'mean_word_length': 4.6944274341702386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 172, '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': '6194202', 'n_tokens_mistral': 3474, 'n_tokens_neox': 2946, 'n_words': 475}