Example #1
0
 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();
     }
 }