public function ingest($summit_id) { $this->tx_manager->transaction(function () use($summit_id) { $summit = $this->summit_repository->getById($summit_id); if (is_null($summit)) { return; } foreach ($summit->getVenues() as $venue) { if ($venue->getTypeName() != SummitVenue::TypeName) { continue; } foreach ($venue->getRooms() as $room) { foreach ($room->getMetricTypes() as $metric) { $sample_data = $this->rest_api->getSamplesDataFromEndpointSinceTimestamp($metric->getEndpointUrl(), $metric->getLastSampleTimeStamp()); if (count($sample_data) == 0) { continue; } foreach ($sample_data as $entry) { if (count($entry) != 2) { continue; } $metric->addSample($entry[0], $entry[1]); } } } } }); }
/** * @param int $batch_size * @param string $email_alert_to * @param string $details_url */ public function makeDigest($batch_size = 15, $email_alert_to, $details_url) { $email_repository = $this->email_repository; $repository = $this->repository; $factory = $this->factory; $this->tx_manager->transaction(function () use($batch_size, $email_alert_to, $details_url, $repository, $email_repository, $factory) { $last_email = $email_repository->getLastOne(); $query = new QueryObject(); $query->addAndCondition(QueryCriteria::equal('isPosted', 0)); $query->addAndCondition(QueryCriteria::equal('isRejected', 0)); if ($last_email) { $query->addAndCondition(QueryCriteria::greater('ID', $last_email->getLastEventRegistrationRequest()->getIdentifier())); } $query->addOrder(QueryOrder::asc('PostDate')); list($list, $size) = $repository->getAll($query, 0, $batch_size); if ($list && count($list) > 0) { $last_one = end($list); reset($list); $email = EmailFactory::getInstance()->buildEmail(EVENT_REGISTRATION_REQUEST_EMAIL_FROM, $email_alert_to, "New Event Registration Requests"); $email->setTemplate('EventAlertEmail'); $email->populateTemplate(array('RegistrationRequests' => new ArrayList($list), 'Details' => $details_url)); $email->send(); $email_repository->add($factory->buildEventAlertEmail($last_one)); } }); }
/** * @param string $token * @param ICommunityMember $member * @return void */ public function confirm($token, ICommunityMember $member) { $repository = $this->repository; return $this->tx_manager->transaction(function () use($token, $member, $repository) { $old_request = $repository->getByConfirmationToken($token); if (is_null($old_request)) { throw new NotFoundEntityException('ISpeakerRegistrationRequest', sprintf("token %s", $token)); } $old_request->confirm($token); $old_request->associatedSpeaker()->associateMember($member); }); }
/** * @param int $company_id * @return void */ public function unsignCCLA($company_id) { $company_repository = $this->company_repository; return $this->tx_manager->transaction(function () use($company_id, $company_repository) { $company = $company_repository->getById($company_id); if (!$company) { throw new NotFoundEntityException('Company', sprintf(' id %s', $company_id)); } if ($company->isICLASigned()) { $company->unsignICLA(); } }); }
/** * @param int $speakerID * @param array $form_data */ public function sendEmail($speaker_id, $form_data) { $email_repository = $this->email_repository; $speaker_repository = $this->speaker_repository; $contact_email_factory = $this->contact_email_factory; $this->tx_manager->transaction(function () use($speaker_repository, $email_repository, $contact_email_factory, $speaker_id, $form_data) { $speaker = $speaker_repository->getById($speaker_id); $contact_email_data = $contact_email_factory->buildSpeakerContactEmail($form_data, $speaker); $email = EmailFactory::getInstance()->buildEmail($contact_email_data->OrgEmail, $speaker->Member()->Email, "Openstack Web Contact: " . $contact_email_data->OrgName); $email->setTemplate('SpeakerContactEmail'); $email->populateTemplate(array('EmailData' => $contact_email_data)); $contact_email_data->EmailSent = $email->send(); $email_repository->add($contact_email_data); }); }
public function processNotifications($batch_size) { $notifications_repository = $this->notifications_repository; return $this->tx_manager->transaction(function () use($batch_size, $notifications_repository) { $qty = 0; $query = new QueryObject(); $query->addAndCondition(QueryCriteria::equal('IsSent', 0)); list($list, $size) = $notifications_repository->getAll($query, 0, $batch_size); // init parse ... ParseClient::initialize(PARSE_APP_ID, PARSE_REST_KEY, PARSE_MASTER_KEY); foreach ($list as $notification) { if (empty($notification->Message)) { continue; } $message = array("data" => array('alert' => $notification->Message)); // Push to speakers try { switch ($notification->Channel) { case 'SPEAKERS': $message['channels'] = ['speakers']; break; case 'ATTENDEES': $message['channels'] = ['attendees']; break; case 'MEMBERS': $recipients = array(); foreach ($notification->Recipients() as $m) { array_push($recipients, 'me_' . $m->ID); } $message['channels'] = $recipients; break; case 'SUMMIT': $message['channels'] = ['su_' . $notification->SummitID]; break; case 'ALL': $message['where'] = ParseInstallation::query(); break; } ParsePush::send($message); $notification->sent(); ++$qty; } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::ERR); } } return $qty; }); }
/** * @param string $token * @param string $password * @param string $password_confirmation * @return Member */ public function changePassword($token, $password, $password_confirmation) { return $this->tx_manager->transaction(function () use($token, $password, $password_confirmation) { $member = Member::currentUser(); if (!$member) { if (empty($token)) { throw new InvalidResetPasswordTokenException(); } $member = Member::member_from_autologinhash($token); } if (!$member) { throw new InvalidResetPasswordTokenException(); } if (empty($password)) { throw new EmptyPasswordException(); } if ($password !== $password_confirmation) { throw new PasswordMismatchException(); } $isValid = $member->changePassword($password); if (!$isValid->valid()) { throw new InvalidPasswordException($isValid->starredList()); } //invalidate former auto login token $member->generateAutologinTokenAndStoreHash(); //send confirmation email $email = EmailFactory::getInstance()->buildEmail(CHANGE_PASSWORD_EMAIL_FROM, $member->Email, CHANGE_PASSWORD_EMAIL_SUBJECT); $email->setTemplate('ChangedPasswordEmail'); $email->populateTemplate(array('MemberName' => $member->getFullName())); $email->send(); return $member; }); }
/** * @param $summit_id * @param array $data * @return ISummitType */ public function saveSummitType($summit_id, array $data) { $this_var = $this; $summittype_repository = $this->summittype_repository; $summit_repository = $this->summit_repository; $factory = $this->summittype_factory; return $this->tx_manager->transaction(function () use($this_var, $factory, $summit_id, $data, $summit_repository, $summittype_repository) { $summit = $summit_repository->getById($summit_id); if (!$summit) { throw new NotFoundEntityException('Summit', sprintf('id %s', $summit_id)); } if (isset($data['summittype_id'])) { $summittype = $summittype_repository->getById(intval($data['summittype_id'])); $summittype->setTitle($data['title']); $summittype->setDescription($data['description']); $summittype->setAudience($data['audience']); $summittype->setStartDate($data['start_date']); $summittype->setEndDate($data['end_date']); } else { $summittype = $factory->buildSummitType($data, $summit_id); $summittype_repository->add($summittype); } return $summittype; }); }
/** * @param int $id * @param array $params * @return bool * @throws NotFoundEntityException */ public function update($id, array $params) { $res = false; $this_var = $this; $repository = $this->repository; $entity_class = $this->entity_class; $allowed_update_params = $this->allowed_update_params; $check_duplicated_entity_criteria = $this->checkDuplicatedEntityCriteria; $custom_update_logic = $this->customUpdateLogic; $this->tx_manager->transaction(function () use(&$res, $entity_class, $allowed_update_params, $id, $params, $repository, $this_var, $check_duplicated_entity_criteria, $custom_update_logic) { $entity = $this_var->getById($id); if (!$entity) { throw new NotFoundEntityException($entity_class, sprintf('id %s', $id)); } $check_duplicated_entity_criteria($id, $params); foreach ($allowed_update_params as $param) { if (array_key_exists($param, $params)) { $setter = sprintf('set%s', ucwords(str_replace('_', '', $param))); call_user_func(array($entity, $setter), $params[$param]); } } $custom_update_logic($entity, $params); }); return $res; }
public function updateLastCommittedDate($batch_size) { $batch_repository = $this->batch_repository; $member_repository = $this->member_repository; $gerrit_api = $this->gerrit_api; $batch_task_factory = $this->batch_task_factory; return $this->tx_manager->transaction(function () use($batch_size, $member_repository, $batch_repository, $gerrit_api, $batch_task_factory) { $task = $batch_repository->findByName(ICLAManager::UpdateLastCommittedDateTaskName); $last_index = 0; $members = array(); $updated_members = 0; if ($task) { $last_index = $task->lastRecordProcessed(); list($members, $total_size) = $member_repository->getAllICLAMembers($last_index, $batch_size); if ($task->lastRecordProcessed() >= $total_size) { $task->initialize($total_size); } } else { list($members, $total_size) = $member_repository->getAllICLAMembers($last_index, $batch_size); $task = $batch_task_factory->buildBatchTask(ICLAManager::UpdateLastCommittedDateTaskName, $total_size); $batch_repository->add($task); } foreach ($members as $member) { $last_commit_date = $gerrit_api->getUserLastCommit($member->getGerritId()); if (!is_null($last_commit_date) && $last_commit_date) { $member->updateLastCommitedDate($last_commit_date); ++$updated_members; } $task->updateLastRecord(); } return $updated_members; }); }
/** * @param $member * @param string $external_summit_id * @param string $external_order_id * @param string $external_attendee_id * @param string $external_ticket_class_id * @param string $bought_date * @param bool $shared_contact_info * @return ISummitAttendee */ public function registerAttendee($member, $external_summit_id, $external_order_id, $external_attendee_id, $external_ticket_class_id, $bought_date, $shared_contact_info = false) { $repository = $this->repository; $member_repository = $this->member_repository; $attendee_factory = $this->attendee_factory; $attendee_repository = $this->attendee_repository; $summit_repository = $this->summit_repository; return $this->tx_manager->transaction(function () use($member, $external_summit_id, $external_order_id, $external_attendee_id, $external_ticket_class_id, $bought_date, $shared_contact_info, $repository, $member_repository, $attendee_factory, $attendee_repository, $summit_repository) { $summit = $summit_repository->getByExternalEventId($external_summit_id); if (is_null($summit)) { throw new NotFoundEntityException('Summit', sprintf('external_summit_id %s', $external_summit_id)); } $ticket_type = $summit->findTicketTypeByExternalId($external_ticket_class_id); if (is_null($ticket_type)) { throw new NotFoundEntityException('SummitTicketType', sprintf('external_ticket_class_id %s', $external_ticket_class_id)); } $old_ticket = SummitAttendeeTicket::get()->filter(array('ExternalOrderId' => $external_order_id, 'ExternalAttendeeId' => $external_attendee_id))->first(); if (!is_null($old_ticket)) { if ($old_ticket->OwnerID > 0) { throw new EntityValidationException(sprintf('Ticket already redeem external_order_id %s - external_attendee_id %s - old attendee id %s - current member id %s !', $external_order_id, $external_attendee_id, $old_ticket->OwnerID, $member->ID)); } $old_ticket->delete(); } $ticket = $attendee_factory->buildTicket($external_attendee_id, $external_order_id, $bought_date, $bought_date, $ticket_type); $attendee = $attendee_factory->build($member, $summit); $attendee->setShareContactInfo($shared_contact_info); $attendee->addTicket($ticket); $attendee_repository->add($attendee); return $attendee; }); }
public function processCommits($batch_size) { $batch_repository = $this->batch_repository; $member_repository = $this->member_repository; $gerrit_api = $this->gerrit_api; $batch_task_factory = $this->batch_task_factory; return $this->tx_manager->transaction(function () use($batch_size, $member_repository, $batch_repository, $gerrit_api, $batch_task_factory) { $task = $batch_repository->findByName(GerritIngestManager::PullCommitsFromGerritTask); $last_index = 0; $members = array(); $updated_members = 0; if ($task) { $last_index = $task->lastRecordProcessed(); list($members, $total_size) = $member_repository->getAllICLAMembers($last_index, $batch_size); if ($task->lastRecordProcessed() >= $total_size) { $task->initialize($total_size); } } else { list($members, $total_size) = $member_repository->getAllICLAMembers($last_index, $batch_size); $task = $batch_task_factory->buildBatchTask(GerritIngestManager::PullCommitsFromGerritTask, $total_size); $batch_repository->add($task); } foreach ($members as $member) { $more_changes = false; $start_point = null; do { $changes = $gerrit_api->getUserCommits($member->getGerritId(), GerritChangeStatus::_MERGED, 250, $start_point); if (!is_null($changes) && is_array($changes) && count($changes) > 0) { $count = count($changes); $last = $changes[$count - 1]; $more_changes = isset($last['_more_changes']) ? $last['_more_changes'] : false; $start_point = $more_changes ? $last['_sortkey'] : null; foreach ($changes as $change) { $db_change = GerritChangeInfo::get()->filter(array('ChangeId' => $change['change_id']))->first(); if (!$db_change) { $db_change = new GerritChangeInfo(); $db_change->kind = @$change['kind']; $db_change->FormattedChangeId = @$change['id']; $db_change->ProjectName = @$change['project']; $db_change->Branch = @$change['branch']; $db_change->Topic = @$change['topic']; $db_change->ChangeId = @$change['change_id']; $db_change->Subject = @$change['subject']; $db_change->Status = @$change['status']; $created_date = explode('.', @$change['created']); $updated_date = explode('.', @$change['updated']); $db_change->CreatedDate = DateTime::createFromFormat('Y-m-d H:i:s', $created_date[0])->getTimestamp(); $db_change->UpdatedDate = DateTime::createFromFormat('Y-m-d H:i:s', $updated_date[0])->getTimestamp(); $db_change->MemberID = $member->getIdentifier(); $db_change->write(); } } } } while ($more_changes); ++$updated_members; $task->updateLastRecord(); } return $updated_members; }); }
/** * @param int $id * @param array $data * @param string $event_link * @return void */ public function rejectEventRegistration($id, array $data, $event_link) { $this_var = $this; $validator_factory = $this->validator_factory; $repository = $this->event_registration_request_repository; return $this->tx_manager->transaction(function () use($this_var, $id, $data, $validator_factory, $repository, $event_link) { $validator = $validator_factory->buildValidatorForEventRejection($data); if ($validator->fails()) { throw new EntityValidationException($validator->messages()); } $request = $repository->getById(intval($id)); if (!$request) { throw new NotFoundEntityException('EventRegistrationRequest', sprintf('id %s', $id)); } $request->markAsRejected(); if (@$data['send_rejection_email']) { //send rejection message $point_of_contact = $request->getPointOfContact(); $name_to = $point_of_contact->getName(); $email_to = $point_of_contact->getEmail(); if (empty($name_to) || empty($email_to)) { throw new EntityValidationException(array(array('message' => 'invalid point of contact'))); } $email = EmailFactory::getInstance()->buildEmail(EVENT_REGISTRATION_REQUEST_EMAIL_FROM, $email_to, "Your Recent OpenStack Event Submission"); $email->setTemplate('EventRegistrationRequestRejectedEmail'); $email->populateTemplate(array('EventLink' => $event_link, 'EventsEmailFrom' => EVENT_REGISTRATION_REQUEST_EMAIL_FROM, 'AdditionalComment' => @$data['custom_reject_message'])); $email->send(); } }); }
/** * return GPS coordinates array($lat,$lng) * @param string $city * @param string $country * @param string|null $state * @param string|null $address * @param string|null $zip_code * @throws EntityValidationException * @return array */ private function doGeoQuery($city, $country, $state = null, $address = null, $zip_code = null) { $formatted_city = urlencode($city); $query = "?components=locality:{$formatted_city}|country:{$country}"; if (!empty($state)) { $formatted_state = urlencode($state); $query .= "|administrative_area:{$formatted_state}"; } if (!empty($address)) { $formatted_address = urlencode($address); $query .= "|address:{$formatted_address}"; } if (!empty($zip_code)) { $formatted_zip_code = urlencode($zip_code); $query .= "&postal_code={$formatted_zip_code}"; } $query .= "&sensor=false"; $url = self::ApiBaseUrl . $query; if ($this->shouldUseKey()) { $url .= "&key={$this->api_key}"; } else { if ($this->shouldSignUrl()) { $url = $this->signUrl($url); } } $factory = $this->factory; $repository = $this->repository; return $this->tx_manager->transaction(function () use($repository, $factory, $url, $query, $city, $country, $state, $address, $zip_code) { $res = $repository->getByGeoQuery($query); if ($res) { return array($res->getLat(), $res->getLng()); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, GoogleGeoCodingService::ApiHost . $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXYPORT, 3128); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $response = curl_exec($ch); curl_close($ch); $response_a = json_decode($response); if (is_null($response_a)) { if (!empty($address)) { throw new EntityValidationException(array(array('message' => sprintf('Address %s (%s) does not exist on City %s', $address, $zip_code, $city)))); } else { throw new EntityValidationException(array(array('message' => sprintf('City %s does not exist on Country %s', $city, $country)))); } } if ($response_a->status != 'OK') { if (!empty($address)) { throw new EntityValidationException(array(array('message' => sprintf('Address %s (%s) does not exist on City %s - (STATUS: %s)', $address, $zip_code, $city, $response_a->status)))); } else { throw new EntityValidationException(array(array('message' => sprintf('City %s does not exist on Country %s (STATUS: %s)', $city, $country, $response_a->status)))); } } $repository->add($factory->buildGeoCodingQuery($query, $response_a->results[0]->geometry->location->lat, $response_a->results[0]->geometry->location->lng)); return array($response_a->results[0]->geometry->location->lat, $response_a->results[0]->geometry->location->lng); }); }
/** * @param ISurvey $survey * @param ISurveyAutopopulationStrategy $strategy * @return mixed */ public function doAutopopulation(ISurvey $survey, ISurveyAutopopulationStrategy $strategy) { $survey_builder = $this->survey_builder; $this_var = $this; $this->tx_manager->transaction(function () use($survey, $strategy, $survey_builder, $this_var) { $strategy->autoPopulate($survey, $survey_builder, $this_var); }); }
/** * @param int $course_id */ public function unRegister($course_id) { $repository = $this->course_repository; $this->tx_manager->transaction(function () use($course_id, $repository) { $course = $repository->getBydId($course_id); $repository->delete($course); }); }
/** * return GPS coordinates array($lat,$lng) * @param string $city * @param string $country * @param string|null $state * @param string|null $address * @param string|null $zip_code * @throws EntityValidationException * @return array */ private function doGeoQuery($city, $country, $state = null, $address = null, $zip_code = null) { return $this->tx_manager->transaction(function () use($city, $country, $state, $address, $zip_code) { $query = []; $formatted_city = urlencode($city); $components = "locality:{$formatted_city}|country:{$country}"; if (!empty($state)) { $formatted_state = urlencode($state); $components .= "|administrative_area:{$formatted_state}"; } if (!empty($address)) { $formatted_address = urlencode($address); $components .= "|address:{$formatted_address}"; } $query['components'] = $components; if (!empty($zip_code)) { $query['postal_code'] = urlencode($zip_code); } $res = $this->repository->getByGeoQuery(http_build_query($query)); if ($res) { return [$res->getLat(), $res->getLng()]; } $url = self::ApiBaseUrl . '?' . http_build_query($query); if ($this->shouldUseKey()) { $query['key'] = $this->api_key; } else { if ($this->shouldSignUrl()) { $query['client'] = $this->client_id; $query['signature'] = $this->calculateSignature($url); } } $response = null; try { $client = new \GuzzleHttp\Client(); $response = json_decode($client->get(self::ApiHost . self::ApiBaseUrl, ['query' => $query])->getBody()); $client = null; } catch (Exception $ex) { SS_Log::log($ex, SS_Log::ERR); throw new EntityValidationException([['message' => 'server error']]); } if (is_null($response)) { if (!empty($address)) { throw new EntityValidationException([['message' => sprintf('Address %s (%s) does not exist on City %s', $address, $zip_code, $city)]]); } throw new EntityValidationException([['message' => sprintf('City %s does not exist on Country %s', $city, $country)]]); } if ($response->status != 'OK') { if (!empty($address)) { throw new EntityValidationException([['message' => sprintf('Address %s (%s) does not exist on City %s - (STATUS: %s)', $address, $zip_code, $city, $response->status)]]); } throw new EntityValidationException([['message' => sprintf('City %s does not exist on Country %s (STATUS: %s)', $city, $country, $response->status)]]); } $geo_query = $this->factory->buildGeoCodingQuery(http_build_query($query), $response->results[0]->geometry->location->lat, $response->results[0]->geometry->location->lng); $this->repository->add($geo_query); return [$response->results[0]->geometry->location->lat, $response->results[0]->geometry->location->lng]; }); }
/** * @return void */ public function run() { $start = time(); $this->tx_manager->transaction(function () { $releases = OpenStackRelease::get()->where(" Name <> 'Trunk' ")->sort('ReleaseDate', 'DESC'); DB::query('DELETE FROM OpenStackComponentReleaseCaveat;'); $this->processProjects(); foreach ($releases as $release) { echo sprintf('processing release %s ...', $release->Name) . PHP_EOL; $this->getProductionUseStatus($release); $this->getInstallationGuideStatus($release); $this->getSDKSupport($release); $this->getQualityOfPackages($release); $this->calculateMaturityPoints($release); $this->getStackAnalytics($release); } }); $delta = time() - $start; echo sprintf('task took %s seconds to run.', $delta) . PHP_EOL; $this->client = null; }
/** * @param string $icla_group_id * @return int */ public function processICLAGroup($icla_group_id) { $member_repository = $this->member_repository; $gerrit_api = $this->gerrit_api; return $this->tx_manager->transaction(function () use($icla_group_id, $member_repository, $gerrit_api) { // query gerrit service $icla_members_response = $gerrit_api->listAllMembersFromGroup($icla_group_id); $icla_members_count = count($icla_members_response); if ($icla_members_count === 0) { return; } //nothing to process... $gerrit_users = 0; foreach ($icla_members_response as $gerrit_info) { $email = @$gerrit_info['email']; $account_id = @$gerrit_info['_account_id']; if (!empty($email) && !empty($account_id)) { $member = $member_repository->findByEmail($email); if ($member) { if (is_null($member->addGerritUser($account_id, $email))) { continue; } ++$gerrit_users; } else { // we dont have a member associated with it :/ // check by account id if (!is_null($member_repository->getGerritUserByAccountId($account_id))) { continue; } $gerrit_user = new GerritUser(); $gerrit_user->AccountID = $account_id; $gerrit_user->Email = $email; $gerrit_user->write(); ++$gerrit_users; } } } return $gerrit_users; }); }
/** * Register an speaker and confirm the registration request if exists * @param array $data * @param IMessageSenderService $sender_service * @return Member * @throws EntityValidationException * @throws Exception */ public function registerSpeaker(array $data, IMessageSenderService $sender_service) { $repository = $this->repository; $group_repository = $this->group_repository; $factory = $this->factory; $group_factory = $this->group_factory; $speaker_registration_request_manager = $this->speaker_registration_request_manager; try { return $this->tx_manager->transaction(function () use($data, $repository, $group_repository, $factory, $group_factory, $speaker_registration_request_manager, $sender_service) { $mandatory_fields = array('Email' => 'Email', 'FirstName' => 'First Name', 'Surname' => 'Surname', 'Password' => 'Password'); foreach ($mandatory_fields as $mf => $fn) { if (!isset($data[$mf]) || empty($data[$mf])) { throw new EntityValidationException(sprintf('%s is a mandatory field!.', $fn)); } } if (!isset($data['Password']['_Password']) || !isset($data['Password']['_ConfirmPassword']) || $data['Password']['_ConfirmPassword'] !== $data['Password']['_Password']) { throw new EntityValidationException('Password is a mandatory field!.'); } $old_member = $repository->findByEmail(Convert::raw2sql($data['Email'])); if (!is_null($old_member)) { throw new EntityValidationException('Sorry, that email address already exists. Please choose another.'); } $member = $factory->buildReduced($data); $member->write(); $member->convert2SiteUser(); $speakers_group = $group_repository->getByCode(ISecurityGroupFactory::SpeakersGroupCode); if (is_null($speakers_group)) { // create group $speakers_group = $group_factory->build(ISecurityGroupFactory::SpeakersGroupCode); $speakers_group->write(); } $member->addToGroupByCode(ISecurityGroupFactory::SpeakersGroupCode); if (!empty($data[SpeakerRegistrationRequest::ConfirmationTokenParamName])) { $speaker_registration_token = $data[SpeakerRegistrationRequest::ConfirmationTokenParamName]; $speaker_registration_request_manager->confirm($speaker_registration_token, $member); } if (!is_null($sender_service)) { $sender_service->send($member); } //force write, $member->write(); PublisherSubscriberManager::getInstance()->publish('new_user_registered', array($member->ID)); return $member; }); } catch (EntityValidationException $ex1) { SS_Log::log($ex1->getMessage(), SS_Log::WARN); throw $ex1; } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::ERR); throw $ex; } }
/** * @param string $token * @param IMessageSenderService $sender_service * @throws NotFoundEntityException * @return Member */ public function verify($token, IMessageSenderService $sender_service) { $repository = $this->repository; return $this->tx_manager->transaction(function () use($token, $repository, $sender_service) { $member = $repository->getByEmailVerificationToken($token); if (is_null($member)) { throw new NotFoundEntityException('Member', sprintf('email verification token %s', $token)); } $member->doEmailConfirmation($token); $sender_service->send($member); return $member; }); }
/** * @param IPresentation $presentation * @param IPresentationSpeaker $speaker * @return void */ public function removeSpeakerFrom(IPresentation $presentation, IPresentationSpeaker $speaker) { return $this->tx_manager->transaction(function () use($presentation, $speaker) { if (!$presentation->canRemoveSpeakers()) { throw new EntityValidationException('You cannot remove speakers from this presentation'); } if ($presentation->isModerator($speaker)) { $presentation->unsetModerator(); return; } $presentation->removeSpeaker($speaker); }); }
/** * @param int $team_id */ public function removeTeam($team_id) { $team_repository = $this->team_repository; $this->tx_manager->transaction(function () use($team_id, $team_repository) { $team = $team_repository->getById($team_id); if (!$team) { throw new NotFoundEntityException('Team', sprintf(' id %s', $team_id)); } $team->clearMembers(); $team->clearInvitations(); $team_repository->delete($team); }); }
/** * @param int $member_id * @param int $foreign_id * @return void */ public function markAsNotMyAccount($member_id, $foreign_id) { $member_repository = $this->member_repository; $factory = $this->not_my_account_factory; $foreign_repository = $this->not_my_account_repository; return $this->tx_manager->transaction(function () use($member_id, $foreign_id, $member_repository, $factory, $foreign_repository) { $current_member = $member_repository->getById($member_id); $foreign_member = $member_repository->getById($foreign_id); if (!is_null($current_member) && !is_null($foreign_member)) { $action = $factory->build($current_member, $foreign_member); $foreign_repository->add($action); } }); }
/** * Moves articles from standby to recent when the embargo date is reached . */ public function activateNews() { $repository = $this->news_repository; return $this->tx_manager->transaction(function () use($repository) { $activate_news = $repository->getNewsToActivate(); if ($activate_news) { foreach ($activate_news as $article) { $article->registerSection('recent'); $article->registerRank(1); } $this->reorderArticles('recent', $repository); } }); }
public function forgotPassword($data) { $email = isset($data['Email']) ? Convert::raw2sql($data['Email']) : null; try { if (empty($email)) { throw new EntityValidationException('Please enter an email address to get a password reset link.'); } $member = Member::get()->filter('Email', $email)->first(); // Allow vetoing forgot password requests $results = $this->extend('forgotPassword', $member); if ($results && is_array($results) && in_array(false, $results, true)) { return $this->controller->redirect('Security/lostpassword'); } if ($member) { $token = $this->tx_manager->transaction(function () use($member) { return $member->generateAutologinTokenAndStoreHash(); }); $e = Member_ForgotPasswordEmail::create(); $e->populateTemplate($member); $e->populateTemplate(array('PasswordResetLink' => Security::getPasswordResetLink($member, $token))); $e->setTo($member->Email); $e->send(); $this->controller->redirect('Security/passwordsent/' . urlencode($email)); } // Avoid information disclosure by displaying the same status, // regardless wether the email address actually exists $this->controller->redirect('Security/passwordsent/' . urlencode($email)); } catch (EntityValidationException $ex1) { $this->sessionMessage($ex1->getMessage(), 'bad'); SS_Log::log($ex1->getMessage(), SS_Log::WARN); $this->controller->redirect('Security/lostpassword'); } catch (Exception $ex) { $this->sessionMessage('There was an error with your request!', 'bad'); SS_Log::log($ex->getMessage(), SS_Log::ERR); $this->controller->redirect('Security/lostpassword'); } }
function saveRssEvents($events_array) { foreach ($events_array as $event) { $filter_array = array(); $filter_array["EventEndDate"] = $event->EventEndDate; $filter_array["ExternalSourceId"] = $event->ExternalSourceId; $count = EventPage::get()->filter($filter_array)->Count(); $event_repository = $this->event_repository; if ($count == 0) { $this->tx_manager->transaction(function () use($event_repository, $event) { $event_repository->add($event); }); } } }
/** * @param array $data * @return IEntity|void * @throws EntityAlreadyExistsException * @throws NotFoundEntityException */ public function updateCompanyService(array $data) { $this_var = $this; $validator_factory = $this->validator_factory; $repository = $this->repository; $marketplace_factory = $this->marketplace_factory; $company_service = $this->tx_manager->transaction(function () use(&$company_service, $this_var, $marketplace_factory, $data, $validator_factory, $repository) { $validator = $validator_factory->buildValidatorForCompanyService($data); if ($validator->fails()) { return $this_var->validationError($validator->messages()); } $id = intval($data['id']); $company_service = $repository->getById($id); if (!$company_service) { throw new NotFoundEntityException('CompanyService', sprintf("id %s", $id)); } $company_service->setName($data['name']); if ($company_service->isDraft()) { $live_service_id = isset($data['live_service_id']) ? $data['live_service_id'] : 0; $published = isset($data['published']) ? $data['published'] : 0; $company_service->setPublished($published); $company_service->setLiveServiceId($live_service_id); } $query = new QueryObject($company_service); $query->addAndCondition(QueryCriteria::equal('Name', $company_service->getName())); $query->addAndCondition(QueryCriteria::equal('Company.ID', $company_service->getCompany()->getIdentifier())); $query->addAndCondition(QueryCriteria::notId('ID', $id)); $res = $repository->getBy($query); if ($res) { throw new EntityAlreadyExistsException('CompanyService', sprintf('name %s', $company_service->getName())); } $this_var->update($company_service, $data); $clearCollections = new ReflectionMethod(get_class($this_var), 'clearCollections'); $clearCollections->setAccessible(true); $clearCollections->invoke($this_var, $company_service); $updateCollections = new ReflectionMethod(get_class($this_var), 'updateCollections'); $updateCollections->setAccessible(true); $updateCollections->invoke($this_var, $company_service, $data); // send notification to admins $username = Member::currentUser()->getName(); $email_subject = "Update on " . $company_service->getName(); $email_body = $company_service->getName() . " was just updated by " . $username . ".\n Please go <a href='https://openstack.org/marketplaceadmin/'>here</a> to review the data.\n <br><br>Thank you,<br>Marketplace Admin"; $email = EmailFactory::getInstance()->buildEmail('*****@*****.**', MARKETPLACE_ADMIN_UPDATE_EMAIL_TO, $email_subject, $email_body); $email->send(); return $company_service; }); return $company_service; }
/** * @param $data * @return mixed */ public function addFeedback($data) { $eventfeedback_repository = $this->eventfeedback_repository; $eventfeedback_factory = $this->eventfeedback_factory; $attendee_repository = $this->attendee_repository; return $this->tx_manager->transaction(function () use($data, $attendee_repository, $eventfeedback_repository, $eventfeedback_factory) { $member_id = intval($data['member_id']); $summit_id = intval($data['summit_id']); $attendee = $attendee_repository->getByMemberAndSummit($member_id, $summit_id); if (!$attendee) { throw new NotFoundEntityException('Attendee', ''); } $feedback = $eventfeedback_factory->buildEventFeedback($data); return $eventfeedback_repository->add($feedback); }); }
/** * @param ISummit $summit * @param array $event_data * @return mixed */ public function updateEvent(ISummit $summit, array $event_data) { $event_repository = $this->event_repository; return $this->tx_service->transaction(function () use($summit, $event_data, $event_repository) { if (!isset($event_data['id'])) { throw new EntityValidationException(array('missing required param: id')); } $event_id = intval($event_data['id']); $event = $event_repository->getById($event_id); if (is_null($event)) { throw new NotFoundEntityException('Summit Event', sprintf('id %s', $event_id)); } if (intval($event->SummitID) !== intval($summit->getIdentifier())) { throw new EntityValidationException(array('event doest not belongs to summit')); } $event->Title = $event_data['title']; $event->Description = $event_data['description']; $event->setStartDate($event_data['start_date']); $event->setEndDate($event_data['end_date']); $event->AllowFeedBack = $event_data['allow_feedback']; $event->LocationID = intval($event_data['location_id']); $event->TypeID = intval($event_data['event_type']); $event->AllowedSummitTypes()->setByIDList($event_data['summit_type']); $event->Tags()->setByIDList(explode(',', $event_data['tags'])); $event->Sponsors()->setByIDList(explode(',', $event_data['sponsors'])); // Speakers, if one of the added members is not a speaker, we need to make him one if ($event->isPresentation()) { $presentation = $event_repository->getPresentationById($event_id); $speaker_ids = array(); $member_ids = explode(',', $event_data['speakers']); foreach ($member_ids as $member_id) { $speaker = PresentationSpeaker::get()->filter('MemberID', $member_id)->first(); if (!$speaker) { $member = Member::get()->byID($member_id); $speaker = new PresentationSpeaker(); $speaker->FirstName = $member->FirstName; $speaker->LastName = $member->Surname; $speaker->MemberID = $member->ID; $speaker->write(); } $speaker_ids[] = $speaker->ID; } $event->Speakers()->setByIDList($speaker_ids); } return $event; }); }