Summit Event tags duplication
formerly, code was not checking the existence of tags before creating them, on Event update/creation process. Change-Id: I0d20c20e5d49d77de61286e22f132a4bb6b57722
This commit is contained in:
parent
f7a6f04891
commit
8bf6b9bbf3
28
app/Models/Foundation/Main/Repositories/ITagRepository.php
Normal file
28
app/Models/Foundation/Main/Repositories/ITagRepository.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php namespace Models\foundation\main\repositories;
|
||||
/**
|
||||
* 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 models\utils\IBaseRepository;
|
||||
|
||||
/**
|
||||
* Interface ITagRepository
|
||||
* @package Models\foundation\main\repositories
|
||||
*/
|
||||
interface ITagRepository extends IBaseRepository
|
||||
{
|
||||
/**
|
||||
* @param string $tag
|
||||
* @return Tag
|
||||
*/
|
||||
public function getByTag($tag);
|
||||
}
|
@ -16,7 +16,7 @@ use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="repositories\main\DoctrineTagRepository")
|
||||
* @ORM\Table(name="Tag")
|
||||
* Class Tag
|
||||
* @package models\main
|
||||
|
@ -587,11 +587,11 @@ class SummitEvent extends SilverstripeBaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
* @param Tag $tag
|
||||
*/
|
||||
public function addTag($tag)
|
||||
public function addTag(Tag $tag)
|
||||
{
|
||||
$this->tags->add(new Tag($tag));
|
||||
$this->tags->add($tag);
|
||||
}
|
||||
|
||||
public function clearTags()
|
||||
|
43
app/Repositories/Main/Doctrine/DoctrineTagRepository.php
Normal file
43
app/Repositories/Main/Doctrine/DoctrineTagRepository.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php namespace repositories\main;
|
||||
/**
|
||||
* 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 Models\foundation\main\repositories\ITagRepository;
|
||||
use models\main\Tag;
|
||||
use repositories\SilverStripeDoctrineRepository;
|
||||
|
||||
/**
|
||||
* Class DoctrineTagRepository
|
||||
* @package repositories\main
|
||||
*/
|
||||
final class DoctrineTagRepository extends SilverStripeDoctrineRepository implements ITagRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
* @return Tag
|
||||
*/
|
||||
public function getByTag($tag)
|
||||
{
|
||||
try {
|
||||
return $this->getEntityManager()->createQueryBuilder()
|
||||
->select("t")
|
||||
->from(\models\main\Tag::class, "t")
|
||||
->where('UPPER(TRIM(t.tag)) = UPPER(TRIM(:tag))')
|
||||
->setParameter('tag', $tag)
|
||||
->getQuery()->getOneOrNullResult();
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -104,5 +104,11 @@ class RepositoriesProvider extends ServiceProvider
|
||||
function(){
|
||||
return EntityManager::getRepository(\models\summit\SummitPushNotification::class);
|
||||
});
|
||||
|
||||
App::singleton(
|
||||
'Models\foundation\main\repositories\ITagRepository',
|
||||
function(){
|
||||
return EntityManager::getRepository(\models\main\Tag::class);
|
||||
});
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ use repositories\SilverStripeDoctrineRepository;
|
||||
* Class DoctrineMemberRepository
|
||||
* @package repositories\summit
|
||||
*/
|
||||
final class DoctrineMemberRepository extends SilverStripeDoctrineRepository implements IMemberRepository
|
||||
final class DoctrineMemberRepository extends SilverStripeDoctrineRepository implements IMemberRepository
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -20,8 +20,10 @@ use Illuminate\Support\Facades\Event;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use Models\foundation\main\repositories\IMemberRepository;
|
||||
use Models\foundation\main\repositories\ITagRepository;
|
||||
use Models\foundation\summit\EntityEvents\EntityEventTypeFactory;
|
||||
use Models\foundation\summit\EntityEvents\SummitEntityEventProcessContext;
|
||||
use models\main\Tag;
|
||||
use models\summit\ConfirmationExternalOrderRequest;
|
||||
use models\summit\ISpeakerRepository;
|
||||
use models\summit\ISummitAttendeeRepository;
|
||||
@ -91,6 +93,11 @@ final class SummitService implements ISummitService
|
||||
*/
|
||||
private $attendee_repository;
|
||||
|
||||
/**
|
||||
* @var ITagRepository
|
||||
*/
|
||||
private $tag_repository;
|
||||
|
||||
public function __construct
|
||||
(
|
||||
ISummitEventRepository $event_repository,
|
||||
@ -99,6 +106,7 @@ final class SummitService implements ISummitService
|
||||
ISummitAttendeeTicketRepository $ticket_repository,
|
||||
ISummitAttendeeRepository $attendee_repository,
|
||||
IMemberRepository $member_repository,
|
||||
ITagRepository $tag_repository,
|
||||
IEventbriteAPI $eventbrite_api,
|
||||
ITransactionService $tx_service
|
||||
)
|
||||
@ -109,6 +117,7 @@ final class SummitService implements ISummitService
|
||||
$this->ticket_repository = $ticket_repository;
|
||||
$this->member_repository = $member_repository;
|
||||
$this->attendee_repository = $attendee_repository;
|
||||
$this->tag_repository = $tag_repository;
|
||||
$this->eventbrite_api = $eventbrite_api;
|
||||
$this->tx_service = $tx_service;
|
||||
}
|
||||
@ -415,7 +424,9 @@ final class SummitService implements ISummitService
|
||||
|
||||
if (isset($data['tags']) && count($data['tags']) > 0) {
|
||||
$event->clearTags();
|
||||
foreach ($data['tags'] as $tag) {
|
||||
foreach ($data['tags'] as $str_tag) {
|
||||
$tag = $this->tag_repository->getByTag($str_tag);
|
||||
if($tag == null) $tag = new Tag($str_tag);
|
||||
$event->addTag($tag);
|
||||
}
|
||||
}
|
||||
|
@ -949,24 +949,27 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
|
||||
public function testUpdateEvent()
|
||||
{
|
||||
$event = $this->testPostEvent();
|
||||
/*$event = $this->testPostEvent();
|
||||
unset($event->summit_types);
|
||||
unset($event->tags);
|
||||
unset($event->tags);*/
|
||||
$params = array
|
||||
(
|
||||
'id' => 6,
|
||||
'event_id' => $event->getId(),
|
||||
'event_id' => 15303,
|
||||
);
|
||||
|
||||
$data = array
|
||||
(
|
||||
'tags' => ['keystone'],
|
||||
);
|
||||
|
||||
|
||||
$headers = array
|
||||
(
|
||||
"HTTP_Authorization" => " Bearer " .$this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
);
|
||||
|
||||
$event->title .= ' update';
|
||||
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"PUT",
|
||||
@ -976,13 +979,13 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
array(),
|
||||
array(),
|
||||
$headers,
|
||||
json_encode($event)
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$this->assertResponseStatus(200);
|
||||
$content = $response->getContent();
|
||||
$event = json_decode($content);
|
||||
$this->assertTrue($event->getId() > 0);
|
||||
$this->assertTrue($event->id > 0);
|
||||
return $event;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user