public function sendEmailAlert() { $this->kuser = kuserPeer::retrieveByPK($this->getKuserId()); if ($this->kuser) { kJobsManager::addMailJob(null, 0, $this->kuser->getPartnerId(), $this->getAlertType(), kMailJobData::MAIL_PRIORITY_NORMAL, kconf::get("batch_notification_sender_email"), kconf::get("batch_notification_sender_name"), $this->kuser->getEmail(), $this->getBodyParamsArray(), $this->getSubjectParamsArray()); } }
/** const SUBJECT_TYPE_KSHOW = '1'; const SUBJECT_TYPE_ENTRY = '2'; const SUBJECT_TYPE_USER = '******'; */ public static function addFavorite(favorite $favorite) { self::add($favorite); $type = $favorite->getSubjectType(); $id = $favorite->getSubjectId(); if ($type == favorite::SUBJECT_TYPE_ENTRY) { $obj = entryPeer::retrieveByPK($id); if ($obj) { $v = $obj->getFavorites(); self::inc($v); $obj->setFavorites($v); } } elseif ($type == favorite::SUBJECT_TYPE_KSHOW) { $obj = kshowPeer::retrieveByPK($id); if ($obj) { $v = $obj->getFavorites(); self::inc($v); $obj->setFavorites($v); } } elseif ($type == favorite::SUBJECT_TYPE_USER) { $obj = kuserPeer::retrieveByPK($id); if ($obj) { $v = $obj->getFans(); self::inc($v); $obj->setFans($v); } } // don't forget to save the modified object self::add($obj); }
/** * Cleans up the environment after running a test. */ protected function tearDown() { kuserPeer::clearInstancePool(); UserLoginDataPeer::clearInstancePool(); kuserPeer::setDefaultCriteriaFilter(false); UserLoginDataPeer::setUseCriteriaFilter(false); $this->clientConfig = null; $this->client = null; $this->nextUserId = null; foreach ($this->createdDbObjects as $obj) { try { if (get_class($obj) == 'kuser') { $updated = kuserPeer::retrieveByPK($obj->getId()); if ($updated) { $loginData = UserLoginDataPeer::retrieveByPK($updated->getLoginDataId()); if ($loginData) { $loginData->delete(); } } } $obj->delete(); } catch (PropelException $e) { } } parent::tearDown(); }
/** * @return string $puserId */ public function getPuserId() { if (!$this->puserId) { if (!$this->getKuserId()) { return null; } $kuser = kuserPeer::retrieveByPK($this->getKuserId()); $this->puserId = $kuser->getPuserId(); } return $this->puserId; }
/** Returns newly created puser - after creating it's corresponding kuser. If the puser_kuser already exists && $verify_not_exists==true , don't create a new one and return the existing one */ public static function createPuserKuser($partner_id, $subp_id, $puser_id, $kuser_name, $puser_name, $create_kuser = false, $kuser = null) { $puser_kuser = self::retrieveByPartnerAndUid($partner_id, $subp_id, $puser_id, true); if (!$kuser) { $kuser = kuserPeer::getKuserByPartnerAndUid($partner_id, $puser_id, true); // don't create an existing kuser! } if ($puser_kuser) { if (!$create_kuser) { // if the puser_kuser already exists - don't re-create it $puser_kuser->exists = true; return $puser_kuser; } else { // puser_kuser exists but it's OK // this might be the case where we don't mind creating a new one each time } } else { $puser_kuser = new PuserKuser(); } $c = new Criteria(); $c->add(self::PARTNER_ID, $partner_id); $c->add(self::PUSER_ID, $puser_id); $partner_puser_kuser = self::doSelectOne($c); if ($kuser !== null) { $kuser_id = $kuser->getId(); } else { if ($partner_puser_kuser) { $kuser_id = $partner_puser_kuser->getKuserId(); $kuser = kuserPeer::retrieveByPK($kuser_id); } else { // create kuser for this puser $kuser = new kuser(); $kuser->setScreenName($kuser_name); list($firstName, $lastName) = kString::nameSplit($kuser_name); $kuser->setFirstName($firstName); $kuser->setLastName($lastName); $kuser->setPartnerId($partner_id); // set puserId for forward compatibility with PS3 $kuser->setPuserId($puser_id); $kuser->setStatus(KuserStatus::ACTIVE); // so he won't appear in the search $kuser->save(); $kuser_id = $kuser->getId(); } } $puser_kuser->setPartnerId($partner_id); $puser_kuser->setSubpId($subp_id); $puser_kuser->setPuserId($puser_id); $puser_kuser->setKuserId($kuser_id); $puser_kuser->setPuserName($puser_name); $puser_kuser->save(); $puser_kuser->setkuser($kuser); return $puser_kuser; }
function retrieveSubject($type, $id) { switch ($type) { case flag::SUBJECT_TYPE_ENTRY: $entry = entryPeer::retrieveByPK($id); return 'entry id:' . $id . '<br/>kshow:' . returnKshowLink($entry->getKshowId()) . '<br/>Name:' . $entry->getName(); case flag::SUBJECT_TYPE_USER: $user = kuserPeer::retrieveByPK($id); return returnUserLink($user->getScreenName()); case flag::SUBJECT_TYPE_COMMENT: $comment = commentPeer::retrieveByPK($id); return 'comment id:' . $id . '<br/>Commnet:' . $comment->getComment(); default: return 'Unknown'; } }
public function sendRegistrationInformationForPartner($partner, $skip_emails, $existingUser) { // email the client with this info $adminKuser = kuserPeer::retrieveByPK($partner->getAccountOwnerKuserId()); $this->sendRegistrationInformation($partner, $adminKuser, $existingUser, null, $partner->getType()); if (!$skip_emails && kConf::hasParam("report_partner_registration") && kConf::get("report_partner_registration")) { // email the wikisupport@kaltura.com with this info $this->sendRegistrationInformation($partner, $adminKuser, $existingUser, self::KALTURA_SUPPORT); // if need to hook into SalesForce - this is the place if (include_once "mySalesForceUtils.class.php") { mySalesForceUtils::sendRegistrationInformationToSalesforce($partner); } // if need to hook into Marketo - this is the place if (include_once "myMarketoUtils.class.php") { myMarketoUtils::sendRegistrationInformation($partner); } } }
/** * @dataProvider providerTestMigration */ public function testMigration($kuserId) { $this->assertNull($this->kuser); $this->kuser = kuserPeer::retrieveByPK($kuserId); $this->assertNotNull($this->kuser); $this->assertEquals($this->kuser->getFullName(), trim($this->kuser->getFirstName() . ' ' . $this->kuser->getLastName())); if ($this->kuser->getSalt() && $this->kuser->getSha1Password() && in_array($this->kuser->getPartnerId(), $this->loginPartnerIds)) { $this->assertTrue($this->kuser->getLoginDataId()); $loginData1 = UserLoginDataPeer::retrieveByPK($this->kuser->getLoginDataId()); $this->assertNotNull($loginData1); $loginData2 = UserLoginDataPeer::getByEmail($this->kuser->getEmail()); $this->assertNotNull($loginData2); $this->assertEquals($loginData1->getId(), $loginData2->getId()); $this->assertEquals($this->kuser->getSalt(), $loginData2->getSalt()); $this->assertEquals($this->kuser->getSha1Password(), $loginData2->getSha1Password()); $this->assertEquals($this->kuser->getEmail(), $loginData2->getLoginEmail()); $c = new Criteria(); $c->addAnd(UserLoginDataPeer::LOGIN_EMAIL, $this->kuser->getEmail()); $loginDatas = UserLoginDataPeer::doSelect($c); $this->assertEquals(count($loginDatas), 1); $this->assertEquals($loginDatas[0]->getId(), $loginData1->getId()); $allKusers = kuserPeer::getByLoginDataAndPartner($this->kuser->getLoginDataId(), $this->kuser->getPartnerId()); $this->assertEquals(count($allKusers), 1); } else { if ($this->kuser->getPartnerId() != $this->adminConsolePartnerId && substr($this->kuser->getPuserId(), 0, 9) != '__ADMIN__') { $this->assertNull($this->kuser->getLoginDataId()); } } if ($this->kuser->getPartnerId() == $this->adminConsolePartnerId || substr($this->kuser->getPuserId(), 0, 9) == '__ADMIN__') { $this->assertTrue($this->kuser->getIsAdmin()); } else { $this->assertFalse($this->kuser->getIsAdmin()); } if ($this->kuser->getIsAdmin()) { $this->assertTrue($this->kuser->getIsAdmin()); } }
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(); }
public function getPuserId() { if (!$this->puserId) { $kuser = kuserPeer::retrieveByPK($this->getKuserId()); if ($kuser) { $this->puserId = $kuser->getPuserId(); } } return $this->puserId; }
public function doFromObject($dbCuePoint, KalturaDetachedResponseProfile $responseProfile = null) { parent::doFromObject($dbCuePoint, $responseProfile); if ($this->shouldGet('userId', $responseProfile)) { if ($dbCuePoint->getKuserId() !== null) { $dbKuser = kuserPeer::retrieveByPK($dbCuePoint->getKuserId()); if ($dbKuser) { if (!kConf::hasParam('protect_userid_in_api') || !in_array($dbCuePoint->getPartnerId(), kConf::get('protect_userid_in_api')) || !in_array(kCurrentContext::getCurrentSessionType(), array(kSessionBase::SESSION_TYPE_NONE, kSessionBase::SESSION_TYPE_WIDGET))) { $this->userId = $dbKuser->getPuserId(); } } } } }
/** * @param $answers * @param $orderBy * @return array */ protected function getAggregateDataForUsers($answers, $orderBy) { $ans = array(); $usersCorrectAnswers = array(); $usersWrongAnswers = array(); foreach ($answers as $answer) { /** * @var AnswerCuePoint $answer */ $quizUserEntryId = $answer->getQuizUserEntryId(); if ($this->isQuizUserEntrySubmitted($quizUserEntryId)) { if ($answer->getIsCorrect()) { if (isset($usersCorrectAnswers[$answer->getKuserId()])) { $usersCorrectAnswers[$answer->getKuserId()]++; } else { $usersCorrectAnswers[$answer->getKuserId()] = 1; } } else { if (isset($usersWrongAnswers[$answer->getKuserId()])) { $usersWrongAnswers[$answer->getKuserId()]++; } else { $usersWrongAnswers[$answer->getKuserId()] = 1; } } } } foreach (array_merge(array_keys($usersCorrectAnswers), array_keys($usersWrongAnswers)) as $kuserId) { $totalAnswers = 0; $totalCorrect = 0; if (isset($usersCorrectAnswers[$kuserId])) { $totalAnswers += $usersCorrectAnswers[$kuserId]; $totalCorrect = $usersCorrectAnswers[$kuserId]; } if (isset($usersWrongAnswers[$kuserId])) { $totalAnswers += $usersWrongAnswers[$kuserId]; } $userId = "unknown-user"; $dbKuser = kuserPeer::retrieveByPK($kuserId); if ($dbKuser) { $userId = $dbKuser->getPuserId(); } $ans[$userId] = array('user_id' => $userId, 'percentage' => $totalCorrect / $totalAnswers * 100, 'num_of_correct_answers' => $totalCorrect, 'num_of_wrong_answers' => $totalAnswers - $totalCorrect); } uasort($ans, $this->getSortFunction($orderBy)); $ans = array_values($ans); return $ans; }
$loggerConfigPath = ROOT_DIR . '/scripts/logger.ini'; $config = new Zend_Config_Ini($loggerConfigPath); KalturaLog::initLog($config); KalturaLog::setContext(basename(__FILE__)); KalturaLog::info("Starting script"); KalturaLog::info("Initializing database..."); DbManager::setConfig(kConf::getDB()); DbManager::initialize(); KalturaLog::info("Database initialized successfully"); $syncType = 'kuser'; $dbh = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_DWH); $sql = "CALL get_data_for_operational('{$syncType}')"; $count = 0; $rows = $dbh->query($sql)->fetchAll(); foreach ($rows as $row) { $kuser = kuserPeer::retrieveByPK($row['kuser_id']); if (is_null($kuser)) { KalturaLog::err('Couldn\'t find kuser [' . $row['kuser_id'] . ']'); continue; } $kuser->setStorageSize($row['storage_size']); $kuser->save(); $count++; KalturaLog::debug('Successfully saved kuser [' . $row['kuser_id'] . ']'); if ($count % 500) { kuserPeer::clearInstancePool(); } } $sql = "CALL mark_operational_sync_as_done('{$syncType}')"; $dbh->query($sql); KalturaLog::debug("Done updating {$count} kusers from DWH to operational DB");
/** * @param int $id * @return string */ public static function getEmailById($id) { $kuser = kuserPeer::retrieveByPK($id); return $kuser->getEmail(); }
public function getRootObjects(IBaseObject $object) { return array(kuserPeer::retrieveByPK($object->getKuserId()), kuserPeer::retrieveByPK($object->getKgroupId())); }
/** * Sets the valid user for the entry * Throws an error if the session user is trying to add entry to another user and not using an admin session * * @param KalturaBaseEntry $entry * @param entry $dbEntry */ protected function checkAndSetValidUser(KalturaBaseEntry $entry, entry $dbEntry) { KalturaLog::debug("DB puser id [" . $dbEntry->getPuserId() . "] kuser id [" . $dbEntry->getKuserId() . "]"); // for new entry, puser ID is null - set it from service scope if ($dbEntry->getPuserId() === null) { KalturaLog::debug("Set kuser id [" . $this->getKuser()->getId() . "] line [" . __LINE__ . "]"); $dbEntry->setKuserId($this->getKuser()->getId()); return; } // get puser ID from entry to compare to userId on the updated entry object $entryPuserId = $dbEntry->getPuserId(); $kuser = null; if ($dbEntry->getKuserId()) { // get kuser object from entry kuserId $kuser = kuserPeer::retrieveByPK($dbEntry->getKuserId()); if (!$kuser || $kuser->getPuserId() != $dbEntry->getPuserId()) { $kuser = null; } } else { // get kuser object from entry puserId $kuser = kuserPeer::getKuserByPartnerAndUid($dbEntry->getPartnerId(), $dbEntry->getPuserId()); } if ($kuser) { KalturaLog::debug("Set kuser id [" . $kuser->getId() . "] line [" . __LINE__ . "]"); $dbEntry->setKuserId($kuser->getId()); return; } // userID doesn't require change (it is null or the same as the db entry) - do nothing if ($entry->userId === null || $entry->userId === $entryPuserId) { KalturaLog::debug('API entry userId [' . $entry->userId . '], DB entry userId [' . $entryPuserId . '] - no need to change - quitting'); return; } // db user is going to be changed, only admin allowed - otherwise, throw exception if (!$this->getKs() || !$this->getKs()->isAdmin()) { KalturaLog::debug('API entry userId [' . $entry->userId . '], DB entry userId [' . $entryPuserId . '] - change required but KS is not admin'); throw new KalturaAPIException(KalturaErrors::INVALID_KS, "", ks::INVALID_TYPE, ks::getErrorStr(ks::INVALID_TYPE)); } // passed previous conditions, need to change userID on entry // first step is to make sure the user exists $puserKuser = PuserKuserPeer::createPuserKuser($this->getPartnerId(), $this->getPartnerId() * 100, $dbEntry->getPuserId(), $dbEntry->getPuserId(), $dbEntry->getPuserId(), true); // second step is simply changing the userID on the entry $dbEntry->setKuserId($puserKuser->getKuserId()); KalturaLog::debug("Set kuser id [" . $puserKuser->getKuserId() . "] line [" . __LINE__ . "]"); }
/** * @return puserId of the kuser currently set as the account owner */ public function getAdminUserId() { $ownerKuserId = $this->getAccountOwnerKuserId(); if (!$ownerKuserId) { return null; } $ownerKuser = kuserPeer::retrieveByPK($ownerKuserId); if (!$ownerKuser) { KalturaLog::err('Cannot find kuser with id [' . $ownerKuserId . '] set as account of partner id [' . $this->getId() . ']'); return null; } return $ownerKuser->getPuserId(); }
protected function getAggregateDataForUsers($userEntries, $orderBy) { $ans = array(); $usersCorrectAnswers = array(); $usersTotalQuestions = array(); foreach ($userEntries as $userEntry) { if ($userEntry->getStatus() == self::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED)) { if (isset($usersCorrectAnswers[$userEntry->getKuserId()])) { $usersCorrectAnswers[$userEntry->getKuserId()] += $userEntry->getNumOfCorrectAnswers(); } else { $usersCorrectAnswers[$userEntry->getKuserId()] = $userEntry->getNumOfCorrectAnswers(); } if (isset($usersTotalQuestions[$userEntry->getKuserId()])) { $usersTotalQuestions[$userEntry->getKuserId()] += $userEntry->getNumOfQuestions(); } else { $usersTotalQuestions[$userEntry->getKuserId()] = $userEntry->getNumOfQuestions(); } } } foreach (array_keys($usersTotalQuestions) as $kuserId) { $totalCorrect = 0; $totalAnswers = $usersTotalQuestions[$kuserId]; if (isset($usersCorrectAnswers[$kuserId])) { $totalCorrect = $usersCorrectAnswers[$kuserId]; } $userId = "Unknown"; $dbKuser = kuserPeer::retrieveByPK($kuserId); if ($dbKuser) { if ($dbKuser->getPuserId()) { $userId = $dbKuser->getPuserId(); } } $ans[$userId] = array('user_id' => $userId, 'percentage' => $totalCorrect / $totalAnswers * 100, 'num_of_correct_answers' => $totalCorrect, 'num_of_wrong_answers' => $totalAnswers - $totalCorrect); } uasort($ans, $this->getSortFunction($orderBy)); $ans = array_values($ans); return $ans; }
public function getObject() { //The object Id received through the API is not the actual kuser ID, but the puser ID. return kuserPeer::retrieveByPK($this->getObjectId()); }
/** * * Gets all the kusers from the puser_ kuser table by the given puser id and partner id * @param string $puserId * @param int $partnerId */ private function getKusersFromPuserKuserTable($puserId, $partnerId) { PuserKuserPeer::clearInstancePool(); $c = new Criteria(); $c->add(PuserKuserPeer::PUSER_ID, $puserId, Criteria::EQUAL); $c->add(PuserKuserPeer::PARTNER_ID, $partnerId, Criteria::EQUAL); $c->add(PuserKuserPeer::PARTNER_ID, $this->ignorePartners, Criteria::NOT_IN); PuserKuserPeer::setUseCriteriaFilter(false); $puserKusers = PuserKuserPeer::doSelect($c); PuserKuserPeer::setUseCriteriaFilter(true); $kusers = array(); foreach ($puserKusers as $puserKuser) { // now we check that the puser_kuser table doesn't reference to a different puser in the kuser table $kuser = kuserPeer::retrieveByPK($puserKuser->getKuserId()); if (!is_null($kuser)) { $kuserId = $kuser->getId(); $kuserTablePuserId = $kuser->getPuserId(); if (is_null($kuserTablePuserId)) { $kuser->setPuserId($puserId); $this->printToLog("puserId [{$puserId}] in the Kuser table is null for kuser [{$kuserId}]- Perfect Match just set the kuser puser id"); if (!$this->isDryRun) { $kuser->save(); } } if ($kuserTablePuserId == $puserId && $kuser->getPartnerId() == $partnerId) { $kusers[] = $kuser; //add to the valid kusers $this->printToLog("Kuser [{$kuserId}] was added to the users found in the puser kuser table"); } else { $kuserTablePuserId = $kuser->getPuserId(); $puserTableKuserId = $puserKuser->getKuserId(); $this->printToLog("We have a different kusers and pusers (Cross reference!!!)"); $this->printToLog("partnerId [{$partnerId}], table puser_kuser: given puserId[{$puserId}] -> kuserId[{$puserTableKuserId} ], table kuser puserId [{$kuserTablePuserId}]"); } } else { $kuserId = $puserKuser->getKuserId(); // the kuser id on the puser table $this->printToLog("Puser [{$puserId}], has kuser [{$kuserId}] and it can't be found on KUSER table"); } } return $kusers; }
/** * Delete CategoryEntry * * @action delete * @param string $entryId * @param int $categoryId * @throws KalturaErrors::INVALID_ENTRY_ID * @throws KalturaErrors::CATEGORY_NOT_FOUND * @throws KalturaErrors::CANNOT_REMOVE_ENTRY_FROM_CATEGORY * @throws KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY * */ function deleteAction($entryId, $categoryId) { $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { if (kCurrentContext::$master_partner_id != Partner::BATCH_PARTNER_ID) { throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $entryId); } } $category = categoryPeer::retrieveByPK($categoryId); if (!$category && kCurrentContext::$master_partner_id != Partner::BATCH_PARTNER_ID) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId); } //validate user is entiteld to remove entry from category if (kEntitlementUtils::getEntitlementEnforcement() && $entry->getKuserId() != kCurrentContext::getCurrentKsKuserId() && $entry->getCreatorKuserId() != kCurrentContext::getCurrentKsKuserId()) { $kuserIsEntitled = false; $kuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryId, kCurrentContext::getCurrentKsKuserId()); // First pass: check if kuser is a manager if ($kuser) { if ($kuser->getPermissionLevel() == CategoryKuserPermissionLevel::MANAGER) { $kuserIsEntitled = true; } } else { $kuser = kuserPeer::retrieveByPK(kCurrentContext::getCurrentKsKuserId()); } // Second pass: check if kuser is a co-publisher if (!$kuserIsEntitled && $kuser && $entry->isEntitledKuserPublish($kuser->getKuserId())) { $kuserIsEntitled = true; } if (!$kuserIsEntitled) { throw new KalturaAPIException(KalturaErrors::CANNOT_REMOVE_ENTRY_FROM_CATEGORY); } } $dbCategoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryId, $entryId); if (!$dbCategoryEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY); } $dbCategoryEntry->setStatus(CategoryEntryStatus::DELETED); $dbCategoryEntry->save(); //need to select the entry again - after update $entry = entryPeer::retrieveByPK($entryId); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry); }
unset($entries); entryPeer::clearInstancePool(); fprintf($stderr, "{$i}\r"); } $connection = Propel::getConnection(); foreach ($stats as $partner_id => $dates) { foreach ($dates as $date => $pstats) { /** * we are deleting entries for a specific partner on a specific date. * * if we run twice on the same date, this way we only re-insert partners found in this run * and not in the first run. */ $query = "DELETE FROM " . PartnerActivityPeer::TABLE_NAME . " WHERE " . PartnerActivityPeer::ACTIVITY . "=" . PartnerActivity::PARTNER_ACTIVITY_STORAGE . " AND " . PartnerActivityPeer::PARTNER_ID . "=" . $partner_id . " AND " . PartnerActivityPeer::ACTIVITY_DATE . "='" . $date . "'"; $connection->exec($query); //print "$partner_id $date ".$pstats["size"]." ".$pstats["count"]."\n"; // output partner ID and date, print "{$partner_id} {$date} \n"; PartnerActivity::incrementActivity($partner_id, PartnerActivity::PARTNER_ACTIVITY_STORAGE, PartnerActivity::PARTNER_SUB_ACTIVITY_STORAGE_SIZE, floor($pstats["size"] / 1024), $date); PartnerActivity::incrementActivity($partner_id, PartnerActivity::PARTNER_ACTIVITY_STORAGE, PartnerActivity::PARTNER_SUB_ACTIVITY_STORAGE_COUNT, $pstats["count"], $date); } } foreach ($kusers as $kuser_id => $size) { $kuser = kuserPeer::retrieveByPK($kuser_id); if ($kuser) { $kuser->setStorageSize($kuser->getStorageSize() + $size); $kuser->save(); } unset($kuser); //echo 'kuser '.$kuser_id.' has total daily size of '.$size.PHP_EOL; }
public static function unsubscribe($kshow_id, $kuser_id, &$message) { // first check if user already subscribed to this show $kshowKuser = self::isSubscribed($kshow_id, $kuser_id, KshowKuser::KSHOW_SUBSCRIPTION_NORMAL); if (!$kshowKuser) { $kshow = kshowPeer::retrieveByPK($kshow_id); if (!$kshow) { $message = "Kaltura {$kshow_id} doesn't exist."; } else { $kuser = kuserPeer::retrieveByPK($kuser_id); if (!$kuser) { $message = "User {$user_id} doesn't exist."; } else { $message = "Error - You are not subscribed to this Kaltura."; } } return false; } // ok, we found he entry, so delete it. $kshowKuser->delete(); $message = "You have unsubscribed from this Kaltura."; return true; }
/** * $notification_type - * $puser_id - the puser_id of the kuser that caused the modification * $object_data - can be either an object or an object id (if the object no longer exists * $partner_id - if exists, use this (usually in case of $object_data is an id), if not - use the partner_id from the object * $entry_id is optional */ public static function createNotification($notification_type, $object_data, $partner_id = null, $puser_id = null, $prefix = null, $extra_notification_data = null, $entry_id = null) { if (!$entry_id && $object_data instanceof entry) { $entry_id = $object_data->getId(); } if (!$partner_id) { if ($object_data instanceof BaseObject) { $partner_id = $object_data->getPartnerId(); } else { KalturaLog::log("Cannot create notification [{$notification_type}] [{$object_data}] [{$partner_id}]"); return false; } } // echo "[$partner_id]"; $nofication_config_str = null; list($nofity, $nofication_config_str) = myPartnerUtils::shouldNotify($partner_id); if (!$nofity) { return false; } $nofication_config = myNotificationsConfig::getInstance($nofication_config_str); $nofity_send_type = $nofication_config->shouldNotify($notification_type); //echo "nofication_config_str: $nofication_config_str<br>notification_type:$notification_type<br>"; if ($nofity_send_type == self::NOTIFICATION_MGR_NO_SEND) { return false; } //echo "nofity_send_type: $nofity_send_type<br>"; // now check what type of notification to use - none / synch / a-synch // Remarked by Tan-Tan, Nov 5 2009 to support the new batches // // $not = new notification(); // $not->setType( $notification_type ); // if ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_ASYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH) // { // // // the notification should be in status pending so it will be sent in the // $not->setStatus( BatchJob::BATCHJOB_STATUS_PENDING ); // } // elseif ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH ) // { // $not->setStatus( BatchJob::BATCHJOB_STATUS_FINISHED ); // } // // // return the notification to the caller // $retrun_notification = ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH ); // ////echo "retrun_notification: $retrun_notification<br>"; // // $not->setPartnerId( $partner_id ); // $not->setPuserId( $puser_id ); // $not->setDc ( kDataCenterMgr::getCurrentDcId() ); // if ( $object_data instanceof BaseObject ) // { // $not->setObjectId($object_data->getId() ); // $not->setData( self::createNotificationData ( $notification_type , $object_data, $extra_notification_data ) ); // // if ( $object_data instanceof entry ) // { // if (defined("KALTURA_API_V3")) // $puser_id = $object_data->getKuser()->getPuserId(); // else // $puser_id = PuserKuserPeer::getByKuserId( $object_data->getKuserId() , 1 ); // // $not->setPuserId( $puser_id ); // // } // } // else // { // // in this case all we have is the object data which is the id // // this is probably the case of some delete and we mifght not have the object in hand but only the id // $not->setObjectId( $object_data ); // } // $not->save(); // Added by Tan-Tan, Nov 2009 to support the new batches // if ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_ASYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH) // { // // // the notification should be in status pending so it will be sent in the // $job->setStatus( BatchJob::BATCHJOB_STATUS_PENDING ); // } // else $dontSend = false; if ($nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH) { $dontSend = true; } // return the notification to the caller $retrun_notification = $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH; $objectId = null; $notificationData = null; if ($object_data instanceof BaseObject) { $objectId = $object_data->getId(); $notificationData = self::createNotificationData($notification_type, $object_data, $extra_notification_data); if ($object_data instanceof entry) { if (kCurrentContext::isApiV3Context()) { $kuser = $object_data->getKuser(); if ($kuser) { $puser_id = $kuser->getPuserId(); } else { $puser_id = null; KalturaLog::log(__CLASS__ . '::' . __METHOD__ . ' [line: ' . __LINE__ . '] could not find kuser [' . $object_data->getKuserId() . '] from object [' . $object_data->getId() . ']'); } } else { $puser_id = PuserKuserPeer::getByKuserId($object_data->getKuserId(), 1); // in flatten (or maybe other old batches), KALTURA_API_V3 is not defined, but entry user could have // been created through api v3, in that case there will not be a record in puser_kuser table if (is_null($puser_id)) { $puser_id = $object_data->getPuserId(); // if entry was created on PS2 and from some reason puserId is still missing if (is_null($puser_id)) { $kuser = kuserPeer::retrieveByPK($object_data->getKuserId()); if ($kuser) { $puser_id = $kuser->getPuserId(); } } } if (is_null($puser_id)) { KalturaLog::log(__CLASS__ . '::' . __METHOD__ . ' [line: ' . __LINE__ . '] could not get puser_id out of api_v3 context puserId from entry:[' . $object_data->getPuserId() . '] kuser ID:[' . $object_data->getKuserId() . '] entry:[' . $object_data->getId() . ']'); } } } } else { // in this case all we have is the object data which is the id // this is probably the case of some delete and we mifght not have the object in hand but only the id $objectId = $object_data; } $job = kJobsManager::addNotificationJob(null, $entry_id, $partner_id, $notification_type, $nofity_send_type, $puser_id, $objectId, $notificationData); if ($retrun_notification) { // return the notification id, notification object , url & the serialized data $partner = PartnerPeer::retrieveByPK($partner_id); list($url, $signature_key) = self::getPartnerNotificationInfo($partner); list($params, $raw_signature) = self::prepareNotificationData($url, $signature_key, $job, $prefix); $serialized_params = http_build_query($params, "", "&"); return array($job->getId(), $job, $url, $params, $serialized_params); } else { return $job->getId(); } }
public function fromObject($dbAnnotation) { parent::fromObject($dbAnnotation); if ($dbAnnotation->getKuserId() !== null) { $dbKuser = kuserPeer::retrieveByPK($dbAnnotation->getKuserId()); $this->userId = $dbKuser->getPuserId(); } }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $target_puser_id = $this->getPM("user_id"); $target_puser_kuser = PuserKuserPeer::retrieveByPartnerAndUid($partner_id, null, $target_puser_id); if ($target_puser_kuser) { $this->addDebug("puser_exists", $target_puser_kuser->getId()); // might be that the puser_kuser exists but the kuser does not $kuser = kuserPeer::retrieveByPK($target_puser_kuser->getKuserId()); if ($kuser) { $this->addError(APIErrors::DUPLICATE_USER_BY_ID, $target_puser_id); return; } else { // puser_kuser exists but need to create the ksuer... } } else { $target_puser_kuser = new PuserKuser(); $target_puser_kuser->setPuserId($target_puser_id); $target_puser_kuser->setPartnerId($partner_id); $target_puser_kuser->save(); $this->addDebug("Created_new_puser_kuser", $target_puser_kuser->getId()); } // get the new properties for the kuser from the request $kuser = new kuser(); $obj_wrapper = objectWrapperBase::getWrapperClass($kuser, 0); $fields_modified = baseObjectUtils::fillObjectFromMap($this->getInputParams(), $kuser, "user_", $obj_wrapper->getUpdateableFields()); // check that mandatory fields were set // TODO if (count($fields_modified) > 0) { if (!$partner_id) { $kuser_from_db = kuserPeer::getKuserByScreenName($kuser->getScreenName()); if ($kuser_from_db) { $this->addError(APIErrors::DUPLICATE_USER_BY_SCREEN_NAME, $kuser->getScreenName()); return; } } $kuser->setPartnerId($partner_id); $kuser->setPuserId($target_puser_id); try { $kuser = kuserPeer::addUser($kuser); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::USER_ALREADY_EXISTS) { $this->addException(APIErrors::DUPLICATE_USER_BY_ID, $kuser->getId()); return null; } if ($code == kUserException::LOGIN_ID_ALREADY_USED) { $this->addException(APIErrors::DUPLICATE_USER_BY_LOGIN_ID, $kuser->getEmail()); return null; } else { if ($code == kUserException::USER_ID_MISSING) { $this->addException(APIErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL, 'id'); return null; } else { if ($code == kUserException::INVALID_EMAIL) { $this->addException(APIErrors::INVALID_FIELD_VALUE); return null; } else { if ($code == kUserException::INVALID_PARTNER) { $this->addException(APIErrors::UNKNOWN_PARTNER_ID); return null; } else { if ($code == kUserException::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED) { $this->addException(APIErrors::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED); return null; } else { if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { $this->addException(APIErrors::PASSWORD_STRUCTURE_INVALID); return null; } } } } } } throw $e; } catch (kPermissionException $e) { $code = $e->getCode(); if ($code == kPermissionException::ROLE_ID_MISSING) { $this->addException(APIErrors::ROLE_ID_MISSING); return null; } if ($code == kPermissionException::ONLY_ONE_ROLE_PER_USER_ALLOWED) { $this->addException(APIErrors::ONLY_ONE_ROLE_PER_USER_ALLOWED); return null; } throw $e; } // now update the puser_kuser $target_puser_kuser->setPuserName($kuser->getScreenName()); $target_puser_kuser->setKuserId($kuser->getId()); $target_puser_kuser->save(); $this->addMsg("user", objectWrapperBase::getWrapperClass($target_puser_kuser, objectWrapperBase::DETAIL_LEVEL_DETAILED)); $this->addDebug("added_fields", $fields_modified); } else { $this->addError(APIErrors::NO_FIELDS_SET_FOR_USER); } }
/** * batch sets a configuration parameter to be loaded by a worker * * @action setWorkerConfig * @param int $workerId The id of the job to be configured * @param int $adminId The id of the admin that called the setConfig * @param string $configParam The parameter to be set * @param string $configValue The value to be set * @param string $configParamPart The parameter part to be set - for additional params * @param string $cause The reason it was changed * @return KalturaControlPanelCommand */ function setWorkerConfigAction($workerId, $adminId, $configParam, $configValue, $configParamPart = null, $cause = null) { $adminDb = kuserPeer::retrieveByPK($adminId); $workerDb = SchedulerWorkerPeer::retrieveByPK($workerId); if (!$workerDb) { throw new KalturaAPIException(KalturaErrors::WORKER_NOT_FOUND, $workerId); } $workerName = $workerDb->getName(); $schedulerId = $workerDb->getSchedulerId(); $schedulerDb = SchedulerPeer::retrieveByPK($schedulerId); if (!$schedulerDb) { throw new KalturaAPIException(KalturaErrors::SCHEDULER_NOT_FOUND, $schedulerId); } $schedulerName = $schedulerDb->getName(); $description = "Configure {$configParam} on {$schedulerName}"; if (!is_null($configParamPart)) { $description = "Configure {$configParam}.{$configParamPart} on {$schedulerName}"; } // saves the command to the DB $commandDb = new ControlPanelCommand(); $commandDb->setSchedulerId($schedulerId); $commandDb->setSchedulerConfiguredId($schedulerDb->getConfiguredId()); $commandDb->setCreatedById($adminId); $commandDb->setType(KalturaControlPanelCommandType::CONFIG); $commandDb->setStatus(KalturaControlPanelCommandStatus::PENDING); $commandDb->setDescription($description); $commandDb->setWorkerId($workerId); $commandDb->setWorkerConfiguredId($workerDb->getConfiguredId()); $commandDb->setWorkerName($workerName); $commandDb->setTargetType(KalturaControlPanelCommandTargetType::JOB); if ($adminDb) { $commandDb->setCreatedBy($adminDb->getName()); } $commandDb->setCause($cause); $commandDb->save(); // saves the new config to the DB $configDb = new SchedulerConfig(); $configDb->setSchedulerId($schedulerId); $configDb->setSchedulerConfiguredId($schedulerDb->getConfiguredId()); $configDb->setCommandId($commandDb->getId()); $configDb->setCommandStatus(KalturaControlPanelCommandStatus::PENDING); $configDb->setSchedulerName($schedulerName); $configDb->setVariable($configParam); $configDb->setVariablePart($configParamPart); $configDb->setValue($configValue); $configDb->setWorkerId($workerId); $configDb->setWorkerConfiguredId($workerDb->getConfiguredId()); $configDb->setWorkerName($workerName); if ($adminDb) { $configDb->setCreatedBy($adminDb->getName()); } $configDb->save(); $command = new KalturaControlPanelCommand(); $command->fromObject($commandDb, $this->getResponseProfile()); return $command; }
/** * This function returns the hash used secure the file uploading. * The hash is the SHA1 of the kuser salt, kuser id and given entity * If the user doesnt exist in the database the returned hash is empty - an error. * @param string $entityName = the entity object name * @param int $kuser_id = the uploading kuser id * @return string the hash */ public static function getTempUploadHash($entityName, $kuser_id, $user = NULL) { if (!$user) { $user = kuserPeer::retrieveByPK($kuser_id); } // found user in db, generate hash if ($user) { $salt = ''; // kusers didn't have salt' return $hash = sha1($salt . $kuser_id . $entityName); } return ""; }
public static function userLoginByKs($ks, $requestedPartnerId, $useOwnerIfNoUser = false) { $ksObj = kSessionUtils::crackKs($ks); $ksUserId = $ksObj->user; $ksPartnerId = $ksObj->partner_id; $kuser = null; if ((is_null($ksUserId) || $ksUserId === '') && $useOwnerIfNoUser) { KalturaLog::log('No user id on KS, trying to login as the account owner'); $partner = PartnerPeer::retrieveByPK($ksPartnerId); if (!$partner) { throw new kUserException('Invalid partner id [' . $ksPartnerId . ']', kUserException::INVALID_PARTNER); } $ksUserId = $partner->getAccountOwnerKuserId(); $kuser = kuserPeer::retrieveByPK($ksUserId); } if (!$kuser) { $kuser = kuserPeer::getKuserByPartnerAndUid($ksPartnerId, $ksUserId, true); } if (!$kuser) { throw new kUserException('User with id [' . $ksUserId . '] was not found for partner with id [' . $ksPartnerId . ']', kUserException::USER_NOT_FOUND); } return self::userLogin($kuser->getLoginData(), null, $requestedPartnerId, false); // don't validate password }
public function reSetScreenName() { $kuser = kuserPeer::retrieveByPK($this->getKuserId()); if ($kuser) { $this->setScreenName($kuser->getScreenName()); } }