Skip to content

Commit

Permalink
Merge pull request #96 from pilot/docker
Browse files Browse the repository at this point in the history
Eventator support fast run with Docker
  • Loading branch information
pilot authored Aug 22, 2019
2 parents 768f1e9 + 77d7d82 commit 9ce7169
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 85 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
app/bootstrap*

# Symfony directories
.composer/
vendor/*
*/logs/*
*/cache/*
web/uploads/*
!web/uploads/tickets/.gitkeep
web/bundles/*
bin/*
dbdata/*

# Configuration files
app/config/parameters.ini
Expand Down
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM phpmentors/symfony-app:php70

# default document root is /var/app/web folder
COPY ./ /var/app

# example how to install app in the container
# RUN apt-get update && \
# apt-get install -y curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN apt-get update && apt-get install -y \
unzip \
libssl-dev \
libzip-dev \
zlib1g-dev \
libgs-dev \
cron
RUN apt-get install -y libmagickwand-dev --no-install-recommends

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version

VOLUME ["/var/app"]

WORKDIR /var/app

EXPOSE 80
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ events managing with easiest ticketing systems
* access to the admin panel by `/event/admin`
* with `admin/admin`

## install
## install with Docker

* download or clone repo `git clone https://github.com/pilot/eventator my_event/`
* create `app/cache` and `app/logs` directories with 777 permissions
* get composer `curl -S https://getcomposer.org/installer | php`
* install dependencies `php composer.phar install`
* create database `php app/console doctrine:database:create`
* create schema `php app/console doctrine:schema:create`
* install assets `php app/console assets:install`
* open browser and follow to the `http://your-events.loc/event/admin` for initial setup
* `$ docker-compose up -d --build`
* `$ docker exec -it eve composer install`
* create schema `$ docker exec -it eve php app/console doctrine:schema:create`
* install assets `$ docker exec -it eve php app/console assets:install`
* open browser and follow to the `http://localhost/event/admin` for initial setup
* login and password to the backend `admin` / `admin`
* bingo!

## online payments with liqpay.com
## cache clear

* `$ docker exec -it eve php app/console ca:cl -e prod`

## (optional) online payments with liqpay.com

* register liqpay.com account
* obtain your private and public keys
Expand Down
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'
services:
mysql:
image: mysql:5.7
restart: always
container_name: eve_mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: eve
MYSQL_USER: root
MYSQL_PASSWORD: root
ports:
- 3307:3306
volumes:
- ./dbdata:/var/lib/mysql

php:
build: .
restart: always
container_name: eve
links:
- mysql
ports:
- 80:80
volumes:
- .:/var/app
63 changes: 1 addition & 62 deletions src/Event/EventBundle/Controller/Backend/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,17 @@

use Symfony\Component\HttpFoundation\Request;
use Event\EventBundle\Controller\Controller;
use Event\EventBundle\Entity\Event;
use Event\EventBundle\Entity\Translation\EventTranslation;
use Event\EventBundle\Entity\Speaker;
use Event\EventBundle\Entity\Translation\SpeakerTranslation;

class DashboardController extends Controller
{
public function indexAction()
{
// @todo: create installer for initial setup
if ('test' != $this->container->getParameter('kernel.environment')) {
$this->initEvent();
}

return $this->render('EventEventBundle:Backend/Dashboard:index.html.twig', []);
}

public function settingAction(Request $request)
{
// @todo: add settgins management
// @todo: add settings management

return $this->render('EventEventBundle:Backend/Dashboard:setting.html.twig', []);
}
Expand All @@ -42,58 +33,6 @@ public function localeTabsAction($translations)
]);
}

/**
* Event initialization
*
* This is a workaround to stay bundle independent from fixtures, or cli init
* Feel free to remove this call after init or switch to the fixtures
*/
protected function initEvent()
{
$locales = $this->container->getParameter('event.locales');
$event = $this->getEvent();
$now = new \DateTime();

if (!$event) {
$event = new Event();
$event
->setTitle('My Event')
->setDescription('My another awesome event!')
->setStartDate($now)
->setEndDate($now->modify('+1 day'))
->setVenue('Burj Khalifa Tower')
->setEmail('eventator@email.com')
;

$speaker = new Speaker();
$speaker
->setFirstName('Phill')
->setLastName('Pilow')
->setCompany('Reseach Supplier')
;

if ($locales) {
foreach ($locales as $locale => $title) {
$eventTranslation = new EventTranslation();
$eventTranslation->setEvent($event);
$eventTranslation->setlocale($locale);

$this->getManager()->persist($eventTranslation);

$speakerTranslation = new SpeakerTranslation();
$speakerTranslation->setSpeaker($speaker);
$speakerTranslation->setlocale($locale);

$this->getManager()->persist($speakerTranslation);
}
}

$this->getManager()->persist($event);
$this->getManager()->persist($speaker);
$this->getManager()->flush();
}
}

/**
* Handle that new locales was added to the configuration, to init it
*/
Expand Down
97 changes: 83 additions & 14 deletions src/Event/EventBundle/EventListener/InitListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,44 @@
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Doctrine\Common\Persistence\ObjectManager;
use Event\EventBundle\Entity\Repository\EventRepository;
use Event\EventBundle\Manager\EventManager;
use Event\EventBundle\Entity\Event;
use Event\EventBundle\Entity\Translation\EventTranslation;
use Event\EventBundle\Entity\Speaker;
use Event\EventBundle\Entity\Translation\SpeakerTranslation;

class InitListener implements EventSubscriberInterface
{
private $eventRepository;
private $eventManager;
private $entityManager;

public function __construct(EventRepository $eventRepository, EventManager $eventManager)
public function __construct(EventRepository $eventRepository, EventManager $eventManager, ObjectManager $entityManager)
{
$this->eventRepository = $eventRepository;
$this->eventManager = $eventManager;
$this->entityManager = $entityManager;
}

public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(GetResponseEvent $onEvent)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
if (HttpKernelInterface::MASTER_REQUEST !== $onEvent->getRequestType()) {
return;
}

$request = $event->getRequest();

if ($request->cookies->has('user_locale')) {
$locale = $request->cookies->get('user_locale');
$request->setLocale($locale);
}
$host = $request->getHttpHost();
$event = $this->eventRepository->findOneBy(['host' => 'http://'.$host]);
$event = $this->checkEvent($onEvent);

if (!$event) {
throw new NotFoundHttpException(sprintf('No event for host "%s" found', $host));
// Create Event for requested host name
$event = $this->initEvent();
}

$this->eventManager->setCurrentEvent($event);

// set event for frontend page
$request->attributes->set('event', $event);
// set event for homepage page template
$onEvent->getRequest()->attributes->set('event', $event);
}

public static function getSubscribedEvents()
Expand All @@ -52,4 +53,72 @@ public static function getSubscribedEvents()
KernelEvents::REQUEST => array(array('onKernelRequest', 32)),
);
}

protected function checkEvent(GetResponseEvent $onEvent)
{
$request = $onEvent->getRequest();

if ($request->cookies->has('user_locale')) {
$locale = $request->cookies->get('user_locale');
$request->setLocale($locale);
}

return $this
->eventRepository
->findOneBy(['host' => $request->getHttpHost()]);
}

/**
* Event initialization
*
* This is a workaround to stay bundle independent from fixtures, or cli init
* Feel free to remove this call after init or switch to the fixtures
*/
protected function initEvent()
{
// en_EN locale is default!
// @todo replace it with event_event.locales from config.yml
$locales = ['ru_RU' => 'ru', 'de_DE' => 'de'];
$now = new \DateTime();

$event = new Event();
$event
->setHost('localhost')
->setTitle('My Event')
->setDescription('My another awesome event!')
->setStartDate($now)
->setEndDate($now->modify('+1 day'))
->setVenue('Burj Khalifa Tower')
->setEmail('hello@lazy-ants.com')
;

$speaker = new Speaker();
$speaker
->setFirstName('Phill')
->setLastName('Pilow')
->setCompany('Reseach Supplier')
;

if ($locales) {
foreach ($locales as $locale => $title) {
$eventTranslation = new EventTranslation();
$eventTranslation->setEvent($event);
$eventTranslation->setlocale($locale);

$this->entityManager->persist($eventTranslation);

$speakerTranslation = new SpeakerTranslation();
$speakerTranslation->setSpeaker($speaker);
$speakerTranslation->setlocale($locale);

$this->entityManager->persist($speakerTranslation);
}
}

$this->entityManager->persist($event);
$this->entityManager->persist($speaker);
$this->entityManager->flush();

return $event;
}
}
1 change: 1 addition & 0 deletions src/Event/EventBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
arguments:
- '@eventator.event_repository'
- '@eventator.event_manager'
- '@doctrine.orm.default_entity_manager'
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

Expand Down

0 comments on commit 9ce7169

Please sign in to comment.