Esempio n. 1
0
 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();
     }
 }
Esempio n. 2
0
 /**
  * @return BaseObject
  */
 public function getObject()
 {
     switch ($this->getObjectType()) {
         case BatchJobObjectType::ENTRY:
             entryPeer::setUseCriteriaFilter(false);
             $object = entryPeer::retrieveByPK($this->getObjectId());
             entryPeer::setUseCriteriaFilter(true);
             return $object;
         case BatchJobObjectType::ASSET:
             assetPeer::setUseCriteriaFilter(false);
             $object = assetPeer::retrieveById($this->getObjectId());
             assetPeer::setUseCriteriaFilter(true);
             return $object;
         case BatchJobObjectType::CATEGORY:
             categoryPeer::setUseCriteriaFilter(false);
             $object = categoryPeer::retrieveByPK($this->getObjectId());
             categoryPeer::setUseCriteriaFilter(true);
             return $object;
         case BatchJobObjectType::FILE_SYNC:
             FileSyncPeer::setUseCriteriaFilter(false);
             $object = FileSyncPeer::retrieveByPK($this->getObjectId());
             FileSyncPeer::setUseCriteriaFilter(true);
             return $object;
         default:
             // TODO implement IBatchable in relevant plugins
             return KalturaPluginManager::loadObject('IBatchable', $this->getObjectId());
     }
     return $this->aRootJob;
 }
Esempio n. 3
0
 public static function copyCategories(Partner $fromPartner, Partner $toPartner)
 {
     KalturaLog::log("Copying categories from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     categoryPeer::setUseCriteriaFilter(false);
     $c = new Criteria();
     $c->addAnd(categoryPeer::PARTNER_ID, $fromPartner->getId());
     $c->addAnd(categoryPeer::STATUS, CategoryStatus::ACTIVE);
     $c->addAscendingOrderByColumn(categoryPeer::DEPTH);
     $c->addAscendingOrderByColumn(categoryPeer::CREATED_AT);
     $categories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     foreach ($categories as $category) {
         /* @var $category category */
         $category->setPuserId(null);
         $newCategory = $category->copy();
         $newCategory->setPartnerId($toPartner->getId());
         if ($category->getParentId()) {
             $newCategory->setParentId(kObjectCopyHandler::getMappedId('category', $category->getParentId()));
         }
         $newCategory->save();
         $newCategory->setIsIndex(true);
         categoryPeer::setUseCriteriaFilter(false);
         $newCategory->reSetFullIds();
         $newCategory->reSetInheritedParentId();
         $newCategory->reSetDepth();
         $newCategory->reSetFullName();
         categoryPeer::setUseCriteriaFilter(true);
         $newCategory->setEntriesCount(0);
         $newCategory->setMembersCount(0);
         $newCategory->setPendingMembersCount(0);
         $newCategory->setDirectSubCategoriesCount(0);
         $newCategory->setDirectEntriesCount(0);
         $newCategory->save();
         KalturaLog::log("Copied [" . $category->getId() . "], new id is [" . $newCategory->getId() . "]");
     }
 }
Esempio n. 4
0
 public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false)
 {
     KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]");
     $newEntry = $entry->copy();
     $newEntry->setIntId(null);
     $newEntry->setCategories(null);
     $newEntry->setCategoriesIds(null);
     if ($toPartner instanceof Partner) {
         $newEntry->setPartnerId($toPartner->getId());
         $newEntry->setSubpId($toPartner->getId() * 100);
         $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId());
     }
     $newKuser = null;
     if (!$dontCopyUsers) {
         // copy the kuser (if the same puser id exists its kuser will be used)
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = $entry->getKuser();
         $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId());
         $newEntry->setKuserId($newKuser->getId());
         $newEntry->setCreatorKuserId($newKuser->getId());
         kuserPeer::setUseCriteriaFilter(true);
     }
     // copy the kshow
     kshowPeer::setUseCriteriaFilter(false);
     $kshow = $entry->getKshow();
     if ($kshow) {
         $newKshow = $kshow->copy();
         $newKshow->setIntId(null);
         $newKshow->setPartnerId($toPartner->getId());
         $newKshow->setSubpId($toPartner->getId() * 100);
         if ($newKuser) {
             $newKshow->setProducerId($newKuser->getId());
         }
         $newKshow->save();
         $newEntry->setKshowId($newKshow->getId());
     }
     kshowPeer::setUseCriteriaFilter(true);
     // reset the statistics
     myEntryUtils::resetEntryStatistics($newEntry);
     // set the new partner id into the default category criteria filter
     $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter();
     $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     // save the entry
     $newEntry->save();
     // restore the original partner id in the default category criteria filter
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId);
     KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created");
     if ($entry->getStatus() != entryStatus::READY) {
         $clonePendingEntries = $entry->getClonePendingEntries();
         $clonePendingEntries[] = $newEntry->getId();
         $entry->setClonePendingEntries($clonePendingEntries);
         $entry->save();
     } else {
         self::copyEntryData($entry, $newEntry);
     }
     //if entry is a static playlist, link between it and its new child entries
     if ($entry->getType() == entryType::PLAYLIST) {
         switch ($entry->getMediaType()) {
             case entry::ENTRY_MEDIA_TYPE_TEXT:
                 $from = $entry->getDataContent();
                 KalturaLog::debug("Entries to copy from source static playlist: [{$from}]");
                 $fromEntryIds = explode(",", $from);
                 $toEntryIds = array();
                 foreach ($fromEntryIds as $fromEntryId) {
                     $toEntryIds[] = kObjectCopyHandler::getMappedId(entryPeer::OM_CLASS, $fromEntryId);
                 }
                 $newEntry->setDataContent(implode(",", $toEntryIds));
                 break;
             case entry::ENTRY_MEDIA_TYPE_XML:
                 list($totalResults, $fromFiltersList) = myPlaylistUtils::getPlaylistFilterListStruct($entry->getDataContent());
                 $toPlaylistXml = new SimpleXMLElement("<playlist/>");
                 $toPlaylistXml->addChild("total_results", $totalResults);
                 $toFiltersXml = $toPlaylistXml->addChild("filters");
                 foreach ($fromFiltersList as $filterXML) {
                     $entryFilter = new entryFilter();
                     $entryFilter->fillObjectFromXml($filterXML, "_");
                     if (isset($entryFilter->fields["_matchand_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchand_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchand_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_matchor_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchor_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchor_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_in_category_ancestor_id"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_in_category_ancestor_id"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_in_category_ancestor_id"] = implode(",", $newCategoriesIds);
                     }
                     $toEntryFilterXML = $toFiltersXml->addChild("filter");
                     $toEntryFilterXML = $entryFilter->toXml($toEntryFilterXML);
                 }
                 $newEntry->setDataContent($toPlaylistXml->asXML());
                 break;
         }
     }
     // copy relationships to categories
     KalturaLog::debug('Copy relationships to categories from entry [' . $entry->getId() . '] to entry [' . $newEntry->getId() . ']');
     $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS);
     $c->addAnd(categoryEntryPeer::ENTRY_ID, $entry->getId());
     $c->addAnd(categoryEntryPeer::STATUS, CategoryEntryStatus::ACTIVE, Criteria::EQUAL);
     $c->addAnd(categoryEntryPeer::PARTNER_ID, $entry->getPartnerId());
     categoryEntryPeer::setUseCriteriaFilter(false);
     $categoryEntries = categoryEntryPeer::doSelect($c);
     categoryEntryPeer::setUseCriteriaFilter(true);
     // Create srcCategoryIdToDstCategoryIdMap - a map of source partner category ids -> dst. partner category ids
     //
     // Build src category IDs set
     $srcCategoryIdSet = array();
     foreach ($categoryEntries as $categoryEntry) {
         $srcCategoryIdSet[] = $categoryEntry->getCategoryId();
     }
     $illegalCategoryStatus = array(CategoryStatus::DELETED, CategoryStatus::PURGED);
     // Get src category objects
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $srcCategoryIdSet, Criteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $entry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $srcCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     // Map the category names to their IDs
     $fullNamesToSrcCategoryIdMap = array();
     foreach ($srcCategories as $category) {
         $fullNamesToSrcCategoryIdMap[$category->getFullName()] = $category->getId();
     }
     // Get dst. partner categories based on src. category full-names
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::FULL_NAME, array_keys($fullNamesToSrcCategoryIdMap), KalturaCriteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $dstCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     $srcCategoryIdToDstCategoryIdMap = array();
     foreach ($dstCategories as $dstCategory) {
         $fullName = $dstCategory->getFullName();
         if (array_key_exists($fullName, $fullNamesToSrcCategoryIdMap)) {
             $srcCategoryId = $fullNamesToSrcCategoryIdMap[$fullName];
             $srcCategoryIdToDstCategoryIdMap[$srcCategoryId] = $dstCategory->getId();
         }
     }
     foreach ($categoryEntries as $categoryEntry) {
         /* @var $categoryEntry categoryEntry */
         $newCategoryEntry = $categoryEntry->copy();
         $newCategoryEntry->setPartnerId($newEntry->getPartnerId());
         $newCategoryEntry->setEntryId($newEntry->getId());
         $srcCategoryId = $categoryEntry->getCategoryId();
         if (!array_key_exists($srcCategoryId, $srcCategoryIdToDstCategoryIdMap)) {
             continue;
             // Skip the category_entry's creation
         }
         $dstCategoryId = $srcCategoryIdToDstCategoryIdMap[$srcCategoryId];
         $newCategoryEntry->setCategoryId($dstCategoryId);
         categoryPeer::setUseCriteriaFilter(false);
         entryPeer::setUseCriteriaFilter(false);
         $newCategoryEntry->save();
         entryPeer::setUseCriteriaFilter(true);
         categoryPeer::setUseCriteriaFilter(true);
     }
     return $newEntry;
 }
 private function updateCategroy($isDelete = false)
 {
     categoryPeer::setUseCriteriaFilter(false);
     $category = categoryPeer::retrieveByPK($this->category_id);
     categoryPeer::setUseCriteriaFilter(true);
     if (!$category) {
         throw new kCoreException('category not found');
     }
     if ($this->isNew()) {
         if ($this->status == CategoryKuserStatus::PENDING) {
             $category->setPendingMembersCount($category->getPendingMembersCount() + 1);
         }
         if ($this->status == CategoryKuserStatus::ACTIVE) {
             $category->setMembersCount($category->getMembersCount() + 1);
         }
         $category->save();
     } elseif ($this->isColumnModified(categoryKuserPeer::STATUS)) {
         if ($this->status == CategoryKuserStatus::PENDING) {
             $category->setPendingMembersCount($category->getPendingMembersCount() + 1);
         }
         if ($this->status == CategoryKuserStatus::ACTIVE) {
             $category->setMembersCount($category->getMembersCount() + 1);
         }
         if ($this->old_status == CategoryKuserStatus::PENDING) {
             $category->setPendingMembersCount($category->getPendingMembersCount() - 1);
         }
         if ($this->old_status == CategoryKuserStatus::ACTIVE) {
             $category->setMembersCount($category->getMembersCount() - 1);
         }
         $category->save();
     }
     if ($isDelete) {
         if ($this->status == CategoryKuserStatus::PENDING) {
             $category->setPendingMembersCount($category->getPendingMembersCount() - 1);
         }
         if ($this->status == CategoryKuserStatus::ACTIVE) {
             $category->setMembersCount($category->getMembersCount() - 1);
         }
         $category->save();
     }
     $this->addIndexCategoryInheritedTreeJob($category->getFullIds());
     $category->indexToSearchIndex();
 }
Esempio n. 6
0
 public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false)
 {
     KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]");
     $newEntry = $entry->copy();
     $newEntry->setIntId(null);
     $newEntry->setCategories(null);
     $newEntry->setCategoriesIds(null);
     if ($toPartner instanceof Partner) {
         $newEntry->setPartnerId($toPartner->getId());
         $newEntry->setSubpId($toPartner->getId() * 100);
         $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId());
     }
     $newKuser = null;
     if (!$dontCopyUsers) {
         // copy the kuser (if the same puser id exists its kuser will be used)
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = $entry->getKuser();
         $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId());
         $newEntry->setKuserId($newKuser->getId());
         $newEntry->setCreatorKuserId($newKuser->getId());
         kuserPeer::setUseCriteriaFilter(true);
     }
     // copy the kshow
     kshowPeer::setUseCriteriaFilter(false);
     $kshow = $entry->getKshow();
     if ($kshow) {
         $newKshow = $kshow->copy();
         $newKshow->setIntId(null);
         $newKshow->setPartnerId($toPartner->getId());
         $newKshow->setSubpId($toPartner->getId() * 100);
         if ($newKuser) {
             $newKshow->setProducerId($newKuser->getId());
         }
         $newKshow->save();
         $newEntry->setKshowId($newKshow->getId());
     }
     kshowPeer::setUseCriteriaFilter(true);
     // reset the statistics
     myEntryUtils::resetEntryStatistics($newEntry);
     // set the new partner id into the default category criteria filter
     $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter();
     $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     // save the entry
     $newEntry->save();
     // restore the original partner id in the default category criteria filter
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId);
     KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created");
     // for any type that does not require assets:
     $shouldCopyDataForNonClip = true;
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         $shouldCopyDataForNonClip = false;
     }
     if ($entry->getType() == entryType::PLAYLIST) {
         $shouldCopyDataForNonClip = false;
     }
     $shouldCopyDataForClip = false;
     // only images get their data copied
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $shouldCopyDataForClip = true;
         }
     }
     //if entry is a static playlist, link between it and its new child entries
     if ($entry->getType() == entryType::PLAYLIST) {
         switch ($entry->getMediaType()) {
             case entry::ENTRY_MEDIA_TYPE_TEXT:
                 $from = $entry->getDataContent();
                 KalturaLog::debug("Entries to copy from source static playlist: [{$from}]");
                 $fromEntryIds = explode(",", $from);
                 $toEntryIds = array();
                 foreach ($fromEntryIds as $fromEntryId) {
                     $toEntryIds[] = kObjectCopyHandler::getMappedId(entryPeer::OM_CLASS, $fromEntryId);
                 }
                 $newEntry->setDataContent(implode(",", $toEntryIds));
                 break;
             case entry::ENTRY_MEDIA_TYPE_XML:
                 list($totalResults, $fromFiltersList) = myPlaylistUtils::getPlaylistFilterListStruct($entry->getDataContent());
                 $toPlaylistXml = new SimpleXMLElement("<playlist/>");
                 $toPlaylistXml->addChild("total_results", $totalResults);
                 $toFiltersXml = $toPlaylistXml->addChild("filters");
                 foreach ($fromFiltersList as $filterXML) {
                     $entryFilter = new entryFilter();
                     $entryFilter->fillObjectFromXml($filterXML, "_");
                     if (isset($entryFilter->fields["_matchand_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchand_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchand_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_matchor_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchor_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchor_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_in_category_ancestor_id"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_in_category_ancestor_id"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_in_category_ancestor_id"] = implode(",", $newCategoriesIds);
                     }
                     $toEntryFilterXML = $toFiltersXml->addChild("filter");
                     $toEntryFilterXML = $entryFilter->toXml($toEntryFilterXML);
                 }
                 $newEntry->setDataContent($toPlaylistXml->asXML());
                 break;
         }
     }
     if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) {
         // copy the data
         $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]");
         kFileSyncUtils::softCopy($from, $to);
     }
     $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     if (kFileSyncUtils::fileSync_exists($ismFrom)) {
         $ismTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
         KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]");
         kFileSyncUtils::softCopy($ismFrom, $ismTo);
     }
     $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($ismcFrom)) {
         $ismcTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
         KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]");
         kFileSyncUtils::softCopy($ismcFrom, $ismcTo);
     }
     $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     // replaced__getThumbnailPath
     $considerCopyThumb = true;
     // if entry is image - data is thumbnail, and it was copied
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $considerCopyThumb = false;
     }
     // if entry is not clip, and there is no file in both DCs - nothing to copy
     if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) {
         $considerCopyThumb = false;
     }
     if ($considerCopyThumb) {
         $skipThumb = false;
         // don't attempt to copy a thumbnail for images - it's the same as the data which was just created
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             // check if audio entry has real thumb, if not - don't copy thumb.
             $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false);
             if (!$originalFileSync) {
                 $skipThumb = true;
             }
         }
         if (!$skipThumb) {
             $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             // replaced__getThumbnailPath
             KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]");
             kFileSyncUtils::softCopy($from, $to);
         }
     }
     // added by Tan-Tan 12/01/2010 to support falvors copy
     $sourceAssets = assetPeer::retrieveByEntryId($entry->getId());
     foreach ($sourceAssets as $sourceAsset) {
         $sourceAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId());
     }
     // copy relationships to categories
     KalturaLog::debug('Copy relationships to categories from entry [' . $entry->getId() . '] to entry [' . $newEntry->getId() . ']');
     $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS);
     $c->addAnd(categoryEntryPeer::ENTRY_ID, $entry->getId());
     $c->addAnd(categoryEntryPeer::STATUS, CategoryEntryStatus::ACTIVE, Criteria::EQUAL);
     $c->addAnd(categoryEntryPeer::PARTNER_ID, $entry->getPartnerId());
     categoryEntryPeer::setUseCriteriaFilter(false);
     $categoryEntries = categoryEntryPeer::doSelect($c);
     categoryEntryPeer::setUseCriteriaFilter(true);
     // Create srcCategoryIdToDstCategoryIdMap - a map of source partner category ids -> dst. partner category ids
     //
     // Build src category IDs set
     $srcCategoryIdSet = array();
     foreach ($categoryEntries as $categoryEntry) {
         $srcCategoryIdSet[] = $categoryEntry->getCategoryId();
     }
     $illegalCategoryStatus = array(CategoryStatus::DELETED, CategoryStatus::PURGED);
     // Get src category objects
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $srcCategoryIdSet, Criteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $entry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $srcCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     // Map the category names to their IDs
     $fullNamesToSrcCategoryIdMap = array();
     foreach ($srcCategories as $category) {
         $fullNamesToSrcCategoryIdMap[$category->getFullName()] = $category->getId();
     }
     // Get dst. partner categories based on src. category full-names
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::FULL_NAME, array_keys($fullNamesToSrcCategoryIdMap), KalturaCriteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $dstCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     $srcCategoryIdToDstCategoryIdMap = array();
     foreach ($dstCategories as $dstCategory) {
         $fullName = $dstCategory->getFullName();
         if (array_key_exists($fullName, $fullNamesToSrcCategoryIdMap)) {
             $srcCategoryId = $fullNamesToSrcCategoryIdMap[$fullName];
             $srcCategoryIdToDstCategoryIdMap[$srcCategoryId] = $dstCategory->getId();
         }
     }
     foreach ($categoryEntries as $categoryEntry) {
         /* @var $categoryEntry categoryEntry */
         $newCategoryEntry = $categoryEntry->copy();
         $newCategoryEntry->setPartnerId($newEntry->getPartnerId());
         $newCategoryEntry->setEntryId($newEntry->getId());
         $srcCategoryId = $categoryEntry->getCategoryId();
         if (!array_key_exists($srcCategoryId, $srcCategoryIdToDstCategoryIdMap)) {
             continue;
             // Skip the category_entry's creation
         }
         $dstCategoryId = $srcCategoryIdToDstCategoryIdMap[$srcCategoryId];
         $newCategoryEntry->setCategoryId($dstCategoryId);
         categoryPeer::setUseCriteriaFilter(false);
         entryPeer::setUseCriteriaFilter(false);
         $newCategoryEntry->save();
         entryPeer::setUseCriteriaFilter(true);
         categoryPeer::setUseCriteriaFilter(true);
     }
     return $newEntry;
 }
 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();
     }
 }
Esempio n. 8
0
 /**
  * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
  *
  * This will only work if the object has been saved and has a valid primary key set.
  *
  * @param      boolean $deep (optional) Whether to also de-associated any related objects.
  * @param      PropelPDO $con (optional) The PropelPDO connection to use.
  * @return     void
  * @throws     PropelException - if this object is deleted, unsaved or doesn't have pk match in db
  */
 public function reload($deep = false, PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("Cannot reload a deleted object.");
     }
     if ($this->isNew()) {
         throw new PropelException("Cannot reload an unsaved object.");
     }
     if ($con === null) {
         $con = Propel::getConnection(categoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     // We don't need to alter the object instance pool; we're just modifying this instance
     // already in the pool.
     categoryPeer::setUseCriteriaFilter(false);
     $stmt = categoryPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
     categoryPeer::setUseCriteriaFilter(true);
     $row = $stmt->fetch(PDO::FETCH_NUM);
     $stmt->closeCursor();
     if (!$row) {
         throw new PropelException('Cannot find matching row in the database to reload object values.');
     }
     $this->hydrate($row, 0, true);
     // rehydrate
     if ($deep) {
         // also de-associate any related objects?
         $this->collcategoryKusers = null;
         $this->lastcategoryKuserCriteria = null;
     }
     // if (deep)
 }
 /**
  * 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);
     }
 }
Esempio n. 10
0
<?php

chdir(dirname(__FILE__));
require_once __DIR__ . '/../../bootstrap.php';
$c = new Criteria();
if ($argc > 1 && is_numeric($argv[1])) {
    $c->add(categoryPeer::UPDATED_AT, $argv[1], Criteria::GREATER_EQUAL);
}
if ($argc > 2 && is_numeric($argv[2])) {
    $c->add(categoryPeer::PARTNER_ID, $argv[2], Criteria::EQUAL);
}
if ($argc > 3 && is_numeric($argv[3])) {
    $c->add(categoryPeer::ID, $argv[3], Criteria::GREATER_EQUAL);
}
if ($argc > 4) {
    categoryPeer::setUseCriteriaFilter((bool) $argv[4]);
}
$c->addAscendingOrderByColumn(categoryPeer::UPDATED_AT);
$c->addAscendingOrderByColumn(categoryPeer::ID);
$c->setLimit(10000);
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2);
//$sphinxCon = DbManager::getSphinxConnection();
$categories = categoryPeer::doSelect($c, $con);
$sphinx = new kSphinxSearchManager();
while (count($categories)) {
    foreach ($categories as $category) {
        /* @var $category Category */
        KalturaLog::log('category id ' . $category->getId() . ' int id[' . $category->getIntId() . '] crc id[' . $sphinx->getSphinxId($category) . '] last updated at [' . $category->getUpdatedAt(null) . ']');
        try {
            $ret = $sphinx->saveToSphinx($category, true);
        } catch (Exception $e) {
 /**
  * Return all categories kuser is entitled to view the content.
  * (User may call category->get to view a category - but not to view its content)
  * 
  * @param int $kuserId
  * @param int $limit
  * @return array<categories>
  */
 public static function retrieveEntitledAndNonIndexedByKuser($kuserId, $limit)
 {
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $partner = PartnerPeer::retrieveByPK($partnerId);
     $categoryGroupSize = category::MAX_NUMBER_OF_MEMBERS_TO_BE_INDEXED_ON_ENTRY;
     if ($partner && $partner->getCategoryGroupSize()) {
         $categoryGroupSize = $partner->getCategoryGroupSize();
     }
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $filteredCategoriesIds = entryPeer::getFilterdCategoriesIds();
     if (count($filteredCategoriesIds)) {
         $c->addAnd(categoryPeer::ID, $filteredCategoriesIds, Criteria::IN);
     }
     $membersCountCrit = $c->getNewCriterion(categoryPeer::MEMBERS_COUNT, $categoryGroupSize, Criteria::GREATER_THAN);
     $membersCountCrit->addOr($c->getNewCriterion(categoryPeer::ENTRIES_COUNT, entry::CATEGORY_ENTRIES_COUNT_LIMIT_TO_BE_INDEXED, Criteria::GREATER_THAN));
     $c->addAnd($membersCountCrit);
     $c->setLimit($limit);
     $c->addDescendingOrderByColumn(categoryPeer::UPDATED_AT);
     //all fields needed from default criteria
     //here we cannot use the default criteria, as we need to get all categories user is entitled to view the content.
     //not deleted or purged
     $c->add(self::STATUS, array(CategoryStatus::DELETED, CategoryStatus::PURGED), Criteria::NOT_IN);
     $c->add(self::PARTNER_ID, $partnerId, Criteria::EQUAL);
     //add privacy context
     $privacyContextCrit = $c->getNewCriterion(self::PRIVACY_CONTEXTS, kEntitlementUtils::getKsPrivacyContext(), KalturaCriteria::IN_LIKE);
     $privacyContextCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $c->addAnd($privacyContextCrit);
     //set privacy by ks and type
     $crit = $c->getNewCriterion(self::PRIVACY, kEntitlementUtils::getPrivacyForKs(), Criteria::IN);
     $crit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     //user is entitled to view all cantent that belong to categoires he is a membr of
     $kuser = null;
     $ksString = kCurrentContext::$ks ? kCurrentContext::$ks : '';
     if ($ksString != '') {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $kuser = kuserPeer::getActiveKuserByPartnerAndUid($partnerId, kCurrentContext::$ks_uid);
     }
     if ($kuser) {
         $membersCrit = $c->getNewCriterion(self::MEMBERS, $kuser->getId(), Criteria::LIKE);
         $membersCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $crit->addOr($membersCrit);
     }
     $c->addAnd($crit);
     categoryPeer::setUseCriteriaFilter(false);
     $categories = self::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     return $categories;
 }
Esempio n. 12
0
 /**
  * Code to be run after inserting to database
  * @param PropelPDO $con 
  */
 public function postInsert(PropelPDO $con = null)
 {
     categoryPeer::setUseCriteriaFilter(false);
     $this->reload();
     categoryPeer::setUseCriteriaFilter(true);
     kEventsManager::raiseEvent(new kObjectCreatedEvent($this));
     if ($this->copiedFrom) {
         kEventsManager::raiseEvent(new kObjectCopiedEvent($this->copiedFrom, $this));
     }
 }