Skip to content

Commit db069c5

Browse files
committed
[smarcet] - #13346
* tweaked slide deck upload code to be able to send out before summit started
1 parent 4f5aa41 commit db069c5

6 files changed

Lines changed: 146 additions & 30 deletions

File tree

summit/code/infrastructure/active_records/events/presentations/PresentationSpeaker.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,4 +1583,28 @@ public function getAvgFeedback(ISummit $summit){
15831583

15841584
return $count ? round($sum/$count,1) : 0;
15851585
}
1586+
1587+
/**
1588+
* @param ISummit $summit
1589+
*/
1590+
public function registerUploadSlidesRequestEmail(ISummit $summit){
1591+
$notification = new PresentationSpeakerUploadPresentationMaterialEmail();
1592+
$notification->SpeakerID = $this->ID;
1593+
$notification->SummitID = $summit->ID;
1594+
$notification->SentDate = MySQLDatabase56::nowRfc2822();
1595+
$notification->write();
1596+
}
1597+
1598+
/**
1599+
* @param ISummit $summit
1600+
* @return bool
1601+
*/
1602+
public function hasUploadSlidesRequestEmail(ISummit $summit){
1603+
return PresentationSpeakerUploadPresentationMaterialEmail::get()->filter(
1604+
[
1605+
'SummitID' => $summit->ID,
1606+
'SpeakerID' => $this->ID
1607+
]
1608+
)->count() > 0;
1609+
}
15861610
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright 2017 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
/**
16+
* Class PresentationSpeakerUploadSlidesNotificationEmailMessageSender
17+
*/
18+
final class PresentationSpeakerUploadSlidesNotificationEmailMessageSender
19+
implements IMessageSenderService
20+
{
21+
22+
/**
23+
* @param mixed $subject
24+
* @throws InvalidArgumentException
25+
* @return void
26+
*/
27+
public function send($subject)
28+
{
29+
if(!is_array($subject)) return;
30+
if(!isset($subject['Presentations']) || !isset($subject['Speaker']) || !isset($subject['Summit'])) return;
31+
32+
$presentations = $subject['Presentations'];
33+
$speaker = $subject['Speaker'];
34+
$summit = $subject['Summit'];
35+
36+
// check if template exists
37+
$email_template = PermamailTemplate::get_by_identifier('upload-presentation-slides-email');
38+
if (is_null($email_template)) {
39+
return;
40+
}
41+
42+
$from = null;
43+
$subject = null;
44+
$email = EmailFactory::getInstance()->buildEmail($from, $speaker->getEmail(), $subject);
45+
46+
$email->setUserTemplate('upload-presentation-slides-email');
47+
48+
$email->populateTemplate
49+
(
50+
[
51+
52+
'Presentations' => $presentations,
53+
'Speaker' => $speaker,
54+
'Summit' => $summit,
55+
// @see class PresentationSlideSubmissionController::presentations
56+
'UploadSlidesURL' => Director::absoluteURL("submit-slides/presentations")
57+
]
58+
);
59+
60+
$email->send();
61+
62+
$speaker->registerUploadSlidesRequestEmail($summit);
63+
}
64+
}

summit/code/models/IPresentationSpeaker.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,15 @@ public function hasRejectedPresentations
486486
*/
487487
public function isModeratorFor(ISummit $summit);
488488

489+
/**
490+
* @param ISummit $summit
491+
*/
492+
public function registerUploadSlidesRequestEmail(ISummit $summit);
493+
494+
/**
495+
* @param ISummit $summit
496+
* @return bool
497+
*/
498+
public function hasUploadSlidesRequestEmail(ISummit $summit);
499+
489500
}

summit/code/models/managers/SpeakerEmailAnnouncementSenderManager.php

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -258,47 +258,67 @@ public function sendModeratorsSelectionAnnouncementBySummit(ISummit $current_sum
258258
public function sendUploadSlidesAnnouncementBySummit(ISummit $current_summit, $batch_size)
259259
{
260260
return $this->tx_manager->transaction(function () use ($current_summit, $batch_size) {
261-
list($count, $speakers) = $this->speaker_repository->searchSpeakerBySummitPaginatedForUploadSlidesAnnouncement($current_summit, 1, $batch_size, $current_summit->getExcludedTracksForUploadPresentationSlideDeck());
261+
$sender_service = new PresentationSpeakerUploadSlidesNotificationEmailMessageSender();
262+
263+
$page = 1;
264+
$page_size = $batch_size;
265+
$task = $this->batch_repository->findByName(self::TaskName . '_SLIDE_UPLOAD_' . $current_summit->getIdentifier());
266+
267+
if (is_null($task)) {
268+
//create task
269+
$task = $this->batch_task_factory->buildBatchTask(self::TaskName . '_SLIDE_UPLOAD_' . $current_summit->getIdentifier(), 0, $page);
270+
$this->batch_repository->add($task);
271+
}
272+
273+
$page = $task->getCurrentPage();
274+
echo "Processing Page " . $page . PHP_EOL;
275+
276+
list($page, $page_size, $count, $speakers) = $this->speaker_repository->searchBySummitSchedulePaginated
277+
(
278+
$current_summit,
279+
$page,
280+
$page_size
281+
);
282+
262283
$send = 0;
284+
echo sprintf('total speakers %s - page count %s', $count, count($speakers)).PHP_EOL;
263285

264286
foreach ($speakers as $speaker) {
265-
/* @var DataList */
266287
if(!$speaker instanceof IPresentationSpeaker) continue;
267288

268-
$presentations = $speaker->PublishedPresentations($current_summit->ID);
269-
270-
if (!$presentations->exists()) {
271-
echo "Skipping {$speaker->getName()}. Has no published presentations" . PHP_EOL;
289+
// we need an email for this speaker ...
290+
$email = $speaker->getEmail();
291+
if (empty($email) || !EmailValidator::validEmail($email)){
292+
echo sprintf("Skipping %s (%s). Has not valid email", $speaker->getName(), $speaker->ID) . PHP_EOL;
272293
continue;
273294
}
274295

275-
if (!$speaker->Member()->exists() || !EmailValidator::validEmail($speaker->Member()->Email)) {
276-
echo $speaker->getName()." (".$speaker->Member()->Email . ") is not a valid email address. Skipping." . PHP_EOL;
296+
$presentations = $speaker->AllPublishedPresentations($current_summit->getIdentifier(), $current_summit->getExcludedTracksForUploadPresentationSlideDeck());
297+
298+
if($presentations->Count() == 0){
299+
echo sprintf("skipping speaker %s (%s) - no published presentations available", $speaker->getName(), $speaker->getEmail()).PHP_EOL;
277300
continue;
278301
}
279302

280-
$to = $speaker->Member()->Email;
281-
$subject = "Important Speaker Information for OpenStack Summit in {$current_summit->Title}";
282-
283-
$email = EmailFactory::getInstance()->buildEmail('do-not-reply@openstack.org', $to, $subject);
303+
if($speaker->hasUploadSlidesRequestEmail($current_summit)){
304+
echo sprintf("skipping speaker %s (%s) - email already sent!", $speaker->getName(), $speaker->getEmail()).PHP_EOL;
305+
continue;
306+
}
284307

285-
$email->setUserTemplate("upload-presentation-slides-email");
286-
$email->populateTemplate([
287-
'Speaker' => $speaker,
308+
$sender_service->send([
288309
'Presentations' => $presentations,
289-
'Summit' => $current_summit
310+
'Speaker' => $speaker,
311+
'Summit' => $current_summit,
290312
]);
291313

292-
$email->send();
293-
294-
$notification = new PresentationSpeakerUploadPresentationMaterialEmail();
295-
$notification->SpeakerID = $speaker->ID;
296-
$notification->SummitID = $current_summit->ID;
297-
$notification->SentDate = MySQLDatabase56::nowRfc2822();
298-
$notification->write();
299314
++$send;
300-
echo 'Email sent to ' . $to . ' (' . $speaker->getName() . ')' . PHP_EOL;
315+
316+
echo sprintf('sending email to %s', $email) . PHP_EOL;
301317
}
318+
319+
$task->updatePage($count, $page_size);
320+
$task->write();
321+
302322
return $send;
303323
});
304324
}

summit/code/models/repositories/ISpeakerRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function searchBySummitPaginated(ISummit $summit, $page= 1, $page_size =
6666
* @param string $sort_dir
6767
* @return array
6868
*/
69-
public function searchBySummitSchedulePaginated(ISummit $summit, $page= 1, $page_size = 10, $term = '', $sort_by = 'id', $sort_dir = 'asc');
69+
public function searchBySummitSchedulePaginated(ISummit $summit, $page = 1, $page_size = 10, $term = '', $sort_by = 'id', $sort_dir = 'asc');
7070

7171
/**
7272
* @param int $page

summit/code/pages/PresentationSlideSubmissionController.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function presentations(SS_HTTPRequest $r)
7979

8080
Session::set('UploadMedia.SpeakerID', $speaker->ID);
8181

82-
$mostRecentSummit = Summit::get_most_recent();
83-
$presentations = $speaker->PublishedPresentations($mostRecentSummit->ID);
82+
$activeSummit = Summit::get_active();
83+
$presentations = $speaker->PublishedPresentations($activeSummit->ID);
8484

8585
// No presentations
8686
if (!$presentations->exists()) {
@@ -130,9 +130,6 @@ public function handlePresentation(SS_HTTPRequest $r)
130130
]);
131131
}
132132

133-
134-
135-
136133
}
137134

138135
/**

0 commit comments

Comments
 (0)