public function execute() { $this->forceSystemAuthentication(); $source_kshow_id = $this->getP("source_kshow_id"); $target_kshow_id = $this->getP("target_kshow_id"); $kuser_names = $this->getP("kuser_names"); $reset = $this->getP("reset"); if ($reset) { $source_kshow_id = null; $target_kshow_id = null; $kuser_names = null; } $mode = 0; // view if ($source_kshow_id && $target_kshow_id && $kuser_names) { $mode = 1; // review $list_of_kuser_names = explode(",", $kuser_names); foreach ($list_of_kuser_names as &$name) { $name = trim($name); } $source_kshow = kshowPeer::retrieveByPK($source_kshow_id); $target_kshow = kshowPeer::retrieveByPK($target_kshow_id); $target_partner_id = $target_kshow->getPartnerId(); $target_subp_id = $target_kshow->getSubpId(); $c = new Criteria(); // select only the kusers of the correct partner_id $c->add(kuserPeer::SCREEN_NAME, $list_of_kuser_names, Criteria::IN); $c->setLimit(10); //$c->add ( kuserPeer::PARTNER_ID , $target_partner_id ); $list_of_kusers = kuserPeer::doSelect($c); $producer = kuserPeer::retrieveByPK($target_kshow->getProducerId()); $list_of_kusers[] = $producer; $c->add(kuserPeer::PARTNER_ID, $target_partner_id); $list_of_valid_kusers = kuserPeer::doSelect($c); $list_of_valid_kusers[] = $producer; $c = new Criteria(); $c->add(entryPeer::KSHOW_ID, $source_kshow_id); $c->add(entryPeer::TYPE, entryType::MEDIA_CLIP); $c->add(entryPeer::STATUS, entryStatus::READY); $entries = entryPeer::doSelectJoinAll($c); $entry_kusers = array(); // assign each entry to a kuser foreach ($entries as $entry) { $place_in_array = count($entry_kusers) % count($list_of_valid_kusers); $kuser = $list_of_valid_kusers[$place_in_array]; $entry_kusers[$entry->getId()] = $kuser->getId(); } $clone = $this->getP("clone"); if ($clone == 'true') { $mode = 2; // clone $entry_id_map = array(); // will be used to map the source->target entries $entry_cache = array(); // will be used to cache all relevat entries $new_entry_list = array(); $failed_entry_list = array(); foreach ($entries as $entry) { try { $kuser_id = $entry_kusers[$entry->getId()]; $override_fields = $entry->copy(); $override_fields->setPartnerId($target_kshow->getPartnerId()); $override_fields->setSubpId($target_kshow->getSubpId()); $override_fields->setKuserId($kuser_id); $override_fields->setCreatorKuserId($kuser_id); $new_entry = myEntryUtils::deepClone($entry, $target_kshow_id, $override_fields, false); $new_entry_list[] = $new_entry; // will help fix the metadata entries $entry_id_map[$entry->getId()] = $new_entry->getId(); $entry_cache[$entry->getId()] = $entry; $entry_cache[$new_entry->getId()] = $new_entry; } catch (Exception $ex) { $failed_entry_list[] = $entry; } // echo "entry [{$entry->getId()}] copied<br>"; flush(); } // now clone the show_entry $new_show_entry = $target_kshow->getShowEntry(); myEntryUtils::deepCloneShowEntry($source_kshow->getShowEntry(), $new_show_entry, $entry_id_map, $entry_cache); $new_entry_list[] = $new_show_entry; $entries = $new_entry_list; $entry_kusers = null; } // echo "ended!<bR>"; flush(); } $this->source_kshow_id = @$source_kshow_id; $this->target_kshow_id = @$target_kshow_id; $this->partner_id = @$target_partner_id; $this->source_kshow = @$source_kshow; $this->target_kshow = @$target_kshow; $this->kuser_names = @$kuser_names; $this->list_of_kusers = @$list_of_kusers; $this->entries = @$entries; $this->mode = $mode; $this->entry_kusers = @$entry_kusers; // echo "going to template!<bR>"; flush(); }
/** * This is not a regular service. * Because the caller is not a partner but rather a 3rd party provider that wishs to query our system, * The security is slightly different and the respons is in the format of mRss which is related to entries only. */ public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2; header("Content-Type: text/xml; charset=utf-8"); // TODO - verify permissions for viewing lists // validate the ks of the caller $code = $this->getP("code"); if ($code != 'fsalh5423a43g') { return "<xml></xml>"; die; } $detailed = $this->getP("detailed", false); $limit = $this->getP("page_size", 100); $limit = $this->maxPageSize($limit); $operated_partner_id = $this->getP("operated_partner_id"); $page = $this->getP("page", 1); $offset = ($page - 1) * $limit; // kuserPeer::setUseCriteriaFilter( false ); if ($operated_partner_id) { entryPeer::setUseCriteriaFilter(true); } else { entryPeer::setUseCriteriaFilter(false); } // FOR now - display only 2 partners // 2460 - dorimedia $partner_list = array(593, 2460); $c = KalturaCriteria::create(entryPeer::OM_CLASS); $c->addAnd(entryPeer::STATUS, entryStatus::READY); // for now display only entries that are part of the kaltura network // $c->addAnd ( entryPeer::DISPLAY_IN_SEARCH , mySearchUtils::DISPLAY_IN_SEARCH_KALTURA_NETWORK ); // filter $filter = new entryFilter(); $fields_set = $filter->fillObjectFromRequest($this->getInputParams(), "filter_", null); $this->setExtraFilters($filter); $offset = ($page - 1) * $limit; $c->setLimit($limit); if ($offset > 0) { $c->setOffset($offset); } $filter->attachToCriteria($c); //if ($order_by != -1) entryPeer::setOrder( $c , $order_by ); $c->addAnd(entryPeer::PARTNER_ID, $partner_list, Criteria::IN); $start_1 = microtime(true); if ($detailed) { // for some entry types - there are no kshow or kusers - don't join even when detailed if ($this->joinOnDetailed()) { $list = entryPeer::doSelectJoinAll($c); } else { $list = entryPeer::doSelect($c); } $level = objectWrapperBase::DETAIL_LEVEL_DETAILED; } else { $list = entryPeer::doSelect($c); $level = objectWrapperBase::DETAIL_LEVEL_REGULAR; } $count = $c->getRecordsCount(); $end_1 = microtime(true); KalturaLog::log("benchmark db: [" . ($end_1 - $start_1) . "]"); $result_count = count($list); $start_2 = microtime(true); $mrss_renderer = new kalturaRssRenderer(kalturaRssRenderer::TYPE_TABOOLA); $str = $mrss_renderer->renderMrssFeed($list, $page, $result_count); $end_2 = microtime(true); KalturaLog::log("benchmark render: [" . ($end_2 - $start_2) . "]"); echo $str; // don't return to the rest of the implementation - the base class manipulates the content. die; }
/** * Gives a system applicative snapsot */ public function execute() { myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3; $this->forceSystemAuthentication(); $partner_id = $this->getRequestParameter('partner_id', -1); if ($partner_id >= 0) { myPartnerUtils::applyPartnerFilters($partner_id); } $this->partner_id = $partner_id; $limit = $this->getRequestParameter('limit', '30'); if ($limit > 300) { $limit = 300; } $bands_only = $this->getRequestParameter("bands", false) != null; $modified_only = $this->getRequestParameter("modified", false) != null; $this->bands_only = $bands_only; $this->modified_only = $modified_only; $this->kshows_with_new_entries = $modified_only ? dashboardUtils::getUpdatedKshows() : null; $yesterday = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y")); $lastweek = mktime(0, 0, 0, date("m"), date("d") - 7, date("Y")); $query_esterday = date('Y-m-d', $yesterday); $query_lastweek = date('Y-m-d', $lastweek); $modified_band_ids = $modified_only ? array_keys($this->kshows_with_new_entries) : null; if ($modified_only) { // TODO - this chunk was copied from the code bellow with minor changes - generalize ! $c = new Criteria(); // $c->add ( kshowPeer::ID , $modified_band_ids , Criteria::IN ); // search only the given IDs $this->bandsOnly($bands_only, $modified_band_ids, $c, kshowPeer::PARTNER_ID); $this->kshow_count = kshowPeer::doCount($c); $criterion = $c->getNewCriterion(kshowPeer::CREATED_AT, $query_esterday, Criteria::GREATER_EQUAL); $c->add($criterion); $this->kshow_count1 = kshowPeer::doCount($c); $criterion = $c->getNewCriterion(kshowPeer::CREATED_AT, $query_lastweek, Criteria::GREATER_EQUAL); $c->add($criterion); $this->kshow_count7 = kshowPeer::doCount($c); $c->setLimit($limit); //$c->hints = array(kshowPeer::TABLE_NAME => "created_at_index"); $c->addDescendingOrderByColumn(kshowPeer::CREATED_AT); $c->remove(kshowPeer::CREATED_AT); $c->addJoin(kshowPeer::PRODUCER_ID, kuserPeer::ID, Criteria::LEFT_JOIN); $this->kshows = kshowPeer::doSelectJoinkuser($c); $this->bands_only = $bands_only; $this->entry_count = 0; $this->entry_count1 = 0; $this->entry_count7 = 0; $this->entries = array(); $this->kuser_count = 0; $this->kuser_count1 = 0; $this->kuser_count7 = 0; $this->kusers = array(); dashboardUtils::updateKshowsRoughcutCount($this->kshows); return sfView::SUCCESS; } $c = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $c, kshowPeer::PARTNER_ID); $this->kshow_count = kshowPeer::doCount($c); $d = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $d, kshowPeer::PARTNER_ID); $criterion = $c->getNewCriterion(kshowPeer::CREATED_AT, $query_esterday, Criteria::GREATER_EQUAL); $d->add($criterion); $this->kshow_count1 = kshowPeer::doCount($d); $e = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $e, kshowPeer::PARTNER_ID); $criterion = $c->getNewCriterion(kshowPeer::CREATED_AT, $query_lastweek, Criteria::GREATER_EQUAL); $e->add($criterion); $this->kshow_count7 = kshowPeer::doCount($e); //$this->kshow_count = kshowPeer::doCount( $c ); $c->setLimit($limit); //$c->hints = array(kshowPeer::TABLE_NAME => "created_at_index"); $c->addDescendingOrderByColumn(kshowPeer::CREATED_AT); $c->addJoin(kshowPeer::PRODUCER_ID, kuserPeer::ID, Criteria::LEFT_JOIN); $this->kshows = kshowPeer::doSelectJoinkuser($c); $c = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $c, entryPeer::PARTNER_ID); $this->entry_count = entryPeer::doCount($c); $d = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $d, entryPeer::PARTNER_ID); $criterion = $c->getNewCriterion(entryPeer::CREATED_AT, $query_esterday, Criteria::GREATER_EQUAL); $d->add($criterion); $this->entry_count1 = entryPeer::doCount($d); $e = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $e, entryPeer::PARTNER_ID); $criterion = $c->getNewCriterion(entryPeer::CREATED_AT, $query_lastweek, Criteria::GREATER_EQUAL); $e->add($criterion); $this->entry_count7 = entryPeer::doCount($e); $c->setLimit($limit); //$c->hints = array(entryPeer::TABLE_NAME => "created_at_index"); $c->addDescendingOrderByColumn(entryPeer::CREATED_AT); $c->add(entryPeer::TYPE, entryType::MEDIA_CLIP); // we don't want entries that // $c->addJoin(entryPeer::KUSER_ID, kuserPeer::ID, Criteria::INNER_JOIN); // $c->addJoin(entryPeer::KSHOW_ID, kshowPeer::ID, Criteria::INNER_JOIN); $this->entries = entryPeer::doSelectJoinAll($c); $c = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $c, kuserPeer::PARTNER_ID); $d = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $d, kuserPeer::PARTNER_ID); $criterion = $c->getNewCriterion(kuserPeer::CREATED_AT, $query_esterday, Criteria::GREATER_EQUAL); $d->add($criterion); $this->kuser_count1 = kuserPeer::doCount($d); $e = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $e, kuserPeer::PARTNER_ID); $criterion = $c->getNewCriterion(kuserPeer::CREATED_AT, $query_lastweek, Criteria::GREATER_EQUAL); $e->add($criterion); $this->kuser_count7 = kuserPeer::doCount($e); $this->kuser_count = kuserPeer::doCount($c); $c->setLimit($limit); $c->addDescendingOrderByColumn(kuserPeer::CREATED_AT); $this->kusers = kuserPeer::doSelect($c); dashboardUtils::updateKusersRoughcutCount($this->kusers); dashboardUtils::updateKshowsRoughcutCount($this->kshows); return sfView::SUCCESS; }