public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     //No need to add objectId to result with status ERROR
     if ($this->status != KalturaBulkUploadResultStatus::ERROR) {
         $kuser = kuserPeer::getKuserByPartnerAndUid($this->partnerId, $this->userId);
         if (!$kuser) {
             throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
         }
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($this->categoryId, $kuser->getId());
         if ($categoryKuser) {
             $this->objectId = $categoryKuser->getId();
         }
     }
     return parent::toObject($object_to_fill, $props_to_skip);
 }
Ejemplo n.º 2
0
 protected function kuserDelete(kuser $kuser)
 {
     $filter = new categoryKuserFilter();
     $filter->setUserIdEqual($kuser->getPuserId());
     $c = new Criteria();
     $c->add(categoryKuserPeer::PUSER_ID, $kuser->getPuserId());
     if (categoryKuserPeer::doSelectOne($c)) {
         kJobsManager::addDeleteJob($kuser->getPartnerId(), DeleteObjectType::CATEGORY_USER, $filter);
     }
     if ($kuser->getType() == KuserType::USER) {
         // remove user from groups
         KuserKgroupPeer::deleteByKuserId($kuser->getId());
     } elseif ($kuser->getType() == KuserType::GROUP) {
         // remove users from group
         $filter = new KuserKgroupFilter();
         $filter->setGroupIdEqual($kuser->getPuserId());
         $c = new Criteria();
         $c->add(KuserKgroupPeer::PGROUP_ID, $kuser->getPuserId());
         if (KuserKgroupPeer::doSelectOne($c)) {
             kJobsManager::addDeleteJob($kuser->getPartnerId(), DeleteObjectType::GROUP_USER, $filter);
         }
     }
 }
Ejemplo n.º 3
0
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if ($this->userIdIn) {
         $usersIds = explode(',', $this->userIdIn);
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
         $c->add(kuserPeer::PUSER_ID, $usersIds, Criteria::IN);
         $kusers = kuserPeer::doSelect($c);
         $usersIds = array();
         foreach ($kusers as $kuser) {
             /* @var $kuser kuser */
             $usersIds[] = $kuser->getId();
         }
         $this->userIdIn = implode(',', $usersIds);
     }
     if ($this->relatedGroupsByUserId) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $userIds = array();
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId);
         $c->add(kuserPeer::PUSER_ID, $this->relatedGroupsByUserId);
         $c->add(kuserPeer::TYPE, KuserType::USER);
         $kuser = kuserPeer::doSelectOne($c);
         if (!$kuser) {
             $response = new KalturaCategoryUserListResponse();
             $response->objects = new KalturaCategoryUserArray();
             $response->totalCount = 0;
             return $response;
         }
         $kgroupIds = KuserKgroupPeer::retrieveKgroupIdsByKuserId($kuser->getId());
         if (!is_null($kgroupIds) && is_array($kgroupIds)) {
             $userIds = $kgroupIds;
         }
         $userIds[] = $kuser->getId();
         // if userIdIn is also set in the filter need to intersect the two arrays.
         if (isset($this->userIdIn)) {
             $curUserIds = explode(',', $this->userIdIn);
             $userIds = array_intersect($curUserIds, $userIds);
         }
         $this->userIdIn = implode(',', $userIds);
     }
     if ($this->userIdEqual) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId);
         $c->add(kuserPeer::PUSER_ID, $this->userIdEqual);
         if (kCurrentContext::$ks_partner_id == Partner::BATCH_PARTNER_ID) {
             //batch should be able to get categoryUser of deleted users.
             kuserPeer::setUseCriteriaFilter(false);
         }
         // in case of more than one deleted kusers - get the last one
         $c->addDescendingOrderByColumn(kuserPeer::UPDATED_AT);
         $kuser = kuserPeer::doSelectOne($c);
         kuserPeer::setUseCriteriaFilter(true);
         if (!$kuser) {
             KalturaLog::debug('User not found');
             $response = new KalturaCategoryUserListResponse();
             $response->objects = new KalturaCategoryUserArray();
             $response->totalCount = 0;
             return $response;
         }
         $this->userIdEqual = $kuser->getId();
     }
     $categories = array();
     if ($this->categoryIdEqual) {
         $categories[] = categoryPeer::retrieveByPK($this->categoryIdEqual);
     } elseif ($this->categoryIdIn) {
         $categories = categoryPeer::retrieveByPKs(explode(',', $this->categoryIdIn));
     }
     $categoriesInheritanceRoot = array();
     foreach ($categories as $category) {
         /* @var $category category */
         if (is_null($category)) {
             continue;
         }
         if ($category->getInheritanceType() == InheritanceType::INHERIT) {
             if ($this->categoryDirectMembers && kCurrentContext::$master_partner_id == Partner::BATCH_PARTNER_ID) {
                 $categoriesInheritanceRoot[$category->getId()] = $category->getId();
             } else {
                 //if category inheris members - change filter to -> inherited from parent id = category->getIheritedParent
                 $categoriesInheritanceRoot[$category->getInheritedParentId()] = $category->getInheritedParentId();
             }
         } else {
             $categoriesInheritanceRoot[$category->getId()] = $category->getId();
         }
     }
     $this->categoryDirectMembers = null;
     $this->categoryIdEqual = null;
     $this->categoryIdIn = implode(',', $categoriesInheritanceRoot);
     //if filter had categories that doesn't exists or not entitled - should return 0 objects.
     if (count($categories) && !count($categoriesInheritanceRoot)) {
         $response = new KalturaCategoryUserListResponse();
         $response->totalCount = 0;
         return $response;
     }
     $categoryKuserFilter = $this->toObject();
     $c = KalturaCriteria::create(categoryKuserPeer::OM_CLASS);
     $categoryKuserFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $c->applyFilters();
     $list = categoryKuserPeer::doSelect($c);
     $totalCount = $c->getRecordsCount();
     $newList = KalturaCategoryUserArray::fromDbArray($list, $responseProfile);
     $response = new KalturaCategoryUserListResponse();
     $response->objects = $newList;
     $response->totalCount = $totalCount;
     return $response;
 }
 /**
  * 
  * @param int $categoryId
  * @param int $kuserId
  * @param $con
  * 
  * @return array
  */
 public static function retrieveActiveKusersByCategoryId($categoryId, $con = null)
 {
     $criteria = new Criteria();
     $criteria->add(categoryKuserPeer::CATEGORY_ID, $categoryId);
     $criteria->add(categoryKuserPeer::STATUS, CategoryKuserStatus::ACTIVE);
     return categoryKuserPeer::doSelect($criteria, $con);
 }
Ejemplo n.º 5
0
 public function postUpdate(PropelPDO $con = null)
 {
     if ($this->alreadyInSave) {
         return parent::postUpdate($con);
     }
     $objectUpdated = $this->isModified();
     $objectDeleted = false;
     if ($this->isColumnModified(kuserPeer::STATUS) && $this->getStatus() == KuserStatus::DELETED) {
         $objectDeleted = true;
     }
     $oldLoginDataId = null;
     if ($this->isColumnModified(kuserPeer::LOGIN_DATA_ID)) {
         $oldLoginDataId = $this->oldColumnsValues[kuserPeer::LOGIN_DATA_ID];
     }
     if ($this->isColumnModified(kuserPeer::EMAIL) && $this->getIsAccountOwner() && isset($this->oldColumnsValues[kuserPeer::EMAIL]) && !is_null($this->oldColumnsValues[kuserPeer::EMAIL])) {
         myPartnerUtils::emailChangedEmail($this->getPartnerId(), $this->oldColumnsValues[kuserPeer::EMAIL], $this->getEmail(), $this->getPartner()->getName(), PartnerPeer::KALTURAS_PARTNER_EMAIL_CHANGE);
     }
     if ($this->getIsAccountOwner() && ($this->isColumnModified(kuserPeer::EMAIL) || $this->isColumnModified(kuserPeer::FIRST_NAME) || $this->isColumnModified(kuserPeer::LAST_NAME))) {
         $partner = $this->getPartner();
         $partner->setAccountOwnerKuserId($this->getId(), false);
         $partner->save();
     }
     if ($this->isColumnModified(kuserPeer::SCREEN_NAME) && categoryKuserPeer::isCategroyKuserExistsForKuser($this->getId())) {
         $featureStatusToRemoveIndex = new kFeatureStatus();
         $featureStatusToRemoveIndex->setType(IndexObjectType::CATEGORY_USER);
         $featureStatusesToRemove = array();
         $featureStatusesToRemove[] = $featureStatusToRemoveIndex;
         $filter = new categoryKuserFilter();
         $filter->setUserIdEqual($this->getPuserId());
         kJobsManager::addIndexJob($this->getPartnerId(), IndexObjectType::CATEGORY_USER, $filter, true, $featureStatusesToRemove);
     }
     $ret = parent::postUpdate($con);
     if ($objectDeleted) {
         kEventsManager::raiseEvent(new kObjectDeletedEvent($this));
         // if user is deleted - check if shoult also delete login data
         UserLoginDataPeer::notifyOneLessUser($this->getLoginDataId());
     }
     if ($objectUpdated) {
         kEventsManager::raiseEvent(new kObjectUpdatedEvent($this));
         if (!$objectDeleted && !is_null($oldLoginDataId) && is_null($this->getLoginDataId())) {
             // if login was disabled - check if should also delete login data
             UserLoginDataPeer::notifyOneLessUser($oldLoginDataId);
         }
     }
     return $ret;
 }
Ejemplo n.º 6
0
 public static function doCountOnPeer(Criteria $c)
 {
     return categoryKuserPeer::doCount($c);
 }
Ejemplo n.º 7
0
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if ($this->entryIdEqual == null && $this->categoryIdIn == null && $this->categoryIdEqual == null && (kEntitlementUtils::getEntitlementEnforcement() || !kCurrentContext::$is_admin_session)) {
         throw new KalturaAPIException(KalturaErrors::MUST_FILTER_ON_ENTRY_OR_CATEGORY);
     }
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         //validate entitl for entry
         if ($this->entryIdEqual != null) {
             $entry = entryPeer::retrieveByPK($this->entryIdEqual);
             if (!$entry) {
                 throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryIdEqual);
             }
         }
         //validate entitl for entryIn
         if ($this->entryIdIn != null) {
             $entry = entryPeer::retrieveByPKs($this->entryIdIn);
             if (!$entry) {
                 throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryIdIn);
             }
         }
         //validate entitl categories
         if ($this->categoryIdIn != null) {
             $categoryIdInArr = explode(',', $this->categoryIdIn);
             if (!categoryKuserPeer::areCategoriesAllowed($categoryIdInArr)) {
                 $categoryIdInArr = array_unique($categoryIdInArr);
             }
             $entitledCategories = categoryPeer::retrieveByPKs($categoryIdInArr);
             if (!count($entitledCategories) || count($entitledCategories) != count($categoryIdInArr)) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdIn);
             }
             $categoriesIdsUnlisted = array();
             foreach ($entitledCategories as $category) {
                 if ($category->getDisplayInSearch() == DisplayInSearchType::CATEGORY_MEMBERS_ONLY) {
                     $categoriesIdsUnlisted[] = $category->getId();
                 }
             }
             if (count($categoriesIdsUnlisted)) {
                 if (!categoryKuserPeer::areCategoriesAllowed($categoriesIdsUnlisted)) {
                     throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdIn);
                 }
             }
         }
         //validate entitl category
         if ($this->categoryIdEqual != null) {
             $category = categoryPeer::retrieveByPK($this->categoryIdEqual);
             if (!$category && kCurrentContext::$master_partner_id != Partner::BATCH_PARTNER_ID) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdEqual);
             }
             if ($category->getDisplayInSearch() == DisplayInSearchType::CATEGORY_MEMBERS_ONLY && !categoryKuserPeer::retrievePermittedKuserInCategory($category->getId(), kCurrentContext::getCurrentKsKuserId())) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdEqual);
             }
         }
     }
     $categoryEntryFilter = $this->toObject();
     $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS);
     $categoryEntryFilter->attachToCriteria($c);
     if (!kEntitlementUtils::getEntitlementEnforcement() || $this->entryIdEqual == null) {
         $pager->attachToCriteria($c);
     }
     $dbCategoriesEntry = categoryEntryPeer::doSelect($c);
     if (kEntitlementUtils::getEntitlementEnforcement() && count($dbCategoriesEntry) && $this->entryIdEqual != null) {
         //remove unlisted categories: display in search is set to members only
         $categoriesIds = array();
         foreach ($dbCategoriesEntry as $dbCategoryEntry) {
             $categoriesIds[] = $dbCategoryEntry->getCategoryId();
         }
         $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
         $c->add(categoryPeer::ID, $categoriesIds, Criteria::IN);
         $pager->attachToCriteria($c);
         $c->applyFilters();
         $categoryIds = $c->getFetchedIds();
         foreach ($dbCategoriesEntry as $key => $dbCategoryEntry) {
             if (!in_array($dbCategoryEntry->getCategoryId(), $categoryIds)) {
                 KalturaLog::info('Category [' . print_r($dbCategoryEntry->getCategoryId(), true) . '] is not listed to user');
                 unset($dbCategoriesEntry[$key]);
             }
         }
         $totalCount = $c->getRecordsCount();
     } else {
         $resultCount = count($dbCategoriesEntry);
         if ($resultCount && $resultCount < $pager->pageSize) {
             $totalCount = ($pager->pageIndex - 1) * $pager->pageSize + $resultCount;
         } else {
             KalturaFilterPager::detachFromCriteria($c);
             $totalCount = categoryEntryPeer::doCount($c);
         }
     }
     $categoryEntrylist = KalturaCategoryEntryArray::fromDbArray($dbCategoriesEntry, $responseProfile);
     $response = new KalturaCategoryEntryListResponse();
     $response->objects = $categoryEntrylist;
     $response->totalCount = $totalCount;
     // no pager since category entry is limited to ENTRY::MAX_CATEGORIES_PER_ENTRY
     return $response;
 }
Ejemplo n.º 8
0
 public function getFieldNameFromPeer($field_name)
 {
     $res = categoryKuserPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
     return $res;
 }
 public function getObject()
 {
     return categoryKuserPeer::retrieveByPK($this->getObjectId());
 }
Ejemplo n.º 10
0
 public static function setDefaultCriteriaFilter()
 {
     if (self::$s_criteria_filter == null) {
         self::$s_criteria_filter = new criteriaFilter();
     }
     $c = KalturaCriteria::create(categoryKuserPeer::OM_CLASS);
     $c->addAnd(categoryKuserPeer::STATUS, array(CategoryKuserStatus::DELETED), Criteria::NOT_IN);
     self::$s_criteria_filter->setFilter($c);
 }
Ejemplo n.º 11
0
 /**
  * Delete a Category
  * 
  * @action delete
  * @param int $id
  * @param KalturaNullableBoolean $moveEntriesToParentCategory
  */
 function deleteAction($id, $moveEntriesToParentCategory = KalturaNullableBoolean::TRUE_VALUE)
 {
     if ($this->getPartner()->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) {
         throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED);
     }
     $categoryDb = categoryPeer::retrieveByPK($id);
     if (!$categoryDb) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $id);
     }
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         $currentKuserCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryDb->getId(), kCurrentContext::getCurrentKsKuserId());
         if (!$currentKuserCategoryKuser || $currentKuserCategoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER) {
             throw new KalturaAPIException(KalturaErrors::NOT_ENTITLED_TO_UPDATE_CATEGORY);
         }
     }
     $this->getPartner()->addFeaturesStatus(IndexObjectType::LOCK_CATEGORY);
     try {
         if ($moveEntriesToParentCategory) {
             $categoryDb->setDeletedAt(time());
         } else {
             $categoryDb->setDeletedAt(time(), 0);
         }
         $categoryDb->save();
         $this->getPartner()->removeFeaturesStatus(IndexObjectType::LOCK_CATEGORY);
     } catch (Exception $ex) {
         $this->getPartner()->removeFeaturesStatus(IndexObjectType::LOCK_CATEGORY);
         throw $ex;
     }
 }
 public function validateForInsert($propertiesToSkip = array())
 {
     $category = categoryPeer::retrieveByPK($this->categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryId);
     }
     if ($category->getInheritanceType() == InheritanceType::INHERIT) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_INHERIT_MEMBERS, $this->categoryId);
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $this->userId);
     if ($kuser) {
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($this->categoryId, $kuser->getId());
         if ($categoryKuser) {
             throw new KalturaAPIException(KalturaErrors::CATEGORY_USER_ALREADY_EXISTS);
         }
     }
     $currentKuserCategoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($this->categoryId, kCurrentContext::$ks_kuser_id);
     if ((!$currentKuserCategoryKuser || $currentKuserCategoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER) && $category->getUserJoinPolicy() == UserJoinPolicyType::NOT_ALLOWED && kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_USER_JOIN_NOT_ALLOWED, $this->categoryId);
     }
     //if user doesn't exists - create it
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $this->userId);
     if (!$kuser) {
         if (!preg_match(kuser::PUSER_ID_REGEXP, $this->userId)) {
             throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'userId');
         }
         kuserPeer::createKuserForPartner($partnerId, $this->userId);
     }
     return parent::validateForInsert($propertiesToSkip);
 }
Ejemplo n.º 13
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(categoryKuserPeer::DATABASE_NAME);
         $criteria->add(categoryKuserPeer::ID, $pks, Criteria::IN);
         $objs = categoryKuserPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 protected function doCountOnPeer(Criteria $c)
 {
     return categoryKuserPeer::doCount($c);
 }
Ejemplo n.º 15
0
 /**
  * activate CategoryEntry when it is pending moderation
  * 
  * @action reject
  * @param string $entryId
  * @param int $categoryId
  * @throws KalturaErrors::INVALID_ENTRY_ID
  * @throws KalturaErrors::CATEGORY_NOT_FOUND
  * @throws KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY
  * @throws KalturaErrors::CANNOT_ACTIVATE_CATEGORY_ENTRY
  */
 function rejectAction($entryId, $categoryId)
 {
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $entryId);
     }
     $category = categoryPeer::retrieveByPK($categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId);
     }
     $dbCategoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryId, $entryId);
     if (!$dbCategoryEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY);
     }
     //validate user is entiteld to reject entry from category
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         $categoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryId, kCurrentContext::getCurrentKsKuserId());
         if (!$categoryKuser || $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MODERATOR) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_REJECT_CATEGORY_ENTRY);
         }
     }
     if ($dbCategoryEntry->getStatus() != CategoryEntryStatus::PENDING) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_REJECT_CATEGORY_ENTRY_SINCE_IT_IS_NOT_PENDING);
     }
     $dbCategoryEntry->setStatus(CategoryEntryStatus::REJECTED);
     $dbCategoryEntry->save();
 }
Ejemplo n.º 16
0
 public function validateForUpdate($sourceObject, $propertiesToSkip = null)
 {
     /* @var $sourceObject categoryKuser */
     $category = categoryPeer::retrieveByPK($sourceObject->getCategoryId());
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $sourceObject->getCategoryId());
     }
     if ($this->permissionNames && $this->permissionNames != $sourceObject->getPermissionNames()) {
         if ($sourceObject->getKuserId() == $category->getKuserId()) {
             if (strpos($this->permissionNames, PermissionName::CATEGORY_EDIT) === false) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER_OWNER);
             }
         }
     }
     $currentKuserCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($sourceObject->getCategoryId(), kCurrentContext::getCurrentKsKuserId());
     if (kEntitlementUtils::getEntitlementEnforcement() && (!$currentKuserCategoryKuser || !$currentKuserCategoryKuser->hasPermission(PermissionName::CATEGORY_EDIT))) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER, $sourceObject->getCategoryId());
     }
     return parent::validateForUpdate($sourceObject, $propertiesToSkip);
 }
 /**
  * Returns true if kuser or current kuser is entitled to assign entry to categoryId
  * @param int $categoryId
  * @param int $kuser
  * @return bool
  */
 public static function validateEntryAssignToCategory($categoryId, $kuserId = null)
 {
     if (!self::getEntitlementEnforcement()) {
         return true;
     }
     $category = categoryPeer::retrieveByPK($categoryUser->categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryUser->categoryId);
     }
     if ($category->getContributionPolicy() == ContributionPolicyType::ALL) {
         return true;
     }
     if ($kuserId) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, kCurrentContext::$ks_uid);
         $kuserId = $kuser->getId();
     }
     $currentKuserCategoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryUser->categoryId, $kuserId);
     if ($currentKuserCategoryKuser && ($currentKuserCategoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MANAGER || $currentKuserCategoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MODERATOR || $currentKuserCategoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::CONTRIBUTOR)) {
         return true;
     }
     return false;
 }
 public static function syncEntriesCategories(entry $entry, $isCategoriesModified)
 {
     self::$skipEntrySave = true;
     if ($entry->getNewCategories() != null && $entry->getNewCategories() !== "") {
         $newCats = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategories());
     } else {
         $newCats = array();
     }
     if (!$isCategoriesModified) {
         if ($entry->getNewCategoriesIds() != null && $entry->getNewCategoriesIds() !== "") {
             $newCatsIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategoriesIds());
         } else {
             $newCatsIds = array();
         }
         KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $dbCategories = categoryPeer::retrieveByPKs($newCatsIds);
         KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         foreach ($dbCategories as $dbCategory) {
             //skip categoy with privacy contexts.
             if ($dbCategory->getPrivacyContexts() != null && $dbCategory->getPrivacyContexts() != '') {
                 continue;
             }
             $newCats[] = $dbCategory->getFullName();
         }
     }
     $newCats = array_unique($newCats);
     $allIds = array();
     $allCats = array();
     $allIdsWithParents = array();
     $addedCats = array();
     $removedCats = array();
     $remainingCats = array();
     $oldCats = array();
     $oldCatsIds = array();
     $dbOldCategoriesEntry = categoryEntryPeer::selectByEntryId($entry->getId());
     foreach ($dbOldCategoriesEntry as $dbOldCategoryEntry) {
         $oldCatsIds[] = $dbOldCategoryEntry->getCategoryId();
     }
     $oldCategoris = categoryPeer::retrieveByPKsNoFilter($oldCatsIds);
     foreach ($oldCategoris as $category) {
         if ($category->getPrivacyContexts() != '' && $category->getPrivacyContexts() != null) {
             continue;
         }
         $oldCats[] = $category->getFullName();
     }
     foreach ($oldCats as $cat) {
         if (array_search($cat, $newCats) === false) {
             $removedCats[] = $cat;
         }
     }
     foreach ($newCats as $cat) {
         if (array_search($cat, $oldCats) === false) {
             $addedCats[] = $cat;
         } else {
             $remainingCats[] = $cat;
         }
     }
     foreach ($remainingCats as $cat) {
         KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $category = categoryPeer::getByFullNameExactMatch($cat);
         KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         if ($category) {
             if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) {
                 $allCats[] = $category->getFullName();
                 $allIds[] = $category->getId();
             }
             $allIdsWithParents[] = $category->getId();
             $allIdsWithParents = array_merge($allIdsWithParents, $category->getAllParentsIds());
         }
     }
     $alreadyAddedCatIds = $allIdsWithParents;
     foreach ($addedCats as $cat) {
         $category = categoryPeer::getByFullNameExactMatch($cat);
         if (!$category) {
             KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             $unentitedCategory = categoryPeer::getByFullNameExactMatch($cat);
             KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             if (!$unentitedCategory) {
                 $category = category::createByPartnerAndFullName($entry->getPartnerId(), $cat);
                 //it is possible to add on an entry a few new categories on the same new parent -
                 //and we need to sync sphinx once we add so the category will not be duplicated
                 kEventsManager::flushEvents();
             }
         } else {
             $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($category->getId(), kCurrentContext::$ks_kuser_id);
             if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) {
                 //user is not entitled to add entry to this category
                 $category = null;
             }
         }
         if (!$category) {
             continue;
         }
         //when use caetgoryEntry->add categoryEntry object was alreay created - and no need to create it.
         //when using baseEntry->categories = 'my category' will need to add the new category.
         $categoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId());
         if (!$categoryEntry) {
             $categoryEntry = new categoryEntry();
             $categoryEntry->setEntryId($entry->getId());
             $categoryEntry->setCategoryId($category->getId());
             $categoryEntry->setEntryCategoriesAddedIds($alreadyAddedCatIds);
             $categoryEntry->setPartnerId($entry->getPartnerId());
             $categoryEntry->setStatus(CategoryEntryStatus::ACTIVE);
             $categoryEntry->save();
         }
         if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) {
             // only categories with no context should be set on entry->categories and entry->categoriesIds
             $allCats[] = $category->getFullName();
             $allIds[] = $category->getId();
         }
         $alreadyAddedCatIds[] = $category->getId();
         $alreadyAddedCatIds = array_merge($alreadyAddedCatIds, $category->getAllParentsIds());
     }
     $alreadyRemovedCatIds = $allIdsWithParents;
     foreach ($removedCats as $cat) {
         $category = categoryPeer::getByFullNameExactMatch($cat);
         if ($category) {
             $categoryEntryToDelete = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId());
             if ($categoryEntryToDelete) {
                 $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntryToDelete->getCategoryId(), kCurrentContext::$ks_kuser_id);
                 if ($category->getPrivacyContexts() && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) {
                     //not entiteld to delete - should be set back on the entry.
                     $allCats[] = $category->getFullName();
                     $allIds[] = $category->getId();
                 } else {
                     $categoryEntryToDelete->setEntryCategoriesRemovedIds($alreadyRemovedCatIds);
                     $categoryEntryToDelete->setStatus(CategoryEntryStatus::DELETED);
                     $categoryEntryToDelete->save();
                 }
             }
             $alreadyRemovedCatIds[] = $category->getId();
             $alreadyRemovedCatIds = array_merge($alreadyRemovedCatIds, $category->getAllParentsIds());
         } else {
             //category was not found - it could be that user is not entitled to remove it
             KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             $category = categoryPeer::getByFullNameExactMatch($cat);
             KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             if ($category) {
                 $allCats[] = $category->getFullName();
                 $allIds[] = $category->getId();
             }
         }
     }
     self::$skipEntrySave = false;
     $entry->parentSetCategories(implode(",", $allCats));
     $entry->parentSetCategoriesIds(implode(',', $allIds));
 }
    $c->add(categoryKuserPeer::UPDATED_AT, $argv[1], Criteria::GREATER_EQUAL);
}
if ($argc > 2 && is_numeric($argv[2])) {
    $c->add(categoryKuserPeer::PARTNER_ID, $argv[2], Criteria::EQUAL);
}
if ($argc > 3 && is_numeric($argv[3])) {
    $c->add(categoryKuserPeer::ID, $argv[3], Criteria::GREATER_EQUAL);
}
$c->addAscendingOrderByColumn(categoryKuserPeer::UPDATED_AT);
$c->addAscendingOrderByColumn(categoryKuserPeer::ID);
$c->setLimit(10000);
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2);
//$sphinxCon = DbManager::getSphinxConnection();
$categoryKusers = categoryKuserPeer::doSelect($c, $con);
$sphinx = new kSphinxSearchManager();
while (count($categoryKusers)) {
    foreach ($categoryKusers as $categoryKuser) {
        /* @var $categoryKuser categoryKuser */
        KalturaLog::log('$categoryKuser id ' . $categoryKuser->getId() . ' updated at ' . $categoryKuser->getUpdatedAt(null));
        try {
            $ret = $sphinx->saveToSphinx($categoryKuser, true);
        } catch (Exception $e) {
            KalturaLog::err($e->getMessage());
            exit - 1;
        }
    }
    $c->setOffset($c->getOffset() + count($categoryKusers));
    kMemoryManager::clearMemory();
    $categoryKusers = categoryKuserPeer::doSelect($c, $con);
}
KalturaLog::log('Done. Current time: ' . time());
Ejemplo n.º 20
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this kuser is new, it will return
  * an empty collection; or if this kuser has previously
  * been saved, it will retrieve related categoryKusers from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in kuser.
  */
 public function getcategoryKusersJoincategory($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(kuserPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collcategoryKusers === null) {
         if ($this->isNew()) {
             $this->collcategoryKusers = array();
         } else {
             $criteria->add(categoryKuserPeer::KUSER_ID, $this->id);
             $this->collcategoryKusers = categoryKuserPeer::doSelectJoincategory($criteria, $con, $join_behavior);
         }
     } else {
         // the following code is to determine if a new query is
         // called for.  If the criteria is the same as the last
         // one, just return the collection.
         $criteria->add(categoryKuserPeer::KUSER_ID, $this->id);
         if (!isset($this->lastcategoryKuserCriteria) || !$this->lastcategoryKuserCriteria->equals($criteria)) {
             $this->collcategoryKusers = categoryKuserPeer::doSelectJoincategory($criteria, $con, $join_behavior);
         }
     }
     $this->lastcategoryKuserCriteria = $criteria;
     return $this->collcategoryKusers;
 }
Ejemplo n.º 21
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(categoryKuserPeer::DATABASE_NAME);
     $criteria->add(categoryKuserPeer::ID, $this->id);
     if ($this->alreadyInSave && count($this->modifiedColumns) == 2 && $this->isColumnModified(categoryKuserPeer::UPDATED_AT)) {
         $theModifiedColumn = null;
         foreach ($this->modifiedColumns as $modifiedColumn) {
             if ($modifiedColumn != categoryKuserPeer::UPDATED_AT) {
                 $theModifiedColumn = $modifiedColumn;
             }
         }
         $atomicColumns = categoryKuserPeer::getAtomicColumns();
         if (in_array($theModifiedColumn, $atomicColumns)) {
             $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
         }
     }
     return $criteria;
 }
Ejemplo n.º 22
0
 /**
  * Index CategoryUser by userid and category id
  * 
  * @action index
  * @param string $userId
  * @param int $categoryId
  * @param bool $shouldUpdate
  * @throws KalturaErrors::INVALID_CATEGORY_USER_ID
  * @return int
  */
 public function indexAction($userId, $categoryId, $shouldUpdate = true)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_INDEX_OBJECT_WHEN_ENTITLEMENT_IS_ENABLE);
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $kuser = kuserPeer::getActiveKuserByPartnerAndUid($partnerId, $userId);
     if (!$kuser) {
         throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
     }
     $dbCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryId, $kuser->getId(), null, false);
     if (!$dbCategoryKuser) {
         throw new KalturaAPIException(KalturaErrors::INVALID_CATEGORY_USER_ID);
     }
     if (!$shouldUpdate) {
         $dbCategoryKuser->setUpdatedAt(time());
         $dbCategoryKuser->save();
         return $dbCategoryKuser->getId();
     }
     $dbCategoryKuser->reSetCategoryFullIds();
     $dbCategoryKuser->reSetScreenName();
     $dbCategoryKuser->save();
     return $dbCategoryKuser->getId();
 }
Ejemplo n.º 23
0
 /**
  * reset category's pendingMembersCount by calculate it.
  */
 public function reSetPendingMembersCount()
 {
     if ($this->getInheritanceType() == InheritanceType::INHERIT) {
         $this->setPendingMembersCount($this->getInheritParent()->getPendingMembersCount());
     } else {
         $criteria = KalturaCriteria::create(categoryKuserPeer::OM_CLASS);
         $criteria->addAnd(categoryKuserPeer::CATEGORY_ID, $this->getId(), Criteria::EQUAL);
         $criteria->addAnd(categoryKuserPeer::STATUS, CategoryKuserStatus::PENDING, Criteria::EQUAL);
         $this->setPendingMembersCount(categoryKuserPeer::doCount($criteria));
     }
 }
 public function postSave(PropelPDO $con = null)
 {
     if ($this->roleIdsChanged) {
         // delete old roles
         $c = new Criteria();
         $c->addAnd(KuserToUserRolePeer::KUSER_ID, $this->getId(), Criteria::EQUAL);
         KuserToUserRolePeer::doDelete($c);
         // add new roles
         $idsArray = explode(',', $this->roleIds);
         foreach ($idsArray as $id) {
             if (!is_null($id) && $id != '') {
                 $kuserToRole = new KuserToUserRole();
                 $kuserToRole->setUserRoleId($id);
                 $kuserToRole->setKuserId($this->getId());
                 $kuserToRole->save();
             }
         }
     }
     $this->roleIdsChanged = false;
     //update all categoryKuser object with kuser
     if (categoryKuserPeer::isCategroyKuserExistsForKuser($this->getId())) {
         $featureStatusToRemoveIndex = new kFeatureStatus();
         $featureStatusToRemoveIndex->setType(IndexObjectType::CATEGORY_USER);
         $featureStatusesToRemove = array();
         $featureStatusesToRemove[] = $featureStatusToRemoveIndex;
         $filter = new categoryKuserFilter();
         $filter->setUserIdEqual($this->getPuserId());
         kJobsManager::addIndexJob($this->getPartnerId(), IndexObjectType::CATEGORY_USER, $filter, true, $featureStatusesToRemove);
     }
     return parent::postSave();
 }
    KalturaLog::info("Migrating [" . count($categoryKusers) . "] categories.");
    foreach ($categoryKusers as $categoryKuser) {
        $categoryKuser = cast($categoryKuser, 'MigrationCategoryKuser');
        /* @var $categoryKuser categoryKuser */
        $categoryKuser->reSetScreenName();
        KalturaStatement::setDryRun($dryRun);
        $categoryKuser->save();
        KalturaStatement::setDryRun(false);
        $startCategoryKuserId = $categoryKuser->getId();
        KalturaLog::info("Migrated categoryKuser [{$startCategoryKuserId}].");
    }
    kEventsManager::flushEvents();
    kMemoryManager::clearMemory();
    $nextCriteria = clone $criteria;
    $nextCriteria->add(categoryKuserPeer::ID, $startCategoryKuserId, Criteria::GREATER_THAN);
    $categoryKusers = categoryKuserPeer::doSelect($nextCriteria);
    usleep(100);
}
KalturaLog::info("Done");
function cast($object, $toClass)
{
    if (class_exists($toClass)) {
        $objectIn = serialize($object);
        $obj_name_len = strlen(get_class($object));
        $objectOut = 'O:' . strlen($toClass) . ':"' . $toClass . '":' . substr($objectIn, $obj_name_len + strlen($obj_name_len) + 6);
        $ret = unserialize($objectOut);
        if ($ret instanceof $toClass) {
            return $ret;
        }
    } else {
        KalturaLog::debug('Class doesnt exists' . print_r($toClass, true));