diff --git a/.gitignore b/.gitignore index dc36760..513c5e2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ app/bootstrap* # Symfony directories +.composer/ vendor/* */logs/* */cache/* @@ -9,6 +10,7 @@ web/uploads/* !web/uploads/tickets/.gitkeep web/bundles/* bin/* +dbdata/* # Configuration files app/config/parameters.ini diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8057db1 --- /dev/null +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 8e55db5..257329d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c9f89b5 --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/src/Event/EventBundle/Controller/Backend/DashboardController.php b/src/Event/EventBundle/Controller/Backend/DashboardController.php index af10026..25fce37 100644 --- a/src/Event/EventBundle/Controller/Backend/DashboardController.php +++ b/src/Event/EventBundle/Controller/Backend/DashboardController.php @@ -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', []); } @@ -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 */ diff --git a/src/Event/EventBundle/EventListener/InitListener.php b/src/Event/EventBundle/EventListener/InitListener.php index f823590..8456a97 100644 --- a/src/Event/EventBundle/EventListener/InitListener.php +++ b/src/Event/EventBundle/EventListener/InitListener.php @@ -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() @@ -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; + } } diff --git a/src/Event/EventBundle/Resources/config/services.yml b/src/Event/EventBundle/Resources/config/services.yml index 68b5960..c57b86a 100644 --- a/src/Event/EventBundle/Resources/config/services.yml +++ b/src/Event/EventBundle/Resources/config/services.yml @@ -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 }