/** * Allows you to clone exiting event notification template object and create a new one with similar configuration * * @action clone * @param int $id source template to clone * @param KalturaEventNotificationTemplate $eventNotificationTemplate overwrite configuration object * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_WRONG_TYPE * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_DUPLICATE_SYSTEM_NAME * @return KalturaEventNotificationTemplate */ public function cloneAction($id, KalturaEventNotificationTemplate $eventNotificationTemplate = null) { // get the source object $dbEventNotificationTemplate = EventNotificationTemplatePeer::retrieveByPK($id); if (!$dbEventNotificationTemplate) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND, $id); } // copy into new db object $newDbEventNotificationTemplate = $dbEventNotificationTemplate->copy(); // init new Kaltura object $newEventNotificationTemplate = KalturaEventNotificationTemplate::getInstanceByType($newDbEventNotificationTemplate->getType()); $templateClass = get_class($newEventNotificationTemplate); if (get_class($eventNotificationTemplate) != $templateClass && !is_subclass_of($eventNotificationTemplate, $templateClass)) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_WRONG_TYPE, $id, kPluginableEnumsManager::coreToApi('EventNotificationTemplateType', $dbEventNotificationTemplate->getType())); } if ($eventNotificationTemplate) { // update new db object with the overwrite configuration $newDbEventNotificationTemplate = $eventNotificationTemplate->toUpdatableObject($newDbEventNotificationTemplate); } //Check uniqueness of new object's system name $systemNameTemplates = EventNotificationTemplatePeer::retrieveBySystemName($newDbEventNotificationTemplate->getSystemName()); if (count($systemNameTemplates)) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_DUPLICATE_SYSTEM_NAME, $newDbEventNotificationTemplate->getSystemName()); } // save the new db object $newDbEventNotificationTemplate->setPartnerId($this->getPartnerId()); $newDbEventNotificationTemplate->save(); // return the saved object $newEventNotificationTemplate = KalturaEventNotificationTemplate::getInstanceByType($newDbEventNotificationTemplate->getType()); $newEventNotificationTemplate->fromObject($newDbEventNotificationTemplate); return $newEventNotificationTemplate; }
/** * Register to a queue from which event messages will be provided according to given template. Queue will be created if not already exists * * @action register * @actionAlias eventNotification_eventNotificationTemplate.register * @param string $notificationTemplateSystemName Existing push notification template system name * @param KalturaEventNotificationParameterArray $userParamsArray User params * @return KalturaPushNotificationData */ function registerAction($notificationTemplateSystemName, $userParamsArray) { // find the template, according to its system name, on both current partner and partner 0 $partnerId = $this->getPartnerId(); $partnersIds = array(PartnerPeer::GLOBAL_PARTNER, $partnerId); $dbEventNotificationTemplate = EventNotificationTemplatePeer::retrieveBySystemName($notificationTemplateSystemName, null, $partnersIds); if (!$dbEventNotificationTemplate) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_SYSTEM_NAME_NOT_FOUND, $notificationTemplateSystemName); } // verify template is push typed if (!$dbEventNotificationTemplate instanceof PushNotificationTemplate) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_WRONG_TYPE, $notificationTemplateSystemName, get_class($dbEventNotificationTemplate)); } // Check all template needed params were actually given $missingParams = array(); $templateParams = $dbEventNotificationTemplate->getContentParameters(); // create array of all keys $userParamsArrayKeys = array(); foreach ($userParamsArray as $userParam) { array_push($userParamsArrayKeys, $userParam->toObject()->getKey()); } foreach ($templateParams as $templateParam) { if (!in_array($templateParam->getKey(), $userParamsArrayKeys)) { array_push($missingParams, $templateParam->getKey()); } } if ($missingParams != null) { throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER, implode(",", $missingParams)); } //check that keys actually have values foreach ($userParamsArray as $userParam) { $userParamObj = $userParam->toObject(); if (!$userParamObj->getValue()) { KalturaLog::debug(print_r($userParamObj, true)); throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER, "Value of " . $userParamObj->getKey()); } } $queueKey = $dbEventNotificationTemplate->getQueueKey($userParamsArray->toObjectsArray(), $partnerId, null); $hash = kCurrentContext::$ks_object->getHash(); // create queue if not exists if (!$dbEventNotificationTemplate->exists($queueKey)) { $dbEventNotificationTemplate->create($queueKey); } $result = new KalturaPushNotificationData(); $result->key = $this->encode($queueKey . ":" . $hash); // build the url to return $protocol = infraRequestUtils::getProtocol(); $host = kConf::get("push_server_host"); $secret = kConf::get("push_server_secret"); $ip = kCurrentContext::$user_ip; $token = base64_encode($partnerId . ":" . $this->encode($secret . ":" . $ip . ":" . $hash . ":" . uniqid())); $result->url = $protocol . "://" . $host . "/?p=" . $partnerId . "&x=" . urlencode($token); return $result; }
/** * Update event notification template status by id * * @action updateStatus * @param int $id * @param KalturaEventNotificationTemplateStatus $status * @return KalturaEventNotificationTemplate * * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND */ function updateStatusAction($id, $status) { // get the object $dbEventNotificationTemplate = EventNotificationTemplatePeer::retrieveByPK($id); if (!$dbEventNotificationTemplate) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND, $id); } if ($status == EventNotificationTemplateStatus::ACTIVE) { //Check uniqueness of new object's system name $systemNameTemplates = EventNotificationTemplatePeer::retrieveBySystemName($dbEventNotificationTemplate->getSystemName()); if (count($systemNameTemplates)) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_DUPLICATE_SYSTEM_NAME, $dbEventNotificationTemplate->getSystemName()); } } // save the object $dbEventNotificationTemplate->setStatus($status); $dbEventNotificationTemplate->save(); // return the saved object $eventNotificationTemplate = KalturaEventNotificationTemplate::getInstanceByType($dbEventNotificationTemplate->getType()); $eventNotificationTemplate->fromObject($dbEventNotificationTemplate, $this->getResponseProfile()); return $eventNotificationTemplate; }
protected function validate(EventNotificationTemplate $sourceObject = null) { $this->validatePropertyMinLength('systemName', 3, true); $id = null; if ($sourceObject) { $id = $sourceObject->getId(); } if (trim($this->systemName) && !$this->isNull('systemName')) { $systemNameTemplates = EventNotificationTemplatePeer::retrieveBySystemName($this->systemName, $id); if (count($systemNameTemplates)) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_DUPLICATE_SYSTEM_NAME, $this->systemName); } } }