Esempio n. 1
0
 /**
  * Get categories by full name using full name wildcard match (returns an array)
  *  
  * @param $partnerId
  * @param $fullName
  * @param $con
  * @return array
  */
 public static function getByFullNameWildcardMatch($fullName, $con = null)
 {
     $fullName = str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $fullName);
     $c = new Criteria();
     $c->add(categoryPeer::FULL_NAME, $fullName . "%", Criteria::LIKE);
     return categoryPeer::doSelect($c, $con);
 }
Esempio n. 2
0
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if ($this->orderBy === null) {
         $this->orderBy = KalturaCategoryOrderBy::DEPTH_ASC;
     }
     $categoryFilter = $this->toObject();
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $categoryFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $dbList = categoryPeer::doSelect($c);
     $totalCount = $c->getRecordsCount();
     $list = KalturaCategoryArray::fromDbArray($dbList, $responseProfile);
     $response = new KalturaCategoryListResponse();
     $response->objects = $list;
     $response->totalCount = $totalCount;
     return $response;
 }
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
 /**
  * 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 = KalturaCriteria::create(categoryPeer::OM_CLASS);
         $criteria->add(categoryPeer::ID, $pks, Criteria::IN);
         $objs = categoryPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * 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(categoryPeer::DATABASE_NAME);
         $criteria->add(categoryPeer::ID, $pks, Criteria::IN);
         $objs = categoryPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
}
$countLimitEachLoop = 200;
//------------------------------------------------------
require_once dirname(__FILE__) . '/../bootstrap.php';
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2);
KalturaStatement::setDryRun($dryRun);
$lastCategoryId = 0;
while (1) {
    $c = new Criteria();
    $c->add(categoryPeer::STATUS, CategoryStatus::ACTIVE, Criteria::EQUAL);
    $c->add(categoryPeer::ID, $lastCategoryId, Criteria::GREATER_THAN);
    $c->add(categoryPeer::PRIVACY_CONTEXTS, null, Criteria::ISNOTNULL);
    $c->add(categoryPeer::PRIVACY_CONTEXTS, '', Criteria::NOT_EQUAL);
    $c->addAscendingOrderByColumn(categoryPeer::ID);
    $c->setLimit($countLimitEachLoop);
    $categories = categoryPeer::doSelect($c, $con);
    if (!count($categories)) {
        break;
    }
    foreach ($categories as $category) {
        /* @var $category category */
        KalturaLog::debug('Category [' . $category->getId() . ']');
        $lastCategoryEntryId = 0;
        while (1) {
            $c = new Criteria();
            $c->add(categoryEntryPeer::CATEGORY_ID, $category->getId(), Criteria::EQUAL);
            $c->add(categoryEntryPeer::STATUS, CategoryEntryStatus::ACTIVE, Criteria::EQUAL);
            $c->add(categoryEntryPeer::ID, $lastCategoryEntryId, Criteria::GREATER_THAN);
            $c->addAscendingOrderByColumn(categoryEntryPeer::ID);
            $c->setLimit($countLimitEachLoop);
            $categoryEntries = categoryEntryPeer::doSelect($c, $con);
Esempio n. 7
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;
 }
if ($limit) {
    $criteria->setLimit(min($page, $limit));
} else {
    $criteria->setLimit($page);
}
$entries = entryPeer::doSelect($criteria);
$migrated = 0;
while (count($entries) && (!$limit || $migrated < $limit)) {
    KalturaLog::info("Migrating [" . count($entries) . "] entries.");
    $migrated += count($entries);
    $lastIntId = null;
    foreach ($entries as $entry) {
        /* @var $entry entry */
        $categoriesCriteria = new Criteria();
        $categoriesCriteria->add(categoryPeer::ID, $entry->getCategoriesIds(), Criteria::IN);
        $categories = categoryPeer::doSelect($categoriesCriteria);
        $categoryIds = array();
        foreach ($categories as $category) {
            /* @var $category category */
            $categoryIds[] = $category->getId();
        }
        $categoryEntriesCriteria = new Criteria();
        $categoryEntriesCriteria->addSelectColumn(categoryEntryPeer::CATEGORY_ID);
        $categoryEntriesCriteria->add(categoryEntryPeer::ENTRY_ID, $entry->getId());
        $categoryEntriesCriteria->add(categoryEntryPeer::CATEGORY_ID, $categoryIds, Criteria::IN);
        $stmt = categoryEntryPeer::doSelectStmt($categoryEntriesCriteria);
        $categoryEntriesIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
        KalturaStatement::setDryRun($dryRun);
        foreach ($categories as $category) {
            /* @var $category category */
            $entryId = $entry->getId();
Esempio n. 9
0
 /**
  * @return array
  */
 public function getAllChildren()
 {
     $c = new Criteria();
     $c->add(categoryPeer::FULL_NAME, $this->getFullName() . '%', Criteria::LIKE);
     $c->addAnd(categoryPeer::PARTNER_ID, $this->getPartnerId(), Criteria::EQUAL);
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $categories = categoryPeer::doSelect($c);
     KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     return $categories;
 }
Esempio n. 10
0
 /**
  * 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;
 }
 public static function getPrivacyContextForEntry(entry $entry)
 {
     $privacyContexts = array();
     $entryPrivacy = null;
     $categories = array();
     if (count($entry->getAllCategoriesIds(true))) {
         $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
         KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $c->add(categoryPeer::ID, $entry->getAllCategoriesIds(true), Criteria::IN);
         KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $categories = categoryPeer::doSelect($c);
         KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         foreach ($categories as $category) {
             $categoryPrivacy = $category->getPrivacy();
             $categoryPrivacyContexts = $category->getPrivacyContexts();
             if (!$categoryPrivacyContexts) {
                 $categoryPrivacyContexts = self::DEFAULT_CONTEXT . $entry->getPartnerId();
             }
             $categoryPrivacyContexts = explode(',', $categoryPrivacyContexts);
             foreach ($categoryPrivacyContexts as $categoryPrivacyContext) {
                 if (trim($categoryPrivacyContext) == '') {
                     $categoryPrivacyContext = self::DEFAULT_CONTEXT . $entry->getPartnerId();
                 }
                 if (!isset($privacyContexts[$categoryPrivacyContext]) || $privacyContexts[$categoryPrivacyContext] > $categoryPrivacy) {
                     $privacyContexts[trim($categoryPrivacyContext)] = $categoryPrivacy;
                 }
             }
         }
     }
     //Entry That doesn't assinged to any category is public.
     if (!count($categories)) {
         $privacyContexts[self::DEFAULT_CONTEXT . $entry->getPartnerId()] = PrivacyType::ALL;
     }
     $entryPrivacyContexts = array();
     foreach ($privacyContexts as $categoryPrivacyContext => $Privacy) {
         $entryPrivacyContexts[] = $categoryPrivacyContext . '_' . $Privacy;
     }
     KalturaLog::debug('Privacy by context: ' . print_r($entryPrivacyContexts, true));
     return $entryPrivacyContexts;
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 private static function getCategoriesByIds($categoriesIds)
 {
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $c->add(categoryPeer::ID, $categoriesIds, Criteria::IN);
     KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $c->dontCount();
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $categories = categoryPeer::doSelect($c);
     KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     return $categories;
 }
Esempio n. 14
0
 /**
  * @return array
  */
 public function getChilds()
 {
     if ($this->isNew()) {
         return array();
     }
     $c = new Criteria();
     $c->add(categoryPeer::PARENT_ID, $this->getId());
     return categoryPeer::doSelect($c);
 }
Esempio n. 15
0
ini_set("memory_limit", "256M");
require_once __DIR__ . '/bootstrap.php';
if (!count($argv)) {
    die("No partner_id passed to script!");
}
$partnerId = $argv[1];
var_dump($partnerId);
if (!PartnerPeer::retrieveByPK($partnerId)) {
    die("Please enter a valid partner Id!");
}
$criteria = new Criteria();
$criteria->add(categoryPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
$criteria->setLimit(1000);
$allCats = categoryPeer::doSelect($criteria);
while (count($allCats)) {
    foreach ($allCats as $categoryDb) {
        /* @var $categoryDb category */
        $categoryDb->reSetEntriesCount();
        $categoryDb->reSetDirectSubCategoriesCount();
        $categoryDb->reSetDirectEntriesCount();
        $categoryDb->reSetPendingEntriesCount();
        $categoryDb->reSetPendingMembersCount();
        $categoryDb->save();
    }
    $criteria->setOffset($criteria->getOffset() + count($allCats));
    kMemoryManager::clearMemory();
    usleep(200);
    $allCats = categoryPeer::doSelect($criteria);
}
KalturaLog::log('Done.');
 public function addIndexCategoryInheritedTreeJob($fullIdsStartsWithCategoryId)
 {
     $featureStatusToRemoveIndex = new kFeatureStatus();
     $featureStatusToRemoveIndex->setType(IndexObjectType::CATEGORY);
     $featureStatusesToRemove = array();
     $featureStatusesToRemove[] = $featureStatusToRemoveIndex;
     $filter = new categoryFilter();
     $filter->setFullIdsStartsWith($fullIdsStartsWithCategoryId);
     $filter->setInheritanceTypeEqual(InheritanceType::INHERIT);
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $filter->attachToCriteria($c);
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $categories = categoryPeer::doSelect($c);
     KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     if (count($categories)) {
         kJobsManager::addIndexJob($this->getPartnerId(), IndexObjectType::CATEGORY, $filter, true, $featureStatusesToRemove);
     }
 }
Esempio n. 17
0
 public function getEntitledKusers()
 {
     $entitledKusersPublish = explode(',', $this->getEntitledKusersPublish());
     $entitledKusersEdit = explode(',', $this->getEntitledKusersEdit());
     $entitledKusersNoPrivacyContext = array_merge($entitledKusersPublish, $entitledKusersEdit);
     $entitledKusersNoPrivacyContext[] = $this->getKuserId();
     foreach ($entitledKusersNoPrivacyContext as $key => $value) {
         if (!$value) {
             unset($entitledKusersNoPrivacyContext[$key]);
         }
     }
     $entitledKusers = array();
     if (count(array_unique($entitledKusersNoPrivacyContext))) {
         $entitledKusers[kEntitlementUtils::ENTRY_PRIVACY_CONTEXT] = array_unique($entitledKusersNoPrivacyContext);
     }
     $allCategoriesIds = $this->getAllCategoriesIds(true);
     if (!count($allCategoriesIds)) {
         return kEntitlementUtils::ENTRY_PRIVACY_CONTEXT . '_' . implode(' ' . kEntitlementUtils::ENTRY_PRIVACY_CONTEXT . '_', $entitledKusersNoPrivacyContext);
     }
     $categoryGroupSize = kConf::get('max_number_of_memebrs_to_be_indexed_on_entry');
     $partner = $this->getPartner();
     if ($partner && $partner->getCategoryGroupSize()) {
         $categoryGroupSize = $partner->getCategoryGroupSize();
     }
     //get categories for this entry that have small amount of members.
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $allCategoriesIds, Criteria::IN);
     $c->add(categoryPeer::MEMBERS_COUNT, $categoryGroupSize, Criteria::LESS_EQUAL);
     $c->add(categoryPeer::ENTRIES_COUNT, kConf::get('category_entries_count_limit_to_be_indexed'), Criteria::LESS_EQUAL);
     $c->dontCount();
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $categories = categoryPeer::doSelect($c);
     KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     //get all memebrs
     foreach ($categories as $category) {
         if (!count($category->getMembers())) {
             continue;
         }
         $privacyContexts = explode(',', $category->getPrivacyContexts());
         if (!count($privacyContexts)) {
             $privacyContexts = array(kEntitlementUtils::DEFAULT_CONTEXT . $this->getPartnerId());
         }
         foreach ($privacyContexts as $privacyContext) {
             $privacyContext = trim($privacyContext);
             if (isset($entitledKusers[$privacyContext])) {
                 $entitledKusers[$privacyContext] = array_merge($entitledKusers[$privacyContext], $category->getMembers());
             } else {
                 $entitledKusers[$privacyContext] = $category->getMembers();
             }
         }
     }
     $entitledKusersByContexts = array();
     foreach ($entitledKusers as $privacyContext => $kusers) {
         $entitledKusersByContexts[] = $privacyContext . '_' . implode(' ' . $privacyContext . '_', $kusers);
     }
     return implode(' ', $entitledKusersByContexts);
 }
 /**
  * List all categories
  * 
  * @action list
  * @param KalturaCategoryFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaCategoryListResponse
  */
 function listAction(KalturaCategoryFilter $filter = null, KalturaFilterPager $pager = null)
 {
     if ($filter === null) {
         $filter = new KalturaCategoryFilter();
     }
     if ($pager == null) {
         $pager = new KalturaFilterPager();
         //before falcon we didn’t have a pager for action category->list,
         //and since we added a pager – and remove the limit for partners categories,
         //for backward compatibility this will be the page size.
         $pager->pageIndex = 1;
         $pager->pageSize = partner::MAX_NUMBER_OF_CATEGORIES;
         KalturaCriteria::setMaxRecords(partner::MAX_NUMBER_OF_CATEGORIES);
         baseObjectFilter::setMaxInValues(partner::MAX_NUMBER_OF_CATEGORIES);
     }
     if ($filter->orderBy === null) {
         $filter->orderBy = KalturaCategoryOrderBy::DEPTH_ASC;
     }
     $categoryFilter = new categoryFilter();
     $filter->toObject($categoryFilter);
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $categoryFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $dbList = categoryPeer::doSelect($c);
     $totalCount = $c->getRecordsCount();
     $list = KalturaCategoryArray::fromCategoryArray($dbList);
     $response = new KalturaCategoryListResponse();
     $response->objects = $list;
     $response->totalCount = $totalCount;
     return $response;
 }