Example #1
0
 protected function processKs($ksStr, $requiredPermission = null)
 {
     try {
         kCurrentContext::initKsPartnerUser($ksStr);
     } catch (Exception $ex) {
         KalturaLog::err($ex);
         return false;
     }
     if (kCurrentContext::$ks_object->type != ks::SESSION_TYPE_ADMIN) {
         KalturaLog::err('Ks is not admin');
         return false;
     }
     try {
         kPermissionManager::init(kConf::get('enable_cache'));
     } catch (Exception $ex) {
         if (strpos($ex->getCode(), 'INVALID_ACTIONS_LIMIT') === false) {
             KalturaLog::err($ex);
             return false;
         }
     }
     if ($requiredPermission) {
         if (!kPermissionManager::isPermitted(PermissionName::ADMIN_PUBLISHER_MANAGE)) {
             KalturaLog::err('Ks is missing "ADMIN_PUBLISHER_MANAGE" permission');
             return false;
         }
     }
     return true;
 }
 private static function getObjectTypeCacheKey(IRelatedObject $object)
 {
     $userRoles = kPermissionManager::getCurrentRoleIds();
     sort($userRoles);
     $objectType = get_class($object);
     $partnerId = self::$cachedObject->getPartnerId();
     $profileKey = self::$responseProfileKey;
     $protocol = infraRequestUtils::getProtocol();
     $ksType = kCurrentContext::getCurrentSessionType();
     $userRoles = implode('-', $userRoles);
     $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
     return "relate_rp{$profileKey}_p{$partnerId}_o{$objectType}_h{$protocol}_k{$ksType}_u{$userRoles}_w{$host}";
 }
Example #3
0
 protected function internalFulfilled(kScope $scope)
 {
     $partner = PartnerPeer::retrieveByPK(kCurrentContext::$ks_partner_id);
     $roleIds = kPermissionManager::getRoleIds($partner, kCurrentContext::getCurrentKsKuser());
     $conditionRoleIds = array_map('trim', explode(',', $this->roleIds));
     if (!is_array($roleIds)) {
         $roleIds = array();
     }
     foreach ($roleIds as $roleId) {
         if (!in_array($roleId, $conditionRoleIds)) {
             return false;
         }
     }
     return true;
 }
Example #4
0
 public function dispatch($service, $action, $params = array())
 {
     KalturaLog::debug("Dispatching service [" . $service . "], action [" . $action . "] with params " . print_r($params, true));
     $start = microtime(true);
     // prevent impersonate to partner zero
     $p = isset($params["p"]) && $params["p"] ? $params["p"] : null;
     if (!$p) {
         $p = isset($params["partnerId"]) && $params["partnerId"] ? $params["partnerId"] : null;
     }
     $GLOBALS["partnerId"] = $p;
     // set for logger
     $userId = "";
     $ksStr = isset($params["ks"]) ? $params["ks"] : null;
     if (!$service) {
         throw new KalturaAPIException(KalturaErrors::SERVICE_NOT_SPECIFIED);
     }
     try {
         // load the service reflector
         $reflector = new KalturaServiceReflector($service);
     } catch (Exception $ex) {
         throw new KalturaAPIException(KalturaErrors::SERVICE_DOES_NOT_EXISTS, $service);
     }
     // check if action exists
     if (!$action) {
         throw new KalturaAPIException(KalturaErrors::ACTION_NOT_SPECIFIED, $service);
     }
     if (!$reflector->isActionExists($action)) {
         throw new KalturaAPIException(KalturaErrors::ACTION_DOES_NOT_EXISTS, $action, $service);
     }
     $actionParams = $reflector->getActionParams($action);
     // services.ct - check if partner is allowed to access service ...
     // validate it's ok to access this service
     $deserializer = new KalturaRequestDeserializer($params);
     $arguments = $deserializer->buildActionArguments($actionParams);
     $serviceInstance = $reflector->getServiceInstance();
     kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : null;
     kCurrentContext::$user_ip = requestUtils::getRemoteAddress();
     kCurrentContext::$ps_vesion = "ps3";
     kCurrentContext::$service = $reflector->getServiceName();
     kCurrentContext::$action = $action;
     kCurrentContext::$client_lang = isset($params['clientTag']) ? $params['clientTag'] : null;
     kCurrentContext::initKsPartnerUser($ksStr, $p, $userId);
     kPermissionManager::init(kConf::get('enable_cache'));
     // initialize the service before invoking the action on it
     $serviceInstance->initService($reflector->getServiceId(), $reflector->getServiceName(), $action);
     $invokeStart = microtime(true);
     KalturaLog::debug("Invoke start");
     $res = $reflector->invoke($action, $arguments);
     KalturaLog::debug("Invoke took - " . (microtime(true) - $invokeStart) . " seconds");
     KalturaLog::debug("Disptach took - " . (microtime(true) - $start) . " seconds");
     $this->clearMemory();
     return $res;
 }
 protected static function getSessionKey($protocol = null, $ksType = null, array $userRoles = null, $host = null)
 {
     if (!$protocol) {
         $protocol = infraRequestUtils::getProtocol();
     }
     if (!$ksType) {
         $ksType = kCurrentContext::getCurrentSessionType();
     }
     if (!$userRoles) {
         $userRoles = kPermissionManager::getCurrentRoleIds();
     }
     if (!$host) {
         $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
     }
     sort($userRoles);
     $userRole = implode('-', $userRoles);
     return "{$protocol}_{$ksType}_{$host}_{$userRole}";
 }
Example #6
0
 /**
  * Check if current action is permitted for current context (ks/partner/user)
  * @param bool $allowPrivatePartnerData true if access to private partner data is allowed, false otherwise (kaltura network)
  * @throws APIErrors::MISSING_KS
  */
 protected function isPermitted(&$allowPrivatePartnerData)
 {
     // if no partner defined but required -> error MISSING_KS
     if (!$this->partner && $this->partnerRequired($this->actionName)) {
         throw new KalturaAPIException(APIErrors::MISSING_KS);
     }
     // check if actions is permitted for current context
     $isActionPermitted = kPermissionManager::isActionPermitted($this->serviceId, $this->actionName);
     // if action permitted - no problem to access action and the private partner data
     if ($isActionPermitted) {
         $allowPrivatePartnerData = true;
         // allow private partner data
         return true;
         // action permitted with access to partner private data
     }
     // action not permitted for current user - check if kaltura network is allowed
     if (!kCurrentContext::$ks && $this->kalturaNetworkAllowed($this->actionName)) {
         // if the service action support kaltura network - continue without private data
         $allowPrivatePartnerData = false;
         // DO NOT allow private partner data
         return true;
         // action permitted (without private partner data)
     }
     // action not permitted, not even without private partner data access
     return false;
 }
Example #7
0
 public function dispatch($service, $action, $params = array())
 {
     $start = microtime(true);
     // prevent impersonate to partner zero
     $p = isset($params["p"]) && $params["p"] ? $params["p"] : null;
     if (!$p) {
         $p = isset($params["partnerId"]) && $params["partnerId"] ? $params["partnerId"] : null;
     }
     $GLOBALS["partnerId"] = $p;
     // set for logger
     $userId = "";
     $ksStr = isset($params["ks"]) ? $params["ks"] : null;
     if (!$service) {
         throw new KalturaAPIException(KalturaErrors::SERVICE_NOT_SPECIFIED);
     }
     //strtolower on service - map is indexed according to lower-case service IDs
     $service = strtolower($service);
     $serviceActionItem = KalturaServicesMap::retrieveServiceActionItem($service, $action);
     $action = strtolower($action);
     if (!isset($serviceActionItem->actionMap[$action])) {
         KalturaLog::crit("Action does not exist!");
         throw new KalturaAPIException(KalturaErrors::ACTION_DOES_NOT_EXISTS, $action, $service);
     }
     try {
         $actionReflector = new KalturaActionReflector($service, $action, $serviceActionItem->actionMap[$action]);
     } catch (Exception $e) {
         throw new Exception("Could not create action reflector for service [{$service}], action [{$action}]. Received error: " . $e->getMessage());
     }
     $actionParams = $actionReflector->getActionParams();
     $actionInfo = $actionReflector->getActionInfo();
     // services.ct - check if partner is allowed to access service ...
     kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : gethostname();
     kCurrentContext::$user_ip = requestUtils::getRemoteAddress();
     kCurrentContext::$ps_vesion = "ps3";
     kCurrentContext::$service = $serviceActionItem->serviceInfo->serviceName;
     kCurrentContext::$action = $action;
     kCurrentContext::$client_lang = isset($params['clientTag']) ? $params['clientTag'] : null;
     kCurrentContext::initKsPartnerUser($ksStr, $p, $userId);
     // validate it's ok to access this service
     $deserializer = new KalturaRequestDeserializer($params);
     $this->arguments = $deserializer->buildActionArguments($actionParams);
     KalturaLog::debug("Dispatching service [" . $service . "], action [" . $action . "], reqIndex [" . kCurrentContext::$multiRequest_index . "] with params " . print_r($this->arguments, true));
     $responseProfile = $deserializer->getResponseProfile();
     if ($responseProfile) {
         KalturaLog::debug("Response profile: " . print_r($responseProfile, true));
     }
     kPermissionManager::init(kConf::get('enable_cache'));
     kEntitlementUtils::initEntitlementEnforcement();
     $disableTags = $actionInfo->disableTags;
     if ($disableTags && is_array($disableTags) && count($disableTags)) {
         foreach ($disableTags as $disableTag) {
             KalturaCriterion::disableTag($disableTag);
         }
     }
     if ($actionInfo->validateUserObjectClass && $actionInfo->validateUserIdParamName && isset($actionParams[$actionInfo->validateUserIdParamName])) {
         //			// TODO maybe if missing should throw something, maybe a bone?
         //			if(!isset($actionParams[$actionInfo->validateUserIdParamName]))
         //				throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER, $actionInfo->validateUserIdParamName);
         KalturaLog::debug("validateUserIdParamName: " . $actionInfo->validateUserIdParamName);
         $objectId = $params[$actionInfo->validateUserIdParamName];
         $this->validateUser($actionInfo->validateUserObjectClass, $objectId, $actionInfo->validateUserPrivilege, $actionInfo->validateOptions);
     }
     // initialize the service before invoking the action on it
     // action reflector will init the service to maintain the pluginable action transparency
     $actionReflector->initService($responseProfile);
     $invokeStart = microtime(true);
     KalturaLog::debug("Invoke start");
     try {
         $res = $actionReflector->invoke($this->arguments);
     } catch (KalturaAPIException $e) {
         if ($actionInfo->returnType != 'file') {
             throw $e;
         }
         KalturaResponseCacher::adjustApiCacheForException($e);
         $res = new kRendererDieError($e->getCode(), $e->getMessage());
     }
     kEventsManager::flushEvents();
     KalturaLog::debug("Invoke took - " . (microtime(true) - $invokeStart) . " seconds");
     KalturaLog::debug("Dispatch took - " . (microtime(true) - $start) . " seconds, memory: " . memory_get_peak_usage(true));
     return $res;
 }
 /**
  * Retrieves a list of permissions that apply to the current KS.
  * 
  * @action getCurrentPermissions
  * 
  * @return string A comma-separated list of current permission names
  * 
  */
 public function getCurrentPermissions()
 {
     $permissions = kPermissionManager::getCurrentPermissions();
     $permissions = implode(',', $permissions);
     return $permissions;
 }
Example #9
0
 public function validateForUsage($sourceObject, $propertiesToSkip = array())
 {
     $useableProperties = array();
     $reflector = KalturaTypeReflectorCacher::get(get_class($this));
     if (!$reflector) {
         KalturaLog::err("Unable to validate usage for attribute object type [" . get_class($this) . "], type reflector not found");
         throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_USAGE_PERMISSION, get_class($this));
     }
     $properties = $reflector->getProperties();
     if ($reflector->requiresUsagePermission() && !kPermissionManager::getUsagePermitted(get_class($this), kApiParameterPermissionItem::ALL_VALUES_IDENTIFIER)) {
         throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_USAGE_PERMISSION, get_class($this));
     }
     foreach ($properties as $property) {
         /* @var $property KalturaPropertyInfo */
         $propertyName = $property->getName();
         if ($propertiesToSkip && is_array($propertiesToSkip) && in_array($propertyName, $propertiesToSkip)) {
             continue;
         }
         if ($this->{$propertyName} !== null) {
             // check if property value is being changed - if not, just continue to the next
             $objectPropertyName = $this->getObjectPropertyName($propertyName);
             $getter_callback = array($sourceObject, "get{$objectPropertyName}");
             if (is_callable($getter_callback)) {
                 $value = call_user_func($getter_callback);
                 if ($value === $this->{$propertyName} || is_bool($this->{$propertyName}) && $value === (int) $this->{$propertyName}) {
                     continue;
                 }
             }
             // property requires update permissions, verify that the current user has it
             if ($property->requiresUsagePermission()) {
                 if (!kPermissionManager::getUsagePermitted($this->getDeclaringClassName($propertyName), $propertyName)) {
                     //throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     //TODO: not throwing exception to not break clients that sends -1 as null for integer values (etc...)
                     $e = new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_USAGE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     $this->{$propertyName} = null;
                     KalturaLog::err($this->getDeclaringClassName($propertyName) . '-' . $propertyName . ' error: ' . $e->getMessage());
                     header($this->getDeclaringClassName($propertyName) . '-' . $propertyName . ' error: ' . $e->getMessage());
                 }
             }
         }
     }
     return $useableProperties;
 }
 /**
  * Retrieve partner secret and admin secret
  * 
  * @action getSecrets
  * @param int $partnerId
  * @param string $adminEmail
  * @param string $cmsPassword
  * @return KalturaPartner
  * 
  *
  * @throws APIErrors::ADMIN_KUSER_NOT_FOUND
  */
 public function getSecretsAction($partnerId, $adminEmail, $cmsPassword)
 {
     KalturaResponseCacher::disableCache();
     $adminKuser = null;
     try {
         $adminKuser = UserLoginDataPeer::userLoginByEmail($adminEmail, $cmsPassword, $partnerId);
     } catch (kUserException $e) {
         throw new KalturaAPIException(APIErrors::ADMIN_KUSER_NOT_FOUND, "The data you entered is invalid");
     }
     if (!$adminKuser || !$adminKuser->getIsAdmin()) {
         throw new KalturaAPIException(APIErrors::ADMIN_KUSER_NOT_FOUND, "The data you entered is invalid");
     }
     KalturaLog::log("Admin Kuser found, going to validate password", KalturaLog::INFO);
     // user logged in - need to re-init kPermissionManager in order to determine current user's permissions
     $ks = null;
     kSessionUtils::createKSessionNoValidations($partnerId, $adminKuser->getPuserId(), $ks, 86400, $adminKuser->getIsAdmin(), "", '*');
     kCurrentContext::initKsPartnerUser($ks);
     kPermissionManager::init();
     $dbPartner = PartnerPeer::retrieveByPK($partnerId);
     $partner = new KalturaPartner();
     $partner->fromPartner($dbPartner);
     $partner->cmsPassword = $cmsPassword;
     return $partner;
 }
 public function __construct($feedId, $feedProcessingKey = null, $ks = null)
 {
     $this->feedProcessingKey = $feedProcessingKey;
     myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3;
     $microTimeStart = microtime(true);
     KalturaLog::info("syndicationFeedRenderer- initialize ");
     $this->syndicationFeedDb = $syndicationFeedDB = syndicationFeedPeer::retrieveByPK($feedId);
     if (!$syndicationFeedDB) {
         throw new Exception("Feed Id not found");
     }
     kCurrentContext::initKsPartnerUser($ks, $syndicationFeedDB->getPartnerId(), '');
     kPermissionManager::init();
     kEntitlementUtils::initEntitlementEnforcement($syndicationFeedDB->getPartnerId(), $syndicationFeedDB->getEnforceEntitlement());
     if (!is_null($syndicationFeedDB->getPrivacyContext()) && $syndicationFeedDB->getPrivacyContext() != '') {
         kEntitlementUtils::setPrivacyContextSearch($syndicationFeedDB->getPrivacyContext());
     }
     $tmpSyndicationFeed = KalturaSyndicationFeedFactory::getInstanceByType($syndicationFeedDB->getType());
     $tmpSyndicationFeed->fromObject($syndicationFeedDB);
     $this->syndicationFeed = $tmpSyndicationFeed;
     // add partner to default criteria
     myPartnerUtils::addPartnerToCriteria('category', $this->syndicationFeed->partnerId, true);
     myPartnerUtils::addPartnerToCriteria('asset', $this->syndicationFeed->partnerId, true);
     myPartnerUtils::resetPartnerFilter('entry');
     $this->baseCriteria = clone entryPeer::getDefaultCriteriaFilter();
     $startDateCriterion = $this->baseCriteria->getNewCriterion(entryPeer::START_DATE, time(), Criteria::LESS_EQUAL);
     $startDateCriterion->addOr($this->baseCriteria->getNewCriterion(entryPeer::START_DATE, null));
     $this->baseCriteria->addAnd($startDateCriterion);
     $endDateCriterion = $this->baseCriteria->getNewCriterion(entryPeer::END_DATE, time(), Criteria::GREATER_EQUAL);
     $endDateCriterion->addOr($this->baseCriteria->getNewCriterion(entryPeer::END_DATE, null));
     $this->baseCriteria->addAnd($endDateCriterion);
     $this->baseCriteria->addAnd(entryPeer::PARTNER_ID, $this->syndicationFeed->partnerId);
     $this->baseCriteria->addAnd(entryPeer::STATUS, entryStatus::READY);
     $this->baseCriteria->addAnd(entryPeer::TYPE, array(entryType::MEDIA_CLIP, entryType::MIX), Criteria::IN);
     $this->baseCriteria->addAnd(entryPeer::MODERATION_STATUS, array(entry::ENTRY_MODERATION_STATUS_REJECTED, entry::ENTRY_MODERATION_STATUS_PENDING_MODERATION), Criteria::NOT_IN);
     if ($this->syndicationFeed->playlistId) {
         $this->entryFilters = myPlaylistUtils::getPlaylistFiltersById($this->syndicationFeed->playlistId);
         foreach ($this->entryFilters as $entryFilter) {
             $entryFilter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE);
             // partner scope already attached
         }
         $playlist = entryPeer::retrieveByPK($this->syndicationFeed->playlistId);
         if ($playlist) {
             if ($playlist->getMediaType() != entry::ENTRY_MEDIA_TYPE_XML) {
                 $this->staticPlaylist = true;
                 $this->staticPlaylistEntriesIdsOrder = explode(',', $playlist->getDataContent());
             }
         }
     } else {
         $this->entryFilters = array();
     }
     $microTimeEnd = microtime(true);
     KalturaLog::info("syndicationFeedRenderer- initialization done [" . ($microTimeEnd - $microTimeStart) . "]");
 }
Example #12
0
 private static function initPermissionsMap()
 {
     // init an empty map
     self::$map = self::initEmptyMap();
     if (!self::$roleIds) {
         self::$map = self::getPermissions(null);
     } else {
         foreach (self::$roleIds as $roleId) {
             // init actions and parameters arrays from cache
             $roleMap = self::getPermissions($roleId);
             // merge current role map to the global map
             self::$map = array_merge_recursive(self::$map, $roleMap);
         }
     }
 }
Example #13
0
 /**
  * Retrieves a user object for a user's login ID and partner ID.
  * A login ID is the email address used by a user to log into the system.
  * 
  * @action getByLoginId
  * @param string $loginId The user's email address that identifies the user for login
  * @return KalturaUser The user object represented by the login and partner IDs
  * 
  * @throws KalturaErrors::LOGIN_DATA_NOT_FOUND
  * @throws KalturaErrors::USER_NOT_FOUND
  */
 public function getByLoginIdAction($loginId)
 {
     $loginData = UserLoginDataPeer::getByEmail($loginId);
     if (!$loginData) {
         throw new KalturaAPIException(KalturaErrors::LOGIN_DATA_NOT_FOUND);
     }
     $kuser = kuserPeer::getByLoginDataAndPartner($loginData->getId(), $this->getPartnerId());
     if (!$kuser) {
         throw new KalturaAPIException(KalturaErrors::USER_NOT_FOUND);
     }
     // users that are not publisher administrator are only allowed to get their own object
     if ($kuser->getId() != kCurrentContext::getCurrentKsKuserId() && !in_array(PermissionName::MANAGE_ADMIN_USERS, kPermissionManager::getCurrentPermissions())) {
         throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID, $loginId);
     }
     $user = new KalturaUser();
     $user->fromObject($kuser, $this->getResponseProfile());
     return $user;
 }
Example #14
0
 /**
  * Delete an existing UIConf with no partner limitation
  * 
  * @action delete
  * @param int $id
  *
  * @throws APIErrors::INVALID_UI_CONF_ID
  */
 function deleteAction($id)
 {
     $dbUiConf = uiConfPeer::retrieveByPK($id);
     if (!$dbUiConf) {
         throw new KalturaAPIException(APIErrors::INVALID_UI_CONF_ID, $id);
     }
     if ($dbUiConf->getPartnerId() == PartnerPeer::GLOBAL_PARTNER && !kPermissionManager::isPermitted(self::PERMISSION_GLOBAL_PARTNER_UI_CONF_UPDTAE)) {
         throw new KalturaAPIException(APIErrors::INVALID_UI_CONF_ID, $id);
     }
     $dbUiConf->setStatus(uiConf::UI_CONF_STATUS_DELETED);
     $dbUiConf->save();
 }
 /**
  * Function creates new partner, saves all the required data to it, and copies objects & filesyncs of template content to its ID.
  * @param string $partner_name
  * @param string $contact
  * @param string $email
  * @param CommercialUseType $ID_is_for
  * @param string $SDK_terms_agreement
  * @param string $description
  * @param string $website_url
  * @param string $password
  * @param Partner $partner
  * @param int $templatePartnerId
  * @return Partner
  */
 private function createNewPartner($partner_name, $contact, $email, $ID_is_for, $SDK_terms_agreement, $description, $website_url, $password = null, $newPartner = null, $templatePartnerId = null)
 {
     $secret = md5($this->str_makerand(5, 10, true, false, true));
     $admin_secret = md5($this->str_makerand(5, 10, true, false, true));
     if (!$newPartner) {
         $newPartner = new Partner();
     }
     if ($partner_name) {
         $newPartner->setPartnerName($partner_name);
     }
     $newPartner->setAdminSecret($admin_secret);
     $newPartner->setSecret($secret);
     $newPartner->setAdminName($contact);
     $newPartner->setAdminEmail($email);
     $newPartner->setUrl1($website_url);
     if ($ID_is_for === "commercial_use" || $ID_is_for === CommercialUseType::COMMERCIAL_USE) {
         $newPartner->setCommercialUse(true);
     } else {
         //($ID_is_for == "non-commercial_use") || $ID_is_for === CommercialUseType::NON_COMMERCIAL_USE)
         $newPartner->setCommercialUse(false);
     }
     $newPartner->setDescription($description);
     $newPartner->setKsMaxExpiryInSeconds(86400);
     $newPartner->setModerateContent(false);
     $newPartner->setNotify(false);
     $newPartner->setAppearInSearch(mySearchUtils::DISPLAY_IN_SEARCH_PARTNER_ONLY);
     $newPartner->setIsFirstLogin(true);
     /* fix drupal5 module partner type */
     //var_dump($description);
     if ($this->partnerParentId) {
         // this is a child partner of some VAR/partner GROUP
         $newPartner->setPartnerParentId($this->partnerParentId);
         $newPartner->setMonitorUsage(PartnerFreeTrialType::NO_LIMIT);
         $parentPartner = PartnerPeer::retrieveByPK($this->partnerParentId);
         $newPartner->setPartnerPackage($parentPartner->getPartnerPackage());
     }
     if (substr_count($description, 'Drupal module|')) {
         $newPartner->setType(102);
     }
     $newPartner->save();
     // if name was left empty - which should not happen - use id as name
     if (!$partner_name) {
         $partner_name = $newPartner->getId();
     }
     $newPartner->setPartnerName($partner_name);
     $newPartner->setPrefix($newPartner->getId());
     $newPartner->setPartnerAlias(md5($newPartner->getId() . 'kaltura partner'));
     // set default conversion profile for trial accounts
     if ($newPartner->getType() == Partner::PARTNER_TYPE_KMC) {
         $newPartner->setDefConversionProfileType(ConversionProfile::DEFAULT_TRIAL_COVERSION_PROFILE_TYPE);
     }
     $newPartner->save();
     // remove the default criteria from all peers and recreate it with the right partner id
     myPartnerUtils::resetAllFilters();
     myPartnerUtils::applyPartnerFilters($newPartner->getId(), true);
     $partner_id = $newPartner->getId();
     widget::createDefaultWidgetForPartner($partner_id, $this->createNewSubPartner($newPartner));
     $fromPartner = PartnerPeer::retrieveByPK($templatePartnerId ? $templatePartnerId : kConf::get("template_partner_id"));
     if (!$fromPartner) {
         KalturaLog::log("Template content partner was not found!");
     } else {
         $newPartner->setI18nTemplatePartnerId($templatePartnerId);
         myPartnerUtils::copyTemplateContent($fromPartner, $newPartner, true);
     }
     if ($newPartner->getType() == Partner::PARTNER_TYPE_WORDPRESS) {
         kPermissionManager::setPs2Permission($newPartner);
     }
     $newPartner->setKmcVersion(kConf::get('new_partner_kmc_version'));
     $newPartner->save();
     return $newPartner;
 }
Example #16
0
 public function validateForUpdate($source_object)
 {
     $updatableProperties = array();
     $reflector = KalturaTypeReflectorCacher::get(get_class($this));
     $properties = $reflector->getProperties();
     if ($reflector->requiresUpdatePermission() && !kPermissionManager::getUpdatePermitted(get_class($this), kApiParameterPermissionItem::ALL_VALUES_IDENTIFIER)) {
         throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, get_class($this));
     }
     foreach ($properties as $property) {
         $propertyName = $property->getName();
         if ($this->{$propertyName} !== null) {
             // check if property value is being changed - if not, just continue to the next
             $objectPropertyName = $this->getObjectPropertyName($propertyName);
             $getter_callback = array($source_object, "get{$objectPropertyName}");
             if (is_callable($getter_callback)) {
                 $value = call_user_func($getter_callback);
                 if ($value === $this->{$propertyName}) {
                     continue;
                 }
             }
             if ($property->isReadOnly() || $property->isInsertOnly()) {
                 throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NOT_UPDATABLE, $this->getFormattedPropertyNameWithClassName($propertyName));
             }
             // property requires update permissions, verify that the current user has it
             if ($property->requiresUpdatePermission()) {
                 if (!kPermissionManager::getUpdatePermitted($this->getDeclaringClassName($propertyName), $propertyName)) {
                     //throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     //TODO: not throwing exception to not break clients that sends -1 as null for integer values (etc...)
                     $e = new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     $this->{$propertyName} = null;
                     header($this->getDeclaringClassName($propertyName) . '-' . $propertyName . ' error: ' . $e->getMessage());
                 }
             }
         }
     }
     return $updatableProperties;
 }