function getClient() { // Check if client already exists if (!$this->client) { $conf = new KalturaConfiguration(null); $conf->serviceUrl = $this->getOption('ServiceUrl'); $conf->serviceBase = $this->getOption('ServiceBase'); $conf->clientTag = $this->getOption('ClientTag'); $conf->curlTimeout = $this->getOption('ServiceTimeout'); $conf->userAgent = $this->getOption('UserAgent'); $conf->verifySSL = false; $conf->requestHeaders = $this->getOption('RequestHeaders'); if ($this->getOption('Method')) { $conf->method = $this->getOption('Method'); } if ($this->getOption('Logger')) { $conf->setLogger($this->getOption('Logger')); } $this->client = new KalturaClient($conf); if ($this->getOption('KS')) { $this->setKS($this->getOption('KS')); } else { if ($this->getOption('WidgetId')) { $this->generateKS($this->getOption('WidgetId')); } } } return $this->client; }
/** * @param KSchedularTaskConfig $taskConfig */ public function __construct($taskConfig = null) { /* * argv[0] - the script name * argv[1] - serialized KSchedulerConfig config */ global $argv, $g_context; $this->sessionKey = uniqid('sess'); $this->start = microtime(true); if (is_null($taskConfig)) { $data = gzuncompress(base64_decode($argv[1])); self::$taskConfig = unserialize($data); } else { self::$taskConfig = $taskConfig; } if (!self::$taskConfig) { die("Task config not supplied"); } date_default_timezone_set(self::$taskConfig->getTimezone()); // clear seperator between executions KalturaLog::debug('___________________________________________________________________________________'); KalturaLog::stderr('___________________________________________________________________________________', KalturaLog::DEBUG); KalturaLog::info(file_get_contents(dirname(__FILE__) . "/../VERSION.txt")); if (!self::$taskConfig instanceof KSchedularTaskConfig) { KalturaLog::err('config is not a KSchedularTaskConfig'); die; } KalturaLog::debug("set_time_limit({" . self::$taskConfig->maximumExecutionTime . "})"); set_time_limit(self::$taskConfig->maximumExecutionTime); KalturaLog::debug('This batch index: ' . $this->getIndex()); KalturaLog::debug('This session key: ' . $this->sessionKey); self::$kClientConfig = new KalturaConfiguration(); self::$kClientConfig->setLogger($this); self::$kClientConfig->serviceUrl = self::$taskConfig->getServiceUrl(); self::$kClientConfig->curlTimeout = self::$taskConfig->getCurlTimeout(); if (isset(self::$taskConfig->clientConfig)) { foreach (self::$taskConfig->clientConfig as $attr => $value) { self::$kClientConfig->{$attr} = $value; } } self::$kClient = new KalturaClient(self::$kClientConfig); self::$kClient->setPartnerId(self::$taskConfig->getPartnerId()); self::$clientTag = 'batch: ' . self::$taskConfig->getSchedulerName() . ' ' . get_class($this) . " index: {$this->getIndex()} sessionId: " . UniqueId::get(); self::$kClient->setClientTag(self::$clientTag); //$ks = self::$kClient->session->start($secret, "user-2", KalturaSessionType::ADMIN); $ks = $this->createKS(); self::$kClient->setKs($ks); KDwhClient::setEnabled(self::$taskConfig->getDwhEnabled()); KDwhClient::setFileName(self::$taskConfig->getDwhPath()); $this->onBatchUp(); KScheduleHelperManager::saveRunningBatch($this->getName(), $this->getIndex()); }
function getServiceConfiguration($params = null) { static $config; if (!isset($config)) { $partnerId = $params->get('kaltura_partnerid'); $subPartnerId = $params->get('kaltura_sub_partnerid'); $config = new KalturaConfiguration($partnerId, $subPartnerId); //$config->serviceUrl = str_replace('/administrator', '', JURI::base()); $config->serviceUrl = KalturaHelpers::kalturaGetServerUrl(); $config->setLogger(new KalturaJoomlaLogger()); } return $config; }
private function getKalturaClient($partnerId, $adminSecret, $isAdmin) { $kConfig = new KalturaConfiguration($partnerId); $kConfig->serviceUrl = KalturaTestConfiguration::SERVICE_URL; $kConfig->setLogger($this); $client = new KalturaClient($kConfig); $userId = "SomeUser"; $sessionType = $isAdmin ? KalturaSessionType::ADMIN : KalturaSessionType::USER; try { $ks = $client->generateSession($adminSecret, $userId, $sessionType, $partnerId); $client->setKs($ks); } catch (Exception $ex) { die("could not start session - check configurations in KalturaTestConfiguration class"); } return $client; }
private function getKalturaClient($partnerId, $adminSecret, $isAdmin) { $kConfig = new KalturaConfiguration(); $kConfig->serviceUrl = $this->config[self::CONFIG_ITEM_SERVICE_URL]; $kConfig->setLogger($this); $client = new KalturaClient($kConfig); $userId = "SomeUser"; $sessionType = $isAdmin ? KalturaSessionType::ADMIN : KalturaSessionType::USER; try { $ks = $client->generateSession($adminSecret, $userId, $sessionType, $partnerId); $client->setKs($ks); } catch (Exception $ex) { throw new Exception("Could not start session - check configurations in config.ini"); } return $client; }
/** * @param KSchedularTaskConfig $taskConfig */ public function __construct($taskConfig = null) { parent::__construct($taskConfig); KalturaLog::debug('This batch index: ' . $this->getIndex()); KalturaLog::debug('This session key: ' . $this->sessionKey); $this->kClientConfig = new KalturaConfiguration(); $this->kClientConfig->setLogger($this); $this->kClientConfig->serviceUrl = $this->taskConfig->getServiceUrl(); $this->kClientConfig->curlTimeout = $this->taskConfig->getCurlTimeout(); $this->kClientConfig->clientTag = 'batch: ' . $this->taskConfig->getSchedulerName(); $this->kClient = new KalturaClient($this->kClientConfig); //$ks = $this->kClient->session->start($secret, "user-2", KalturaSessionType::ADMIN); $ks = $this->createKS(); $this->kClient->setKs($ks); KDwhClient::setFileName($this->taskConfig->getDwhPath()); $this->onBatchUp(); KScheduleHelperManager::saveRunningBatch($this->taskConfig->getCommandsDir(), $this->getName(), $this->getIndex()); }
/** * * @return KalturaClient */ public static function getClient() { if (self::$client) { return self::$client; } $partnerId = self::getPartnerId(); $ks = self::getKs(); $config = new KalturaConfiguration($partnerId); $config->serviceUrl = self::getServiceUrl(); $config->curlTimeout = self::getCurlTimeout(); $config->setLogger(new Kaltura_ClientLoggingProxy()); $front = Zend_Controller_Front::getInstance(); $bootstrap = $front->getParam('bootstrap'); if ($bootstrap) { $enviroment = $bootstrap->getApplication()->getEnvironment(); if ($enviroment === 'development') { $config->startZendDebuggerSession = true; } } $client = new KalturaClient($config); $client->setKs($ks); self::$client = $client; return $client; }
function getServiceConfiguration() { $partnerId = variable_get('kaltura_partner_id', 0); if ($partnerId == '') { $partnerId = 0; } $subPartnerId = variable_get('kaltura_subp_id', 0); if ($subPartnerId == '') { $subPartnerId = 0; } $config = new KalturaConfiguration($partnerId, $subPartnerId); $config->serviceUrl = KalturaHelpers::getKalturaServerUrl(); $config->setLogger(new KalturaLogger()); return $config; }
public function getClient() { global $wgKalturaServiceTimeout, $wgLogApiRequests; $cacheFile = $this->getCacheDir() . '/' . $this->getWidgetId() . '.' . $this->getCacheSt() . ".ks.txt"; $conf = new KalturaConfiguration(null); $conf->serviceUrl = $this->getServiceConfig('ServiceUrl'); $conf->serviceBase = $this->getServiceConfig('ServiceBase'); $conf->clientTag = $this->clientTag; $conf->curlTimeout = $wgKalturaServiceTimeout; $conf->userAgent = $this->getUserAgent(); $conf->verifySSL = false; $conf->requestHeaders = array($this->getRemoteAddrHeader()); if ($wgLogApiRequests) { require_once 'KalturaLogger.php'; $conf->setLogger(new KalturaLogger()); } $client = new KalturaClient($conf); // Set KS if (isset($this->urlParameters['flashvars']['ks'])) { $this->ks = $this->urlParameters['flashvars']['ks']; } else { if (isset($this->urlParameters['ks'])) { $this->ks = $this->urlParameters['ks']; } } // check for empty ks if (!isset($this->ks) || trim($this->ks) == '') { if ($this->canUseCacheFile($cacheFile)) { $this->ks = file_get_contents($cacheFile); } else { try { $session = $client->session->startWidgetSession($this->urlParameters['wid']); $this->ks = $session->ks; $this->partnerId = $session->partnerId; $this->putCacheFile($cacheFile, $this->ks); } catch (Exception $e) { throw new Exception(KALTURA_GENERIC_SERVER_ERROR . "\n" . $e->getMessage()); } } } // Set the kaltura ks and return the client $client->setKS($this->ks); return $client; }
$config = parse_ini_file("config.ini"); $serviceUrl = $config['service_url']; writeLog($logPrefix, 'Service URL ' . $serviceUrl); $sleepSec = $config['sleep_time']; $fileName = basename($filePath); $folderPath = dirname($filePath); writeLog($logPrefix, '---------------------------- Start handling --------------------------'); writeLog($logPrefix, 'action:' . $action); writeLog($logPrefix, 'file path:' . $filePath); writeLog($logPrefix, 'folder path:' . $folderPath); writeLog($logPrefix, 'file name:' . $fileName); writeLog($logPrefix, 'file size:' . $fileSize); $kClientConfig = new KalturaConfiguration(-1); $kClientConfig->serviceUrl = $serviceUrl; $kClientConfig->curlTimeout = 180; $kClientConfig->setLogger(new SyncDropFolderWatcherLogger($logPrefix)); $kClient = new KalturaClient($kClientConfig); $dropFolderPlugin = KalturaDropFolderClientPlugin::get($kClient); try { $folder = null; $filter = new KalturaDropFolderFilter(); $filter->pathEqual = $folderPath; $filter->typeEqual = KalturaDropFolderType::LOCAL; $filter->statusIn = KalturaDropFolderStatus::ENABLED . ',' . KalturaDropFolderStatus::ERROR; $dropFolders = $dropFolderPlugin->dropFolder->listAction($filter); writeLog($logPrefix, 'found ' . $dropFolders->totalCount . ' folders'); if ($dropFolders->totalCount == 1) { $folder = $dropFolders->objects[0]; writeLog($logPrefix, 'drop folder id ' . $folder->id); $ignorePatterns = array_map('trim', explode(',', $folder->ignoreFileNamePatterns)); foreach ($ignorePatterns as $ignorePattern) {
/** * Init a KalturaClient object for the target account * @param KalturaCrossKalturaDistributionProfile $distributionProfile * @throws Exception */ protected function initClients(KalturaCrossKalturaDistributionProfile $distributionProfile) { // init source client $sourceClientConfig = new KalturaConfiguration($distributionProfile->partnerId); $sourceClientConfig->serviceUrl = KBatchBase::$kClient->getConfig()->serviceUrl; // copy from static batch client $sourceClientConfig->setLogger($this); $this->sourceClient = new KalturaClient($sourceClientConfig); $this->sourceClient->setKs(KBatchBase::$kClient->getKs()); // copy from static batch client // init target client $targetClientConfig = new KalturaConfiguration($distributionProfile->targetAccountId); $targetClientConfig->serviceUrl = $distributionProfile->targetServiceUrl; $targetClientConfig->setLogger($this); $this->targetClient = new KalturaClient($targetClientConfig); $ks = $this->targetClient->user->loginByLoginId($distributionProfile->targetLoginId, $distributionProfile->targetLoginPassword, "", 86400, 'disableentitlement'); $this->targetClient->setKs($ks); }
/** * * Creates a new Kaltura API Unit Test Case * @param unknown_type $name * @param array $data * @param unknown_type $dataName */ public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); $testConfig = $this->config->get('config'); $needSave = false; if (!$testConfig->serviceUrl) { $testConfig->serviceUrl = 'http://www.kaltura.com/'; $needSave = true; } if (!$testConfig->partnerId) { $testConfig->partnerId = 100; $needSave = true; } if (!$testConfig->clientTag) { $testConfig->clientTag = 'unitTest'; $needSave = true; } if (!$testConfig->curlTimeout) { $testConfig->curlTimeout = 90; $needSave = true; } if (!$testConfig->startSession) { $testConfig->startSession = true; $needSave = true; } if ($testConfig->startSession) { if (!$testConfig->secret) { $testConfig->secret = 'PARTNER_SECRET'; $needSave = true; } if (!$testConfig->userId) { $testConfig->userId = ''; $needSave = true; } if (!$testConfig->sessionType) { $testConfig->sessionType = 0; $needSave = true; } if (!$testConfig->expiry) { $testConfig->expiry = 60 * 60 * 24; $needSave = true; } if (!$testConfig->privileges) { $testConfig->privileges = ''; $needSave = true; } } if ($needSave) { $this->config->saveToIniFile(); } $kalturaConfiguration = new KalturaConfiguration($testConfig->partnerId); $kalturaConfiguration->serviceUrl = $testConfig->serviceUrl; $kalturaConfiguration->clientTag = $testConfig->clientTag; $kalturaConfiguration->curlTimeout = $testConfig->curlTimeout; $kalturaConfiguration->setLogger($this); $this->client = new KalturaClient($kalturaConfiguration); if ($testConfig->startSession) { $ks = $this->client->session->start($testConfig->secret, $testConfig->userId, $testConfig->sessionType, $testConfig->partnerId, $testConfig->expiry, $testConfig->privileges); $this->client->setKs($ks); KalturaLog::info("Session started [{$ks}]"); } }
function getServiceConfiguration() { $partnerId = KalturaHelpers::getPlatformKey("partner_id", "0"); $config = new KalturaConfiguration($partnerId); $config->serviceUrl = KalturaHelpers::getKalturaServerUrl(); $config->setLogger(new KalturaLogger()); return $config; }
$savePath = null; if ($argc > 1) { $savePath = $argv[1]; } class clientLogger implements IKalturaLogger { function log($msg) { echo "{$msg}\n"; } } $partnerId = 101; $config = new KalturaConfiguration($partnerId); $config->curlTimeout = 300; $config->serviceUrl = 'http://kaltura.trunk'; $config->setLogger(new clientLogger()); $client = new KalturaClient($config); $ks = $client->generateSession('815d617b032593a8519c4dcc5f61b25f', 'tester', KalturaSessionType::ADMIN, $partnerId); $client->setKs($ks); $filter = new KalturaAccessControlFilter(); $filter->orderBy = KalturaAccessControlOrderBy::CREATED_AT_ASC; $pager = new KalturaFilterPager(); $pager->pageSize = 200; $pager->pageIndex = 0; $results = $client->accessControl->listAction($filter, $pager); /* @var $results KalturaAccessControlListResponse */ while (count($results->objects)) { echo count($results->objects) . "\n"; echo $results->totalCount . "\n"; if ($savePath) { foreach ($results->objects as $object) {
private function createCategoryEntriesWithEntitlement(array $categoriesArr, $entryId, $userId) { $partnerInfo = KBatchBase::$kClient->partner->get(KBatchBase::$kClientConfig->partnerId); $clientConfig = new KalturaConfiguration($partnerInfo->id); $clientConfig->serviceUrl = KBatchBase::$kClient->getConfig()->serviceUrl; $clientConfig->setLogger($this); $client = new KalturaClient($clientConfig); foreach ($categoriesArr as $category) { /* @var $category KalturaCategory */ $ks = $client->generateSessionV2($partnerInfo->adminSecret, $userId, KalturaSessionType::ADMIN, $partnerInfo->id, 86400, 'enableentitlement,privacycontext:' . $category->privacyContexts); $client->setKs($ks); $categoryEntry = new KalturaCategoryEntry(); $categoryEntry->categoryId = $category->id; $categoryEntry->entryId = $entryId; try { $client->categoryEntry->add($categoryEntry); } catch (Exception $e) { KalturaLog::err("Could not add entry {$entryId} to category {$category->id}. Exception thrown."); } } }
} function askForUserParameter($message) { fwrite(STDERR, "{$message} "); return trim(fgets(STDIN)); } require_once realpath(__DIR__ . '/../') . '/lib/KalturaClient.php'; class KalturaStandAloneTestLogger implements IKalturaLogger { function log($msg) { echo "{$msg}\n"; } } $config = new KalturaConfiguration(); $config->setLogger(new KalturaStandAloneTestLogger()); $client = new KalturaClient($config); if (isset($inXml->variables)) { $variablesXml = $inXml->variables->children(); foreach ($variablesXml as $variableXml) { if (!isset($variableXml['name'])) { continue; } $variableValue = parseInputObject($variableXml); $variables[strval($variableXml['name'])] = $variableValue; } } if (isset($inXml->config)) { $configs = $inXml->config->children(); foreach ($configs as $configItem) { $configItemName = $configItem->getName();
$headers = array(); $headerLines = file($headerFilePath); foreach ($headerLines as $header) { if (preg_match('/HTTP\\/?[\\d.]{0,3} ([\\d]{3}) ([^\\n\\r]+)/', $header, $matches)) { $errCode = $matches[1]; continue; } $parts = explode(':', $header, 2); if (count($parts) != 2) { continue; } list($name, $value) = $parts; $headers[trim(strtolower($name))] = trim($value); } return $errCode; } require_once '/opt/kaltura/web/content/clientlibs/php5/KalturaClient.php'; class SanityTestLogger implements IKalturaLogger { function log($msg) { //echo "Client: $msg\n"; } } $clientConfig = new KalturaConfiguration(); $clientConfig->setLogger(new SanityTestLogger()); $clientConfig->partnerId = null; foreach ($config['client'] as $field => $value) { $clientConfig->{$field} = $value; } $client = new KalturaClient($clientConfig);
/** * * Creates a new Kaltura API Test Case * @param unknown_type $name * @param array $data * @param unknown_type $dataName */ public function __construct($name = NULL, array $data = array(), $dataName = '') { KalturaLog::debug("KalturaApiTestCase::__construct name [{$name}], data [" . print_r($data, true) . "], dataName [{$dataName}]\n"); parent::__construct($name, $data, $dataName); $testConfig = $this->config->get('config'); $needSave = false; //TODO: add support for getting the values from the global data if (!$testConfig->serviceUrl) { $testConfig->serviceUrl = '@SERVICE_URL@'; $needSave = true; } if (!$testConfig->partnerId) { $testConfig->partnerId = "@TEST_PARTNER_ID@"; $needSave = true; } if (!$testConfig->clientTag) { $testConfig->clientTag = 'unitTest'; $needSave = true; } if (!$testConfig->curlTimeout) { $testConfig->curlTimeout = 90; $needSave = true; } if (!isset($testConfig->startSession)) { $testConfig->startSession = false; $needSave = true; } if ($testConfig->startSession) { if (!$testConfig->secret) { $testConfig->secret = 'PARTNER_SECRET'; $needSave = true; } if (!$testConfig->userSecret) { $testConfig->secret = 'PARTNER_USER_SECRET'; $needSave = true; } if (!$testConfig->userId) { $testConfig->userId = ''; } if (!$testConfig->sessionType) { $testConfig->sessionType = 2; $needSave = true; } if (!$testConfig->expiry) { $testConfig->expiry = 60 * 60 * 24; $needSave = true; } if (!$testConfig->privileges) { $testConfig->privileges = ''; } } if ($needSave) { $this->config->saveToIniFile(); } $kalturaConfiguration = new KalturaConfiguration($testConfig->partnerId); $kalturaConfiguration->serviceUrl = $testConfig->serviceUrl; $kalturaConfiguration->clientTag = $testConfig->clientTag; $kalturaConfiguration->curlTimeout = $testConfig->curlTimeout; $kalturaConfiguration->setLogger($this); $this->client = new KalturaClient($kalturaConfiguration); if ($testConfig->startSession) { $this->startSession($this->client, $testConfig->sessionType, $testConfig->userId); } if ($testConfig->serviceUrlStaging) { $kalturaConfigurationStaging = $kalturaConfiguration; $kalturaConfigurationStaging->serviceUrl = $testConfig->serviceUrlStaging; $this->clientStaging = new KalturaClient($kalturaConfigurationStaging); if ($testConfig->startSession) { $this->startSession($this->clientStaging, $testConfig->sessionType, $testConfig->userId); } } }
$responseHeaders = $this->getResponseHeaders(); foreach ($responseHeaders as $header) { if (preg_match('/HTTP\\/?[\\d.]{0,3} ([\\d]{3}) ([^\\n\\r]+)/', $header, $matches)) { $errCode = $matches[1]; continue; } $parts = explode(':', $header, 2); if (count($parts) != 2) { continue; } list($name, $value) = $parts; $headers[trim(strtolower($name))] = trim($value); } $this->resetRequest(); return $errCode; } } $config = parse_ini_file(__DIR__ . '/../config.ini', true); $serviceUrl = $config['client-config']['protocol'] . '://' . $options['service-url'] . ':' . $config['client-config']['port']; $clientConfig = new KalturaConfiguration(); $clientConfig->serviceUrl = $serviceUrl; foreach ($config['config'] as $attribute => $value) { $clientConfig->{$attribute} = $value; } if (isset($options['debug'])) { $clientConfig->setLogger(new KalturaMonitorClientLogger()); } $client = new KalturaMonitorClient($clientConfig); foreach ($config['client-config'] as $attribute => $value) { $client->setClientConfiguration($attribute, $value); }