Fix on summit schedule ingest when speaker is not found
or speaker email is empty Change-Id: I78bf7a22e3a576de01a917c972fe4a976f57f2ac
This commit is contained in:
parent
6dcaf89287
commit
dc19042816
@ -65,5 +65,7 @@ abstract class AbstractExternalScheduleFeed implements IExternalScheduleFeed
|
||||
}
|
||||
}
|
||||
|
||||
abstract public function getDefaultSpeakerEmail(string $speakerFullName):string;
|
||||
|
||||
|
||||
}
|
@ -94,14 +94,18 @@ final class SchedScheduleFeed extends AbstractExternalScheduleFeed
|
||||
foreach($response as $speaker){
|
||||
if(!isset($speaker['name'])) continue;
|
||||
$speakerFullNameParts = explode(" ", $speaker['name']);
|
||||
$speakerFirstName = trim(trim(array_pop($speakerFullNameParts)));
|
||||
$speakerLastName = trim(implode(" ", $speakerFullNameParts));
|
||||
$speakerLastName = trim(trim(array_pop($speakerFullNameParts)));
|
||||
$speakerFirstName = trim(implode(" ", $speakerFullNameParts));
|
||||
$email = trim($speaker['email']);
|
||||
|
||||
if(empty($email))
|
||||
$email = $this->getDefaultSpeakerEmail(trim($speaker['name']));
|
||||
|
||||
$speakers[trim($speaker['name'])] = [
|
||||
'full_name' => trim($speaker['name']),
|
||||
'first_name' => trim($speakerFirstName),
|
||||
'last_name' => trim($speakerLastName),
|
||||
'email' => trim($speaker['email']),
|
||||
'email' => $email,
|
||||
'company' => trim($speaker['company']),
|
||||
'position' => trim($speaker['position']),
|
||||
'avatar' => trim($speaker['avatar']),
|
||||
@ -110,4 +114,9 @@ final class SchedScheduleFeed extends AbstractExternalScheduleFeed
|
||||
|
||||
return $speakers;
|
||||
}
|
||||
|
||||
public function getDefaultSpeakerEmail(string $speakerFullName): string
|
||||
{
|
||||
return sprintf("%s@sched.com", ltrim(str_replace(",", "",str_replace(" ", "",strtolower($speakerFullName)))), ".");
|
||||
}
|
||||
}
|
@ -54,7 +54,7 @@ final class VanderpoelScheduleFeed extends AbstractExternalScheduleFeed
|
||||
'full_name' => $speakerFullName,
|
||||
'first_name' => trim($speaker['first_name']),
|
||||
'last_name' => trim($speaker['last_name']),
|
||||
'email' => sprintf("%s@vanderpoel.com", $speakerFullName),
|
||||
'email' => $this->getDefaultSpeakerEmail($speakerFullName),
|
||||
'company' => trim($speaker['company']),
|
||||
'position' => trim($speaker['job_title']),
|
||||
'avatar' => trim($speaker['photo']),
|
||||
@ -83,4 +83,9 @@ final class VanderpoelScheduleFeed extends AbstractExternalScheduleFeed
|
||||
{
|
||||
return $this->speakers;
|
||||
}
|
||||
|
||||
public function getDefaultSpeakerEmail(string $speakerFullName): string
|
||||
{
|
||||
return sprintf("%s@vanderpoel.com", strtolower($speakerFullName));
|
||||
}
|
||||
}
|
@ -207,10 +207,18 @@ final class ScheduleIngestionService
|
||||
if (isset($event['speakers'])) {
|
||||
foreach ($event['speakers'] as $speakerFullName) {
|
||||
$speakerFullNameParts = explode(" ", $speakerFullName);
|
||||
$speakerFirstName = trim(trim(array_pop($speakerFullNameParts)));
|
||||
$speakerLastName = trim(implode(" ", $speakerFullNameParts));
|
||||
$speakerLastName = trim(trim(array_pop($speakerFullNameParts)));
|
||||
$speakerFirstName = trim(implode(" ", $speakerFullNameParts));
|
||||
|
||||
$foundSpeaker = isset($speakers[$speakerFullName]) ? $speakers[$speakerFullName] : null;
|
||||
if(is_null($foundSpeaker)){
|
||||
// partial match
|
||||
$result_array = preg_grep("/{$speakerFullName}/i",array_keys($speakers));
|
||||
if(count($result_array) > 0){
|
||||
$foundSpeaker = $speakers[array_values($result_array)[0]];
|
||||
}
|
||||
}
|
||||
|
||||
$speakerEmail = $foundSpeaker && isset($foundSpeaker['email']) ? $foundSpeaker['email'] : null;
|
||||
$companyName = $foundSpeaker && isset($foundSpeaker['company']) ? $foundSpeaker['company'] : null;
|
||||
$companyPosition = $foundSpeaker && isset($foundSpeaker['position']) ? $foundSpeaker['position'] : null;;
|
||||
|
@ -19,8 +19,10 @@ use Mockery;
|
||||
use models\summit\Summit;
|
||||
use App\Services\Apis\ExternalScheduleFeeds\IExternalScheduleFeedFactory;
|
||||
use App\Services\Apis\ExternalScheduleFeeds\ExternalScheduleFeedFactory;
|
||||
use models\summit\SummitVenue;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use App\Services\Model\IScheduleIngestionService;
|
||||
/**
|
||||
* Class ExternalFeedIngestionTest
|
||||
* @package Tests
|
||||
@ -43,10 +45,18 @@ JSON;
|
||||
JSON;
|
||||
|
||||
$summit = new Summit();
|
||||
$summit->setActive(true);
|
||||
// set feed type (sched)
|
||||
$summit->setApiFeedType(IExternalScheduleFeedFactory::SchedType);
|
||||
$summit->setApiFeedUrl("https://localhost.com");
|
||||
$summit->setApiFeedKey("secret");
|
||||
$summit->setTimeZoneId("America/Chicago");
|
||||
$summit->setBeginDate(new \DateTime("2019-03-12"));
|
||||
$summit->setEndDate(new \DateTime("2019-03-16"));
|
||||
|
||||
$mainVenue = new SummitVenue();
|
||||
$mainVenue->setIsMain(true);
|
||||
$summit->addLocation($mainVenue);
|
||||
|
||||
$factory = new ExternalScheduleFeedFactory();
|
||||
// mock events response
|
||||
@ -78,6 +88,10 @@ JSON;
|
||||
|
||||
$this->assertTrue(count($events) == 218);
|
||||
$this->assertTrue(count($speakers) == 1009);
|
||||
|
||||
$service = App::make(IScheduleIngestionService::class);
|
||||
|
||||
$service->ingestSummit($summit);
|
||||
}
|
||||
|
||||
public function testGetSummitWithFeeds(){
|
||||
|
Loading…
Reference in New Issue
Block a user