public function save(PropelPDO $con = null) { if ($this->isNew()) { $numOfCatsForPartner = categoryPeer::doCount(new Criteria()); if ($numOfCatsForPartner >= Partner::MAX_NUMBER_OF_CATEGORIES) { throw new kCoreException("Max number of categories was reached", kCoreException::MAX_NUMBER_OF_CATEGORIES_REACHED); } } // set the depth of the parent category + 1 if ($this->isNew() || $this->isColumnModified(categoryPeer::PARENT_ID)) { $parentCat = $this->getParentCategory(); if ($this->getParentId() !== 0) { $this->setDepth($parentCat->getDepth() + 1); } else { $this->setDepth(0); } $this->setChildsDepth(); } if ($this->getDepth() >= self::MAX_CATEGORY_DEPTH) { throw new kCoreException("Max depth was reached", kCoreException::MAX_CATEGORY_DEPTH_REACHED); } if ($this->isColumnModified(categoryPeer::NAME) || $this->isColumnModified(categoryPeer::PARENT_ID)) { $this->updateFullName(); $this->renameOnEntries(); } // happens in 3 cases: // 1. name of the current category was updated // 2. full name of the parent category was updated and it was set here as child // 3. parent id was changed if ($this->isColumnModified(categoryPeer::FULL_NAME)) { $this->setChildsFullNames(); } // save the childs foreach ($this->childs_for_save as $child) { $child->save(); } $this->childs_for_save = array(); if ($this->isColumnModified(categoryPeer::DELETED_AT) && $this->getDeletedAt() !== null) { $this->moveEntriesToParent(); } if ($this->isColumnModified(categoryPeer::PARENT_ID) && !$this->isNew()) { // decrease for the old parent category if ($this->old_parent_id) { $oldParentCat = categoryPeer::retrieveByPK($this->old_parent_id); } if ($oldParentCat) { $oldParentCat->decrementEntriesCount($this->entries_count); } // increase for the new parent category $newParentCat = categoryPeer::retrieveByPK($this->parent_id); if ($newParentCat) { $newParentCat->incrementEntriesCount($this->entries_count); } $this->old_parent_id = null; } parent::save($con); }
public static function doCountOnPeer(Criteria $c) { return categoryPeer::doCount($c); }
public function save(PropelPDO $con = null) { if ($this->isNew()) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::STATUS, CategoryStatus::DELETED, Criteria::NOT_EQUAL); $c->add(categoryPeer::PARTNER_ID, $partnerId, Criteria::EQUAL); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $numOfCatsForPartner = categoryPeer::doCount($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $chunkedCategoryLoadThreshold = kConf::get('kmc_chunked_category_load_threshold'); if ($numOfCatsForPartner >= $chunkedCategoryLoadThreshold) { PermissionPeer::enableForPartner(PermissionName::DYNAMIC_FLAG_KMC_CHUNKED_CATEGORY_LOAD, PermissionType::SPECIAL_FEATURE); } if ($this->getParentId() && ($this->getPrivacyContext() == '' || $this->getPrivacyContext() == null)) { $parentCategory = $this->getParentCategory(); $this->setPrivacyContexts($parentCategory->getPrivacyContexts()); } } if (!$this->getIsIndex() && ($this->isColumnModified(categoryPeer::NAME) || $this->isColumnModified(categoryPeer::PARENT_ID))) { $this->updateFullName(); } if (trim($this->getPrivacyContexts()) == '') { $this->setDefaultUnEntitlmenetCategory(); } // set the depth of the parent category + 1 if (!$this->getIsIndex() && ($this->isNew() || $this->isColumnModified(categoryPeer::PARENT_ID))) { $this->reSetDepth(); } if (!$this->isNew() && $this->isColumnModified(categoryPeer::PARENT_ID)) { $this->resetFullIds(); } //index + update categoryEntry if (!$this->isNew() && ($this->isColumnModified(categoryPeer::FULL_IDS) || $this->isColumnModified(categoryPeer::PARENT_ID))) { $this->addIndexCategoryEntryJob($this->getId()); $this->addIndexCategoryKuserJob($this->getId()); } if (!$this->isNew() && $this->getInheritanceType() !== InheritanceType::INHERIT && $this->isColumnModified(categoryPeer::PRIVACY_CONTEXTS)) { if ($this->getPrivacyContexts() == '') { $this->addDeleteCategoryKuserJob($this->getId()); } } if (!$this->isNew() && $this->isColumnModified(categoryPeer::PRIVACY_CONTEXTS)) { $this->addSyncCategoryPrivacyContextJob(); } // save the childs for action category->delete - delete category is not done by async batch. foreach ($this->childs_for_save as $child) { $child->save(); } $this->childs_for_save = array(); if ($this->isColumnModified(categoryPeer::DELETED_AT) && $this->getDeletedAt() !== null) { // delete all categoryKuser objects for this category if ($this->getInheritanceType() == InheritanceType::MANUAL) { $this->addDeleteCategoryKuserJob($this->getId()); } if ($this->move_entries_to_parent_category) { $this->addMoveEntriesToCategoryJob($this->move_entries_to_parent_category); } elseif ($this->move_entries_to_parent_category === 0) { $this->addDeleteCategoryEntryJob($this->getId()); } } $kuserChanged = false; if (!$this->isNew() && $this->isColumnModified(categoryPeer::INHERITANCE_TYPE)) { if ($this->inheritance_type == InheritanceType::MANUAL && $this->old_inheritance_type == InheritanceType::INHERIT) { if ($this->parent_id) { $categoryToCopyInheritedFields = $this->getInheritParent(); } if ($categoryToCopyInheritedFields) { $this->copyInheritedFields($categoryToCopyInheritedFields); $kuserChanged = true; } $this->reSetMembersCount(); } elseif ($this->inheritance_type == InheritanceType::INHERIT && $this->old_inheritance_type == InheritanceType::MANUAL) { $this->addDeleteCategoryKuserJob($this->getId(), true); } } if ($this->isColumnModified(categoryPeer::KUSER_ID)) { $kuserChanged = true; } if (!$this->isNew() && $this->isColumnModified(categoryPeer::PRIVACY) && $this->getPrivacy() == PrivacyType::MEMBERS_ONLY) { $this->removeNonMemberKusers(); } parent::save($con); if ($kuserChanged && $this->inheritance_type != InheritanceType::INHERIT && $this->getKuserId()) { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($this->getId(), $this->getKuserId()); if (!$categoryKuser) { $categoryKuser = new categoryKuser(); $categoryKuser->setCategoryId($this->getId()); $categoryKuser->setCategoryFullIds($this->getFullIds()); $categoryKuser->setKuserId($this->getKuserId()); } $categoryKuser->setPermissionLevel(CategoryKuserPermissionLevel::MANAGER); $permissionNamesArr = array(); if ($categoryKuser->getPermissionNames()) { $permissionNamesArr = explode(",", $categoryKuser->getPermissionNames()); } $permissionNamesArr = categoryKuser::removeCategoryPermissions($permissionNamesArr); $permissionNamesArr[] = PermissionName::CATEGORY_CONTRIBUTE; $permissionNamesArr[] = PermissionName::CATEGORY_EDIT; $permissionNamesArr[] = PermissionName::CATEGORY_MODERATE; $permissionNamesArr[] = PermissionName::CATEGORY_VIEW; $categoryKuser->setPermissionNames(implode(",", $permissionNamesArr)); $categoryKuser->setStatus(CategoryKuserStatus::ACTIVE); $categoryKuser->setPartnerId($this->getPartnerId()); $categoryKuser->setUpdateMethod(UpdateMethodType::MANUAL); $categoryKuser->save(); $this->indexToSearchIndex(); } }
protected function doCountOnPeer(Criteria $c) { return categoryPeer::doCount($c); }
/** * List all categories * * @action list * @return KalturaCategoryListResponse */ function listAction(KalturaCategoryFilter $filter = null) { if ($filter === null) { $filter = new KalturaCategoryFilter(); } if ($filter->orderBy === null) { $filter->orderBy = KalturaCategoryOrderBy::DEPTH_ASC; } $categoryFilter = new categoryFilter(); $filter->toObject($categoryFilter); $c = new Criteria(); $categoryFilter->attachToCriteria($c); $totalCount = categoryPeer::doCount($c); $dbList = categoryPeer::doSelect($c); $list = KalturaCategoryArray::fromCategoryArray($dbList); $response = new KalturaCategoryListResponse(); $response->objects = $list; $response->totalCount = $totalCount; return $response; }
/** * Validate the amount of core and plugin objects found on the template partner. * @param Partner $templatePartner */ private function validateTemplatePartner(Partner $templatePartner) { //access control profiles $c = new Criteria(); $c->add(accessControlPeer::PARTNER_ID, $templatePartner->getId()); $count = accessControlPeer::doCount($c); if ($count > kConf::get('copy_partner_limit_ac_profiles')) { throw new kCoreException("Template partner's number of [accessControlProfiles] objects exceed allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED); } //categories categoryPeer::setUseCriteriaFilter(false); $c = new Criteria(); $c->addAnd(categoryPeer::PARTNER_ID, $templatePartner->getId()); $c->addAnd(categoryPeer::STATUS, CategoryStatus::ACTIVE); $count = categoryPeer::doCount($c); if ($count > kConf::get('copy_partner_limit_categories')) { throw new kCoreException("Template partner's number of [category] objects exceed allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED); } categoryPeer::setUseCriteriaFilter(true); //conversion profiles $c = new Criteria(); $c->add(conversionProfile2Peer::PARTNER_ID, $templatePartner->getId()); $count = conversionProfile2Peer::doCount($c); if ($count > kConf::get('copy_partner_limit_conversion_profiles')) { throw new kCoreException("Template partner's number of [conversionProfile] objects exceeds allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED); } //entries entryPeer::setUseCriteriaFilter(false); $c = new Criteria(); $c->addAnd(entryPeer::PARTNER_ID, $templatePartner->getId()); $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP); $c->addAnd(entryPeer::STATUS, entryStatus::READY); $count = entryPeer::doCount($c); if ($count > kConf::get('copy_partner_limit_entries')) { throw new kCoreException("Template partner's number of MEDIA_CLIP objects exceed allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED); } entryPeer::setUseCriteriaFilter(true); //playlists entryPeer::setUseCriteriaFilter(false); $c = new Criteria(); $c->addAnd(entryPeer::PARTNER_ID, $templatePartner->getId()); $c->addAnd(entryPeer::TYPE, entryType::PLAYLIST); $c->addAnd(entryPeer::STATUS, entryStatus::READY); $count = entryPeer::doCount($c); if ($count > kConf::get('copy_partner_limit_playlists')) { throw new kCoreException("Template partner's number of PLAYLIST objects exceed allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED); } entryPeer::setUseCriteriaFilter(true); //flavor params $c = new Criteria(); $c->add(assetParamsPeer::PARTNER_ID, $templatePartner->getId()); $count = assetParamsPeer::doCount($c); if ($count > kConf::get('copy_partner_limit_flavor_params')) { throw new kCoreException("Template partner's number of [flavorParams] objects exceeds allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED); } //uiconfs uiConfPeer::setUseCriteriaFilter(false); $c = new Criteria(); $c->addAnd(uiConfPeer::PARTNER_ID, $templatePartner->getId()); $c->addAnd(uiConfPeer::OBJ_TYPE, array(uiConf::UI_CONF_TYPE_KDP3, uiConf::UI_CONF_TYPE_WIDGET), Criteria::IN); $c->addAnd(uiConfPeer::STATUS, uiConf::UI_CONF_STATUS_READY); $count = uiConfPeer::doCount($c); if ($count > kConf::get('copy_partner_limit_ui_confs')) { throw new kCoreException("Template partner's number of [uiconf] objects exceeds allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED); } uiConfPeer::setUseCriteriaFilter(true); //user roles UserRolePeer::setUseCriteriaFilter(false); $c = new Criteria(); $c->addAnd(UserRolePeer::PARTNER_ID, $templatePartner->getId(), Criteria::EQUAL); $c->addAnd(UserRolePeer::STATUS, UserRoleStatus::ACTIVE, Criteria::EQUAL); $count = UserRolePeer::doCount($c); if ($count > kConf::get('copy_partner_limit_user_roles')) { throw new kCoreException("Template partner's number of [userRole] objects exceed allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED); } UserRolePeer::setUseCriteriaFilter(true); $validatorPlugins = KalturaPluginManager::getPluginInstances('IKalturaObjectValidator'); foreach ($validatorPlugins as $validatorPlugins) { $validatorPlugins->validateObject($templatePartner, IKalturaObjectValidator::OPERATION_COPY); } }