/** * get the kaltura client * @param bol $isAdmin default = false * @param $privileges * @return unknown_type */ function getClient($isAdmin = false, $privileges = null) { // get the configuration to use the kaltura client $kalturaConfig = KalturaHelpers::getServiceConfiguration($this->params); // inititialize the kaltura client using the above configurations $kalturaClient = new KalturaClient($kalturaConfig); // get the current logged in user $sessionUser = KalturaHelpers::kalturaGetSessionUser(); if ($isAdmin) { $adminSecret = $this->params->get("kaltura_webservice_admin_secret"); $result = $kalturaClient->startsession($sessionUser, $adminSecret, true, $privileges); } else { $secret = $this->params->get("kaltura_webservice_secret"); $result = $kalturaClient->startsession($sessionUser, $secret, false, $privileges); } if (count(@$result["error"])) { return null; } else { // now lets get the session key $session = $result["result"]["ks"]; // set the session so we can use other service methods $kalturaClient->setKs($session); } return $kalturaClient; }
function getPlayList() { // Your Kaltura partner credentials define("PARTNER_ID", "xxxxxxx"); define("ADMIN_SECRET", "xxxxxxx"); $user = "******"; $kconf = new KalturaConfiguration(PARTNER_ID); $kclient = new KalturaClient($kconf); $ksession = $kclient->session->start(ADMIN_SECRET, $user, KalturaSessionType::ADMIN); if (!isset($ksession)) { die("Could not establish Kaltura session. Please verify that you are using valid Kaltura partner credentials."); } $kclient->setKs($ksession); $result = $kclient->playlist->get('0_3x0phjri'); $l = explode(",", $result->playlistContent); foreach ($l as $key => $value) { $filter = new KalturaMetadataFilter(); $filter->objectIdEqual = $value; $metadata = $kclient->metadata->listAction($filter)->objects; $id = $metadata[0]->objectId; if (isset($metadata[0]->xml)) { $xml = $metadata[0]->xml; $meta = new SimpleXMLElement($xml); $amt = (string) $meta->Amt; $taxamt = (string) $meta->Taxamt; } $obj = array("name" => "Video", "number" => $value, "category" => "Digital", "desc" => "my video", "amt" => $amt, "taxamt" => $taxamt); $objArray[] = $obj; } return $objArray; }
function get_se_wizard($div, $width, $height, $entryId) { $params = "''"; $url = "''"; $platformUser = "******"" . KalturaHelpers::getSessionUser()->userId . "\""; $kalturaSecret = KalturaHelpers::getPlatformKey("secret", ""); if ($kalturaSecret != null && strlen($kalturaSecret) > 0) { try { $kClient = new KalturaClient(KalturaHelpers::getServiceConfiguration()); $kalturaUser = KalturaHelpers::getPlatformKey("user", ""); $ksId = $kClient->session->start($kalturaSecret, $kalturaUser, KalturaSessionType::USER, null, 86400, "*"); $kClient->setKs($ksId); $url = KalturaHelpers::getSimpleEditorUrl(KalturaHelpers::getPlatformKey("editor", null)); $params = KalturaHelpers::flashVarsToString(KalturaHelpers::getSimpleEditorFlashVars($ksId, $entryId, "entry", "")); } catch (Exception $exp) { $flash_embed = $exp->getMessage(); } $flash_embed = ' <div id="' . $div . '" style="width:' . $width . 'px;height:' . $height . ';"> <script type="text/javascript"> var kso = new SWFObject("' . $url . '", "KalturaSW", "' . $width . '", "' . $height . '", "9", "#ffffff"); kso.addParam("flashVars", "' . $params . '"); kso.addParam("allowScriptAccess", "always"); kso.addParam("allowFullScreen", "TRUE"); kso.addParam("allowNetworking", "all"); if(kso.installedVer.major >= 9) { kso.write("' . $div . '"); } else { document.getElementById("' . $div . '").innerHTML = "Flash player version 9 and above is required. <a href=\\"http://get.adobe.com/flashplayer/\\">Upgrade your flash version</a>"; } </script> '; return $flash_embed; } }
function getData() { $params = $this->getParams(); $conf = $this->getKalturaConfig(); $user = new KalturaSessionUser(); $user->userId = "1"; $cl = new KalturaClient($conf); $res = $cl->startSession($user, $params->get('kaltura_admin_secret'), true); //$res =$cl->startAdmin($user, $conf->adminSecret , null); //$ks = $cl->getKs(); $ks = $res['result']['ks']; echo $ks; // create a filter to define what exactly we want to be in the list $filter =& $this->getKalturaFilter(); $page = $this->getKalturaPage(); $page_size = 20; // choose the page_size to be some number that will fit the area you would like to display the thumbnails gallery $detailed = false; $res = $cl->listentries ( $user , $filter , $detailed , $page_size , $page); $count = @$res["result"]["count"]; $entries = @$res["result"]["entries"]; if (!$entries) $entries =array(); return $entries; }
private static function buildSubTitleCommandParam(KalturaConvartableJobData $data, KalturaClient $client) { // $cmdStr.= " -add ".KDLCmdlinePlaceholders::OutFileName.".temp.srt:hdlr=sbtl:lang=$lang:group=0:layer=-1"; // impersonite $preImpersoniteId = $client->getConfig()->partnerId; $client->getConfig()->partnerId = $data->flavorParamsOutput->partnerId; $flrAsst = $client->flavorAsset->get($data->flavorAssetId); if (!isset($flrAsst)) { throw new KOperationEngineException("Failed to retrieve the flavor asset object (" . $data->flavorAssetId . ")"); } $filter = new KalturaAssetFilter(); $filter->entryIdEqual = $flrAsst->entryId; $captionsList = $client->captionAsset->listAction($filter, null); if (!isset($captionsList) || count($captionsList->objects) == 0) { throw new KOperationEngineException("No caption assets for entry (" . $flrAsst->entryId . ")"); } $captionsStr = null; $addedSubs = 0; foreach ($captionsList->objects as $captionObj) { try { $cptUrl = $client->captionAsset->getUrl($captionObj->id, null); } catch (Exception $ex) { $cptUrl = null; KalturaLog::err("Exception on etrieve caption asset url retrieval (" . $captionObj->id . "),\nexception:" . print_r($ex, 1)); } if (!isset($cptUrl)) { KalturaLog::err("Failed to retrieve caption asset url (" . $captionObj->id . ")"); continue; } $cptFilePath = self::retrieveCaptionFile($captionObj, $cptUrl, $data->destFileSyncLocalPath); if (!isset($cptFilePath)) { continue; } /* * group - "An integer that specifies a group or collection of tracks. If this field is 0 there is no information * on possible relations to other tracks. If this field is not 0, it should be the same for tracks that contain * alternate data for one another and different for tracks belonging to different such groups. Only one track * within an alternate group should be played or streamed at any one time, and must be distinguishable from other * racks in the group via attributes such as bitrate, codec, language, packet size etc. A group may have only one member. " * To follow that desc, the group id for all subtitles would be set to 1. * Apart from the first subs track, all the others would be tagged with 'disabled', otherwise the older iOS devices (pre 5.x) * does not handle it properly. * layer - "Specifies the front-to-back ordering of video tracks; tracks with lower numbers are closer to the viewer. * 0 is the normal value, and -1 would be in front of track 0, and so on." * layer=-1, closest to the viewer */ $captionsStr .= " -add " . $cptFilePath . ":hdlr=sbtl:lang=" . $captionObj->languageCode . ":group=1:layer=-1"; if ($addedSubs > 0) { $captionsStr .= ":disabled"; } $addedSubs++; } // un-impersonite $client->getConfig()->partnerId = $preImpersoniteId; if (!isset($captionsStr)) { throw new KOperationEngineException("Error: missing caption data or files."); } return $captionsStr; }
function generate_ks($service_url, $partnerId, $secret, $type = KalturaSessionType::ADMIN, $userId = null, $expiry = null, $privileges = null) { $config = new KalturaConfiguration($partnerId); $config->serviceUrl = $service_url; $client = new KalturaClient($config); $ks = $client->session->start($secret, $userId, $type, $partnerId, $expiry, $privileges); $client->setKs($ks); return $client; }
function isPayItem($entryId) { require_once 'kalturaConfig.php'; require_once 'client/KalturaClient.php'; $config = new KalturaConfiguration(PARTNER_ID); $config->serviceUrl = 'http://www.kaltura.com/'; $client = new KalturaClient($config); global $USER_ID; $ks = $client->generateSession(ADMIN_SECRET, $USER_ID, KalturaSessionType::ADMIN, PARTNER_ID); $client->setKs($ks); $entry = $client->media->get($entryId); $paid = ''; if ($entry->categoriesIds != '') { $categories = explode(',', $entry->categoriesIds); foreach ($categories as $category) { $filter = new KalturaMetadataFilter(); $filter->metadataObjectTypeEqual = KalturaMetadataObjectType::CATEGORY; $filter->objectIdEqual = trim($category); $pager = new KalturaFilterPager(); $pager->pageSize = 500; $pager->pageIndex = 1; $categoryMetadatas = $client->metadata->listAction($filter, $pager)->objects; foreach ($categoryMetadatas as $categoryMetadata) { $categoryMetadataProfile = $client->metadataProfile->get($categoryMetadata->metadataProfileId); if ($categoryMetadata->metadataProfileId == PAYPAL_CATEGORY_METADATA_PROFILE_ID) { $xml = simplexml_load_string($categoryMetadata->xml); if ($paid != 'true') { $paid = strtolower($xml->Paid); } //Only need to find one instance of a paid category break; } } } } //If the video is not part of a paid channel, see if the video itself is paid if ($paid != 'true') { $pager = new KalturaFilterPager(); $pageSize = 50; $pager->pageSize = $pageSize; $metadataFilter = new KalturaMetadataFilter(); $metadataFilter->objectIdEqual = $entryId; $metaResults = $client->metadata->listAction($metadataFilter, $pager)->objects; foreach ($metaResults as $metaResult) { if ($metaResult->metadataProfileId == PAYPAL_METADATA_PROFILE_ID) { $xml = simplexml_load_string($metaResult->xml); $paid = strtolower($xml->Paid); break; } } } if ($paid == '') { echo 'false'; } else { echo $paid; } }
private function establishConnection($ini_file) { $config = new KalturaConfiguration($ini_file["partner_id"]); $config->serviceUrl = $ini_file["service_url"]; $client = new KalturaClient($config); $partnerId = $ini_file["partner_id"]; $ks = $client->session->start($ini_file["admin_secret"], "", KalturaSessionType::ADMIN, $partnerId); $client->setKs($ks); return $client; }
function getSessionOnce($itemId, $userId) { //Create a session $conf = new KalturaConfiguration(PARTNER_ID); $client = new KalturaClient($conf); $session = $client->session->start(USER_SECRET, $userId, KalturaSessionType::USER, PARTNER_ID, 86400, 'sview:' . $itemId); if (!isset($session)) { die("Could not establish Kaltura session with OLD session credentials. Please verify that you are using valid Kaltura partner credentials."); } $client->setKs($session); echo $session; }
/** * * Gets an API object from the API - using a client session and KS also using the action get from this service on the object id * * @param KalturaObjectBase $objectInstance * @param string $objectId * @param int $partnerId * @param string $secret * @param string $serviceUrl * @param string $service * @throws KalturaAPIException */ private static function getAPIObject(KalturaObjectBase $objectInstance, $objectId, $partnerId, $secret, $serviceUrl, $service) { //here we create the KS and get the data from the API calls $config = new KalturaConfiguration((int) $partnerId); $config->serviceUrl = $serviceUrl; $client = new KalturaClient($config); $ks = $client->session->start($secret, null, KalturaSessionType::ADMIN, (int) $partnerId, null, null); $client->setKs($ks); $entryId = $objectId; $result = $client->{$service}->get($entryId); return $result; }
private function getKalturaClient($partnerId, $adminSecret, $isAdmin) { $kConfig = new KalturaConfiguration($partnerId); $kConfig->serviceUrl = KalturaTestConfiguration::SERVICE_URL; $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; }
private function initClient() { echo 'initClient' . PHP_EOL; if ($this->client) { return; } try { $config = new KalturaConfiguration(Config::PARTNER_ID); $config->serviceUrl = Config::SERVER_URL; $client = new KalturaClient($config); $ks = $client->session->start(Config::PARTNER_ADMIN_SECRET, Config::PARTNER_USER_ID, KalturaSessionType::ADMIN, Config::PARTNER_ID); $client->setKs($ks); } catch (Exception $ex) { $this->assertTrue(false, 'Exception in session->start - ' . $ex->getMessage()); } $this->client = $client; }
function getClient() { // Get kaltura configuration file require_once realpath(dirname(__FILE__)) . '/../config/kConf.php'; $kConf = new kConf(); // Load kaltura client require_once realpath(dirname(__FILE__)) . '/../../clients/php5/KalturaClient.php'; try { $conf = new KalturaConfiguration($this->partnerId); $conf->serviceUrl = 'http://' . $kConf->get('www_host'); $client = new KalturaClient($conf); $client->setKS($this->Ks); } catch (Exception $e) { $this->error = 'Error setting KS. <a href="' . $_SERVER['SCRIPT_NAME'] . '">Try again</a>'; die($this->error); return false; } return $client; }
function startKalturaSession() { $kConfig = new KalturaConfiguration(PARTNER_ID); $kConfig->serviceUrl = kalturaServiceURL; $client = new KalturaClient($kConfig); writeToLog("startKalturaSession()"); $userID = "OVALAutomatedUploads"; // If this user does not exist in your KMC, then it will be created. //$sessionType = ($isAdmin)? KalturaSessionType::ADMIN : KalturaSessionType::USER; $sessionType = KalturaSessionType::ADMIN; try { $ks = $client->generateSession(ADMIN_SECRET, $userID, $sessionType, PARTNER_ID); $client->setKs($ks); } catch (Exception $ex) { writeToLog("could not start session - check configurations in KalturaTestConfiguration class"); } //writeToLog("client: " . print_r($client, true)); return $client; }
private function getClient() { if (!$this->initialized && !$this->client) { $this->initialized = true; try { $client = new KalturaClient($this->getConfig()); if ($session = $this->storedKey()) { $client->setKs($session); $this->client = $client; } elseif ($session = $this->initializeClient($client)) { $client->setKs($session); $this->client = $client; $this->storedKey($session); } } catch (Exception $e) { TikiLib::lib('errorreport')->report($e->getMessage()); } } return $this->client; }
/** * Starts a new session * @param KalturaSessionType $type * @param string $userId */ private function startSession2($type, $userId) { $secret = $type == KalturaSessionType::ADMIN ? self::TEST_ADMIN_SECRET_2 : self::TEST_USER_SECRET_2; $ks = $this->client2->session->start($secret, $userId, $type, self::TEST_PARTNER_ID_2); $this->assertNotNull($ks); if (!$ks) { return false; } $this->client2->setKs($ks); return true; }
/** * Helper function to generate the KS (kaltura session) * @param bool $admin - wether or not to use an admin session * @return KalturaClient */ function simplekaltura_create_client($admin = false) { // Get settings $partner_user_id = elgg_get_plugin_setting('kaltura_partnerid', 'simplekaltura'); //Construction of Kaltura objects for session initiation $config = simplekaltura_create_config(); $client = new KalturaClient($config); $partner = $client->partner->getSecrets($config->partnerId, elgg_get_plugin_setting('kaltura_email_account', 'simplekaltura'), elgg_get_plugin_setting('kaltura_password_account', 'simplekaltura')); if ($admin) { $st = KalturaSessionType::ADMIN; $secret = $partner->adminSecret; } else { $st = KalturaSessionType::USER; $secret = $partner->secret; } $ks = $client->session->start($secret, $partner_user_id, $st); // Set KS $client->setKs($ks); return $client; }
private function createKs(KalturaClient $client, KalturaScheduledTaskJobData $jobData) { $partnerId = self::$taskConfig->getPartnerId(); $sessionType = KalturaSessionType::ADMIN; $puserId = 'batchUser'; $adminSecret = self::$taskConfig->getSecret(); $privileges = array('disableentitlement'); if ($jobData->referenceTime) { $privileges[] = 'reftime:' . $jobData->referenceTime; } return $client->generateSession($adminSecret, $puserId, $sessionType, $partnerId, 86400, implode(',', $privileges)); }
protected function init($args) { parent::init($args); if (!isset($args['PartnerID'])) { throw new KurogoConfigurationException('Kaltura PartnerID not included'); } $this->token = $args['token']; if (!isset($args['PartnerSecret'])) { throw new KurogoConfigurationException('Kaltura PartnerSecret not included'); } define("KALTURA_PARTNER_ID", PartnerID); define("KALTURA_PARTNER_ADMIN_SECRET", PartnerSecret); //define session variables $this->partnerUserID = 'ANONYMOUS'; //construct Kaltura objects for session initiation $config = new KalturaConfiguration(KALTURA_PARTNER_ID); $client = new KalturaClient($config); $ks = $client->session->start(KALTURA_PARTNER_ADMIN_SECRET, $this->partnerUserID, KalturaSessionType::ADMIN); $client->setKs($ks); $this->setBaseURL("http://www.kaltura.com/api_v3"); }
/** * @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()); }
/** * * Checks if the job was aborted (throws exception if so) * @throws KalturaBulkUploadAbortedException */ protected function checkAborted() { if ($this->kClient->isMultiRequest()) { return false; } $batchJobResponse = $this->kClient->jobs->getBulkUploadStatus($this->job->id); $updatedJob = $batchJobResponse->batchJob; if ($updatedJob->abort) { KalturaLog::info("job[{$this->job->id}] aborted"); //Throw exception and close the job from the outside throw new KalturaBulkUploadAbortedException("Job was aborted", KalturaBulkUploadAbortedException::JOB_ABORTED); } return false; }
public function doRecalculate(KalturaRecalculateResponseProfileCacheJobData $data) { $job = KJobHandlerWorker::getCurrentJob(); KBatchBase::impersonate($job->partnerId); $partner = KBatchBase::$kClient->partner->get($job->partnerId); KBatchBase::unimpersonate(); $role = reset($data->userRoles); /* @var $role KalturaIntegerValue */ $privileges = array('setrole:' . $role->value, 'disableentitlement'); $privileges = implode(',', $privileges); $client = new KalturaClient(KBatchBase::$kClientConfig); $ks = $client->generateSession($partner->adminSecret, 'batchUser', $data->ksType, $job->partnerId, 86400, $privileges); $client->setKs($ks); $options = new KalturaResponseProfileCacheRecalculateOptions(); $options->limit = $this->maxCacheObjectsPerRequest; $options->cachedObjectType = $data->cachedObjectType; $options->objectId = $data->objectId; $options->startObjectKey = $data->startObjectKey; $options->endObjectKey = $data->endObjectKey; $options->jobCreatedAt = $job->createdAt; $options->isFirstLoop = true; $recalculated = 0; try { do { $results = $client->responseProfile->recalculate($options); $recalculated += $results->recalculated; $options->startObjectKey = $results->lastObjectKey; $options->isFirstLoop = false; } while ($results->lastObjectKey); } catch (KalturaException $e) { if ($e->getCode() != self::RESPONSE_PROFILE_CACHE_ALREADY_RECALCULATED && $e->getCode() != self::RESPONSE_PROFILE_CACHE_RECALCULATE_RESTARTED) { throw $e; } KalturaLog::err($e); } return $recalculated; }
/** * Takes in a : * $wid, string, The widget id * $playlistId, string, The playlist_id */ function getKalturaPlaylist($partnerId, $playlistId) { $config = new KalturaConfiguration($partnerId); $config->serviceUrl = 'http://www.kaltura.com/'; $client = new KalturaClient($config); $client->startMultiRequest(); // the session: $kparams = array(); $client->addParam($kparams, 'widgetId', '_' . $partnerId); $client->queueServiceActionCall('session', 'startWidgetSession', $kparams); // The playlist meta: $kparams = array(); $client->addParam($kparams, 'ks', '{1:result:ks}'); $client->addParam($kparams, 'id', $playlistId); $client->queueServiceActionCall('playlist', 'get', $kparams); // The playlist entries: $client->queueServiceActionCall('playlist', 'execute', $kparams); $rawResultObject = $client->doQueue(); return array('meta' => (array) $rawResultObject[1], 'playlist' => (array) $rawResultObject[2]); }
function getClient() { // Get kaltura configuration file require_once realpath(dirname(__FILE__)) . '/../../infra/kConf.php'; $kConf = new kConf(); // Load kaltura client require_once realpath(dirname(__FILE__)) . '/../../clients/php5/KalturaClient.php'; try { $conf = new KalturaConfiguration(null); $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? "https://" : "http://"; $port = null; if (is_null(parse_url($kConf->get('www_host'), PHP_URL_PORT))) { $port = isset($_SERVER["SERVER_PORT"]) ? $_SERVER["SERVER_PORT"] : 80; } $conf->serviceUrl = $protocol . $kConf->get('www_host') . ($port ? ':' . $port : ""); $client = new KalturaClient($conf); $client->setKS($this->Ks); } catch (Exception $e) { $this->error = 'Error setting KS. <a href="' . $_SERVER['SCRIPT_NAME'] . '">Try again</a>'; die($this->error); return false; } return $client; }
/** * * @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; }
/** * Will take a single KalturaBatchJob and export the given file * * @param KalturaBatchJob $job * @param KalturaStorageExportJobData $data * @return KalturaBatchJob */ protected function export(KalturaBatchJob $job, KalturaStorageExportJobData $data) { KalturaLog::debug("export({$job->id})"); $srcFile = str_replace('//', '/', trim($data->srcFileSyncLocalPath)); $this->updateJob($job, "Syncing {$srcFile}, id: {$data->srcFileSyncId}", KalturaBatchJobStatus::QUEUED, 1); $remoteClientConfig = clone $this->kClient->getConfig(); $remoteClientConfig->serviceUrl = $data->serverUrl; $remoteClientConfig->curlTimeout = $this->taskConfig->maximumExecutionTime; $remoteClient = new KalturaClient($remoteClientConfig); $remoteClient->setKs($this->kClient->getKs()); try { $fileSync = $remoteClient->fileSync->sync($data->srcFileSyncId, realpath($srcFile)); if ($fileSync->status == KalturaFileSyncStatus::READY) { return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED); } return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, 0, 'File sync not ready', KalturaBatchJobStatus::RETRY); } catch (KalturaException $kex) { return $this->closeJob($job, KalturaBatchJobErrorTypes::KALTURA_API, $kex->getCode(), "Error: " . $kex->getMessage(), KalturaBatchJobStatus::RETRY); } catch (KalturaClientException $kcex) { return $this->closeJob($job, KalturaBatchJobErrorTypes::KALTURA_CLIENT, $kcex->getCode(), "Error: " . $kcex->getMessage(), KalturaBatchJobStatus::RETRY); } catch (Exception $e) { return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $e->getCode(), $e->getMessage(), KalturaBatchJobStatus::FAILED); } }
/** * @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()); }
/** * 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); }
/** * Starts a new session * @param KalturaSessionType $type * @param string $userId */ protected function startSessionWithDiffe($type, $userId, $privileges = null) { $testConfig = $this->config->get('config'); $secret = $testConfig->secret; if ($type == SessionType::ADMIN) { $secret = $testConfig->userSecret; } if (is_null($privileges)) { $privileges = $testConfig->privilege; } $ks = $this->client->generateSession($secret, $userId, $type, $testConfig->partnerId, $testConfig->expiry, $privileges); KalturaLog::debug('Generate session for ks with privileges: ' . print_r($privileges, true) . ' ks: ' . $ks); if (!$ks) { return false; } $this->client->setKs($ks); KalturaLog::info("Session started [{$ks}]"); return true; }