public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if ($this->userIdIn) {
         $usersIds = explode(',', $this->userIdIn);
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
         $c->add(kuserPeer::PUSER_ID, $usersIds, Criteria::IN);
         $kusers = kuserPeer::doSelect($c);
         $usersIds = array();
         foreach ($kusers as $kuser) {
             /* @var $kuser kuser */
             $usersIds[] = $kuser->getId();
         }
         $this->userIdIn = implode(',', $usersIds);
     }
     if ($this->relatedGroupsByUserId) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $userIds = array();
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId);
         $c->add(kuserPeer::PUSER_ID, $this->relatedGroupsByUserId);
         $c->add(kuserPeer::TYPE, KuserType::USER);
         $kuser = kuserPeer::doSelectOne($c);
         if (!$kuser) {
             $response = new KalturaCategoryUserListResponse();
             $response->objects = new KalturaCategoryUserArray();
             $response->totalCount = 0;
             return $response;
         }
         $kgroupIds = KuserKgroupPeer::retrieveKgroupIdsByKuserId($kuser->getId());
         if (!is_null($kgroupIds) && is_array($kgroupIds)) {
             $userIds = $kgroupIds;
         }
         $userIds[] = $kuser->getId();
         // if userIdIn is also set in the filter need to intersect the two arrays.
         if (isset($this->userIdIn)) {
             $curUserIds = explode(',', $this->userIdIn);
             $userIds = array_intersect($curUserIds, $userIds);
         }
         $this->userIdIn = implode(',', $userIds);
     }
     if ($this->userIdEqual) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId);
         $c->add(kuserPeer::PUSER_ID, $this->userIdEqual);
         if (kCurrentContext::$ks_partner_id == Partner::BATCH_PARTNER_ID) {
             //batch should be able to get categoryUser of deleted users.
             kuserPeer::setUseCriteriaFilter(false);
         }
         // in case of more than one deleted kusers - get the last one
         $c->addDescendingOrderByColumn(kuserPeer::UPDATED_AT);
         $kuser = kuserPeer::doSelectOne($c);
         kuserPeer::setUseCriteriaFilter(true);
         if (!$kuser) {
             KalturaLog::debug('User not found');
             $response = new KalturaCategoryUserListResponse();
             $response->objects = new KalturaCategoryUserArray();
             $response->totalCount = 0;
             return $response;
         }
         $this->userIdEqual = $kuser->getId();
     }
     $categories = array();
     if ($this->categoryIdEqual) {
         $categories[] = categoryPeer::retrieveByPK($this->categoryIdEqual);
     } elseif ($this->categoryIdIn) {
         $categories = categoryPeer::retrieveByPKs(explode(',', $this->categoryIdIn));
     }
     $categoriesInheritanceRoot = array();
     foreach ($categories as $category) {
         /* @var $category category */
         if (is_null($category)) {
             continue;
         }
         if ($category->getInheritanceType() == InheritanceType::INHERIT) {
             if ($this->categoryDirectMembers && kCurrentContext::$master_partner_id == Partner::BATCH_PARTNER_ID) {
                 $categoriesInheritanceRoot[$category->getId()] = $category->getId();
             } else {
                 //if category inheris members - change filter to -> inherited from parent id = category->getIheritedParent
                 $categoriesInheritanceRoot[$category->getInheritedParentId()] = $category->getInheritedParentId();
             }
         } else {
             $categoriesInheritanceRoot[$category->getId()] = $category->getId();
         }
     }
     $this->categoryDirectMembers = null;
     $this->categoryIdEqual = null;
     $this->categoryIdIn = implode(',', $categoriesInheritanceRoot);
     //if filter had categories that doesn't exists or not entitled - should return 0 objects.
     if (count($categories) && !count($categoriesInheritanceRoot)) {
         $response = new KalturaCategoryUserListResponse();
         $response->totalCount = 0;
         return $response;
     }
     $categoryKuserFilter = $this->toObject();
     $c = KalturaCriteria::create(categoryKuserPeer::OM_CLASS);
     $categoryKuserFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $c->applyFilters();
     $list = categoryKuserPeer::doSelect($c);
     $totalCount = $c->getRecordsCount();
     $newList = KalturaCategoryUserArray::fromDbArray($list, $responseProfile);
     $response = new KalturaCategoryUserListResponse();
     $response->objects = $newList;
     $response->totalCount = $totalCount;
     return $response;
 }
Exemple #2
0
 /**
  * Gets an array of categoryKuser objects which contain a foreign key that references this object.
  *
  * If this collection has already been initialized with an identical Criteria, it returns the collection.
  * Otherwise if this kuser has previously been saved, it will retrieve
  * related categoryKusers from storage. If this kuser is new, it will return
  * an empty collection or the current collection, the criteria is ignored on a new object.
  *
  * @param      PropelPDO $con
  * @param      Criteria $criteria
  * @return     array categoryKuser[]
  * @throws     PropelException
  */
 public function getcategoryKusers($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(kuserPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collcategoryKusers === null) {
         if ($this->isNew()) {
             $this->collcategoryKusers = array();
         } else {
             $criteria->add(categoryKuserPeer::KUSER_ID, $this->id);
             categoryKuserPeer::addSelectColumns($criteria);
             $this->collcategoryKusers = categoryKuserPeer::doSelect($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return the collection.
             $criteria->add(categoryKuserPeer::KUSER_ID, $this->id);
             categoryKuserPeer::addSelectColumns($criteria);
             if (!isset($this->lastcategoryKuserCriteria) || !$this->lastcategoryKuserCriteria->equals($criteria)) {
                 $this->collcategoryKusers = categoryKuserPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastcategoryKuserCriteria = $criteria;
     return $this->collcategoryKusers;
 }
    $c->add(categoryKuserPeer::UPDATED_AT, $argv[1], Criteria::GREATER_EQUAL);
}
if ($argc > 2 && is_numeric($argv[2])) {
    $c->add(categoryKuserPeer::PARTNER_ID, $argv[2], Criteria::EQUAL);
}
if ($argc > 3 && is_numeric($argv[3])) {
    $c->add(categoryKuserPeer::ID, $argv[3], Criteria::GREATER_EQUAL);
}
$c->addAscendingOrderByColumn(categoryKuserPeer::UPDATED_AT);
$c->addAscendingOrderByColumn(categoryKuserPeer::ID);
$c->setLimit(10000);
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2);
//$sphinxCon = DbManager::getSphinxConnection();
$categoryKusers = categoryKuserPeer::doSelect($c, $con);
$sphinx = new kSphinxSearchManager();
while (count($categoryKusers)) {
    foreach ($categoryKusers as $categoryKuser) {
        /* @var $categoryKuser categoryKuser */
        KalturaLog::log('$categoryKuser id ' . $categoryKuser->getId() . ' updated at ' . $categoryKuser->getUpdatedAt(null));
        try {
            $ret = $sphinx->saveToSphinx($categoryKuser, true);
        } catch (Exception $e) {
            KalturaLog::err($e->getMessage());
            exit - 1;
        }
    }
    $c->setOffset($c->getOffset() + count($categoryKusers));
    kMemoryManager::clearMemory();
    $categoryKusers = categoryKuserPeer::doSelect($c, $con);
}
KalturaLog::log('Done. Current time: ' . time());
 /**
  * 
  * @param int $categoryId
  * @param int $kuserId
  * @param $con
  * 
  * @return array
  */
 public static function retrieveActiveKusersByCategoryId($categoryId, $con = null)
 {
     $criteria = new Criteria();
     $criteria->add(categoryKuserPeer::CATEGORY_ID, $categoryId);
     $criteria->add(categoryKuserPeer::STATUS, CategoryKuserStatus::ACTIVE);
     return categoryKuserPeer::doSelect($criteria, $con);
 }
 /**
  * List all categories
  * 
  * @action list
  * @param KalturaCategoryUserFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaCategoryUserListResponse
  * @throws KalturaErrors::MUST_FILTER_USERS_OR_CATEGORY
  */
 function listAction(KalturaCategoryUserFilter $filter = null, KalturaFilterPager $pager = null)
 {
     if (!($filter->categoryIdEqual || $filter->categoryIdIn || $filter->userIdIn || $filter->userIdEqual)) {
         throw new KalturaAPIException(KalturaErrors::MUST_FILTER_USERS_OR_CATEGORY);
     }
     if (!$filter) {
         $filter = new KalturaCategoryUserFilter();
     }
     if (!$pager) {
         $pager = new kalturaFilterPager();
     }
     if ($filter->userIdIn) {
         $usersIds = explode(',', $filter->userIdIn);
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
         $c->add(kuserPeer::PUSER_ID, $usersIds, Criteria::IN);
         $kusers = kuserPeer::doSelect($c);
         $usersIds = array();
         foreach ($kusers as $kuser) {
             $usersIds[] = $kuser->getId();
         }
         $filter->userIdIn = implode(',', $usersIds);
     }
     if ($filter->userIdEqual) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId);
         $c->add(kuserPeer::PUSER_ID, $filter->userIdEqual);
         $c->add(kuserPeer::STATUS, KuserStatus::ACTIVE);
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = kuserPeer::doSelectOne($c);
         kuserPeer::setUseCriteriaFilter(true);
         //batch should be abke to get categoryUser of deleted users.
         if (!$kuser || $kuser->getStatus() != KuserStatus::ACTIVE && kCurrentContext::$ks_partner_id != Partner::BATCH_PARTNER_ID) {
             KalturaLog::debug('User not found');
             $response = new KalturaCategoryUserListResponse();
             $response->objects = new KalturaCategoryUserArray();
             $response->totalCount = 0;
             return $response;
         }
         $filter->userIdEqual = $kuser->getId();
     }
     $categories = array();
     if ($filter->categoryIdEqual) {
         $categories[] = categoryPeer::retrieveByPK($filter->categoryIdEqual);
     } elseif ($filter->categoryIdIn) {
         $categories = categoryPeer::retrieveByPKs(explode(',', $filter->categoryIdIn));
     }
     $categoriesInheritanceRoot = array();
     foreach ($categories as $category) {
         if (is_null($category)) {
             continue;
         }
         if ($category->getInheritanceType() == InheritanceType::INHERIT) {
             if ($filter->categoryDirectMembers && kCurrentContext::$master_partner_id == Partner::BATCH_PARTNER_ID) {
                 $categoriesInheritanceRoot[$category->getId()] = $category->getId();
             } else {
                 //if category inheris members - change filter to -> inherited from parent id = category->getIheritedParent
                 $categoriesInheritanceRoot[$category->getInheritedParentId()] = $category->getInheritedParentId();
             }
         } else {
             $categoriesInheritanceRoot[$category->getId()] = $category->getId();
         }
     }
     $filter->categoryDirectMembers = null;
     $filter->categoryIdEqual = null;
     $filter->categoryIdIn = implode(',', $categoriesInheritanceRoot);
     //if filter had categories that doesn't exists or not entitled - should return 0 objects.
     if (count($categories) && !count($categoriesInheritanceRoot)) {
         $response = new KalturaCategoryUserListResponse();
         $response->totalCount = 0;
         return $response;
     }
     $categoryKuserFilter = new categoryKuserFilter();
     $filter->toObject($categoryKuserFilter);
     $c = KalturaCriteria::create(categoryKuserPeer::OM_CLASS);
     $categoryKuserFilter->attachToCriteria($c);
     $c->applyFilters();
     $totalCount = categoryKuserPeer::doCount($c);
     $pager->attachToCriteria($c);
     $list = categoryKuserPeer::doSelect($c);
     $newList = KalturaCategoryUserArray::fromDbArray($list);
     $response = new KalturaCategoryUserListResponse();
     $response->objects = $newList;
     $response->totalCount = $totalCount;
     return $response;
 }
 /**
  * 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(categoryKuserPeer::DATABASE_NAME);
         $criteria->add(categoryKuserPeer::ID, $pks, Criteria::IN);
         $objs = categoryKuserPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
    KalturaLog::info("Migrating [" . count($categoryKusers) . "] categories.");
    foreach ($categoryKusers as $categoryKuser) {
        $categoryKuser = cast($categoryKuser, 'MigrationCategoryKuser');
        /* @var $categoryKuser categoryKuser */
        $categoryKuser->reSetScreenName();
        KalturaStatement::setDryRun($dryRun);
        $categoryKuser->save();
        KalturaStatement::setDryRun(false);
        $startCategoryKuserId = $categoryKuser->getId();
        KalturaLog::info("Migrated categoryKuser [{$startCategoryKuserId}].");
    }
    kEventsManager::flushEvents();
    kMemoryManager::clearMemory();
    $nextCriteria = clone $criteria;
    $nextCriteria->add(categoryKuserPeer::ID, $startCategoryKuserId, Criteria::GREATER_THAN);
    $categoryKusers = categoryKuserPeer::doSelect($nextCriteria);
    usleep(100);
}
KalturaLog::info("Done");
function cast($object, $toClass)
{
    if (class_exists($toClass)) {
        $objectIn = serialize($object);
        $obj_name_len = strlen(get_class($object));
        $objectOut = 'O:' . strlen($toClass) . ':"' . $toClass . '":' . substr($objectIn, $obj_name_len + strlen($obj_name_len) + 6);
        $ret = unserialize($objectOut);
        if ($ret instanceof $toClass) {
            return $ret;
        }
    } else {
        KalturaLog::debug('Class doesnt exists' . print_r($toClass, true));