public function postUpdate(PropelPDO $con = null) { parent::postUpdate($con); categoryPeer::setUseCriteriaFilter(false); $category = categoryPeer::retrieveByPK($this->getCategoryId()); categoryPeer::setUseCriteriaFilter(true); if (!$category) { throw new kCoreException('category id [' . $this->getCategoryId() . 'was not found', kCoreException::ID_NOT_FOUND); } $entry = entryPeer::retrieveByPK($this->getEntryId()); if (!$entry && $this->getStatus() != CategoryEntryStatus::DELETED) { throw new kCoreException('entry id [' . $this->getEntryId() . 'was not found', kCoreException::ID_NOT_FOUND); } if ($entry && $this->getStatus() == CategoryEntryStatus::ACTIVE && $this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $entry = $this->setEntryOnCategory($category, $entry); } if ($this->getStatus() == CategoryEntryStatus::REJECTED && $this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $category->decrementPendingEntriesCount(); } if ($this->getStatus() == CategoryEntryStatus::PENDING && $this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::REJECTED) { $category->incrementPendingEntriesCount(); } if ($this->getStatus() == CategoryEntryStatus::DELETED) { if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::ACTIVE) { $category->decrementEntriesCount($this->getEntryId()); $category->decrementDirectEntriesCount($this->getEntryId()); if ($entry && !categoryEntryPeer::getSkipSave()) { $categories = array(); if (trim($entry->getCategories()) != '') { $categories = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategories()); foreach ($categories as $index => $entryCategoryFullName) { if ($entryCategoryFullName == $category->getFullName()) { unset($categories[$index]); } } } $categoriesIds = array(); if (trim($entry->getCategoriesIds()) != '') { $categoriesIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategoriesIds()); foreach ($categories as $index => $entryCategoryId) { if ($entryCategoryId == $category->getId()) { unset($categoriesIds[$index]); } } } $entry->setCategories(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categories)); $entry->setCategoriesIds(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categoriesIds)); $entry->save(); } kEventsManager::raiseEvent(new kObjectDeletedEvent($this)); } if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $category->decrementPendingEntriesCount(); } } $category->save(); if ($entry && !categoryEntryPeer::getSkipSave()) { $entry->indexToSearchIndex(); } }
public function postUpdate(PropelPDO $con = null) { parent::postUpdate($con); categoryPeer::setUseCriteriaFilter(false); $category = categoryPeer::retrieveByPK($this->getCategoryId()); categoryPeer::setUseCriteriaFilter(true); if (!$category) { throw new kCoreException('category id [' . $this->getCategoryId() . 'was not found', kCoreException::ID_NOT_FOUND); } $entry = entryPeer::retrieveByPK($this->getEntryId()); if (!$entry && $this->getStatus() != CategoryEntryStatus::DELETED) { throw new kCoreException('entry id [' . $this->getEntryId() . 'was not found', kCoreException::ID_NOT_FOUND); } if ($entry && $this->getStatus() == CategoryEntryStatus::ACTIVE && $this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $entry = $this->setEntryOnCategory($category, $entry); } if ($this->getStatus() == CategoryEntryStatus::REJECTED && $this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $category->decrementPendingEntriesCount(); } if ($this->getStatus() == CategoryEntryStatus::DELETED) { if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::ACTIVE) { if (is_null($this->entryCategoriesRemovedIds)) { $categoriesEntries = categoryEntryPeer::retrieveActiveByEntryId($this->getEntryId()); $categoriesIds = array(); foreach ($categoriesEntries as $categroyEntry) { //cannot get directly the full ids - since it might not be updated. if ($categroyEntry->getCategoryId() != $this->getCategoryId()) { $categoriesIds[] = $categroyEntry->getCategoryId(); } } $categoriesRemoved = categoryPeer::retrieveByPKs($categoriesIds); $entryCategoriesRemovedIds = array(); foreach ($categoriesRemoved as $categoryRemoved) { $fullIds = explode(categoryPeer::CATEGORY_SEPARATOR, $categoryRemoved->getFullIds()); $entryCategoriesRemovedIds = array_merge($entryCategoriesRemovedIds, $fullIds); } $this->entryCategoriesRemovedIds = $entryCategoriesRemovedIds; } $category->decrementEntriesCount(1, $this->entryCategoriesRemovedIds); $category->decrementDirectEntriesCount(); if ($entry && !categoryEntryPeer::getSkipSave()) { $fullName = $category->getFullName(); $entryCategories = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategories()); $newCategories = array(); foreach ($entryCategories as $entryCategory) { if (!preg_match("/^" . $fullName . "/", $entryCategory)) { $newCategories[] = $entryCategory; } } $categoryId = $category->getId(); $entryCategoriesIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategoriesIds()); $newCategoriesIds = array(); foreach ($entryCategoriesIds as $entryCategoryIds) { if (!preg_match("/^" . $categoryId . "/", $entryCategoryIds)) { $newCategoriesIds[] = $entryCategoryIds; } } $entry->parentSetCategories(implode(entry::ENTRY_CATEGORY_SEPARATOR, $newCategories)); $entry->parentSetCategoriesIds(implode(entry::ENTRY_CATEGORY_SEPARATOR, $newCategoriesIds)); $entry->save(); } } if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $category->decrementPendingEntriesCount(); } } $category->save(); if ($entry && !categoryEntryPeer::getSkipSave()) { $entry->indexToSearchIndex(); } }