Fix on mising presentation material data updates

added missing presentation material events

Change-Id: I5bcfcb3b601d2b091e0a75de0873672a1f7b2b65
This commit is contained in:
Sebastian Marcet 2016-10-24 10:47:56 -03:00
parent ba392e405c
commit 003d615d8b
6 changed files with 225 additions and 35 deletions

View File

@ -0,0 +1,76 @@
<?php namespace App\Events;
/**
* Copyright 2016 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Illuminate\Queue\SerializesModels;
use models\summit\Presentation;
/**
* Class PresentationMaterialDeleted
* @package App\Events
*/
class PresentationMaterialDeleted extends Event
{
use SerializesModels;
/**
* @var Presentation
*/
private $presentation;
/**
* @var int
*/
private $material_id;
/**
* @var string
*/
private $class_name;
/**
* PresentationMaterialDeleted constructor.
* @param Presentation $presentation
* @param int $material_id
* @param string $class_name
*/
public function __construct(Presentation $presentation, $material_id, $class_name)
{
$this->presentation = $presentation;
$this->material_id = $material_id;
$this->class_name = $class_name;
}
/**
* @return Presentation
*/
public function getPresentation(){
return $this->presentation;
}
/**
* @return int
*/
public function getMaterialId(){
return $this->material_id;
}
/**
* @return string
*/
public function getClassName(){
return $this->class_name;
}
}

View File

@ -0,0 +1,46 @@
<?php namespace App\Events;
/**
* Copyright 2016 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Illuminate\Queue\SerializesModels;
use models\summit\PresentationMaterial;
/**
* Class PresentationMaterialUpdated
* @package App\Events
*/
class PresentationMaterialUpdated extends Event
{
use SerializesModels;
/**
* @var PresentationMaterial
*/
private $material;
/**
* PresentationMaterialUpdated constructor.
* @param PresentationMaterial $material
*/
public function __construct(PresentationMaterial $material)
{
$this->material = $material;
}
/**
* @return PresentationMaterial
*/
public function getMaterial(){
return $this->material;
}
}

View File

@ -40,7 +40,6 @@ class EventServiceProvider extends ServiceProvider
{
parent::boot($events);
Event::listen(\App\Events\MyScheduleAdd::class, function($event)
{
if(!$event instanceof MyScheduleAdd) return;
@ -104,32 +103,6 @@ class EventServiceProvider extends ServiceProvider
});
Event::listen(\App\Events\PresentationMaterialCreated::class, function($event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getMaterial()->getClassName());
$entity_event->setEntityId($event->getMaterial()->getId());
$entity_event->setType('INSERT');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit());
$em = Registry::getManager('ss');
$em->persist($entity_event);
$em->flush();
});
Event::listen(\App\Events\SummitEventUpdated::class, function($event)
{
if(!$event instanceof SummitEventUpdated) return;
@ -194,5 +167,86 @@ class EventServiceProvider extends ServiceProvider
$em->persist($entity_event);
$em->flush();
});
Event::listen(\App\Events\PresentationMaterialCreated::class, function($event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getMaterial()->getClassName());
$entity_event->setEntityId($event->getMaterial()->getId());
$entity_event->setType('INSERT');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit());
$entity_event->setMetadata(json_encode([ 'presentation_id' => intval($event->getMaterial()->getPresentation()->getId())]));
$em = Registry::getManager('ss');
$em->persist($entity_event);
$em->flush();
});
Event::listen(\App\Events\PresentationMaterialUpdated::class, function($event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getMaterial()->getClassName());
$entity_event->setEntityId($event->getMaterial()->getId());
$entity_event->setType('UPDATE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit());
$entity_event->setMetadata(json_encode([ 'presentation_id' => intval($event->getMaterial()->getPresentation()->getId())]));
$em = Registry::getManager('ss');
$em->persist($entity_event);
$em->flush();
});
Event::listen(\App\Events\PresentationMaterialDeleted::class, function($event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getClassName());
$entity_event->setEntityId($event->getMaterialId());
$entity_event->setType('DELETE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getPresentation()->getSummit());
$em = Registry::getManager('ss');
$em->persist($entity_event);
$em->flush();
});
}
}

View File

@ -12,6 +12,9 @@
* limitations under the License.
**/
use App\Events\PresentationMaterialDeleted;
use App\Events\PresentationMaterialUpdated;
use Illuminate\Support\Facades\Event;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use models\summit\factories\IPresentationVideoFactory;
@ -90,7 +93,7 @@ final class PresentationService implements IPresentationService
*/
public function updateVideo($presentation_id, $video_id, array $video_data)
{
return $this->tx_service->transaction(function() use($presentation_id, $video_id, $video_data){
$video = $this->tx_service->transaction(function() use($presentation_id, $video_id, $video_data){
$presentation = $this->presentation_repository->getById($presentation_id);
@ -120,6 +123,8 @@ final class PresentationService implements IPresentationService
return $video;
});
Event::fire(new PresentationMaterialUpdated($video));
return $video;
}
/**
@ -149,6 +154,8 @@ final class PresentationService implements IPresentationService
$presentation->removeVideo($video);
Event::fire(new PresentationMaterialDeleted($presentation, $video_id, 'PresentationVideo'));
});
}
}

View File

@ -193,6 +193,7 @@ final class SummitService implements ISummitService
if (is_null($event)) throw new EntityNotFoundException('event not found on summit!');
$attendee->removeFromSchedule($event);
});
Event::fire(new MyScheduleRemove($attendee, $event_id));
}
@ -271,7 +272,9 @@ final class SummitService implements ISummitService
);
foreach ($events as $e) {
if ($ctx->getListSize() === $limit) break;
$last_event_id = $e->getId();
$last_event_date = $e->getCreated();
try {

View File

@ -1787,12 +1787,12 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
$this->assertTrue(!is_null($events));
}
public function testAddPresentationVideo()
public function testAddPresentationVideo($summit_id = 7, $presentation_id = 15404)
{
$params = array
(
'id' => 7,
'presentation_id' => 15404
'id' => $summit_id,
'presentation_id' => $presentation_id
);
$headers = array
@ -1821,18 +1821,20 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
json_encode($video_data)
);
$content = $response->getContent();
$video_id = $response->getContent();
$this->assertResponseStatus(201);
return intval($video_id);
}
public function testUpdatePresentationVideo()
{
$video_id = $this->testAddPresentationVideo(7, 15404);
$params = array
(
'id' => 7,
'presentation_id' => 15404,
'video_id' => 32801
'video_id' => $video_id
);
$headers = array
@ -1866,11 +1868,13 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
public function testDeletePresentationVideo()
{
$video_id = $this->testAddPresentationVideo(7, 15404);
$params = array
(
'id' => 7,
'presentation_id' => 15404,
'video_id' => 32800
'video_id' => $video_id
);
$headers = array