From 11d89c8a10ced4921824211009d28895a789c1b7 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sat, 23 Jun 2018 17:57:10 +0300 Subject: [PATCH] Separated Entity Managers for magneticod SQLite database and app's PostgreSQL database implemented. Some refactoring has been made. --- config/packages/doctrine.yaml | 43 +++++++++++++------ src/Api/V1/Controller/TorrentController.php | 4 +- src/Controller/MainController.php | 2 +- src/Controller/TorrentController.php | 4 +- src/{ => Magnetico}/Entity/File.php | 4 +- src/{ => Magnetico}/Entity/Torrent.php | 6 +-- .../Repository/TorrentRepository.php | 10 +++-- templates/torrent_list.html.twig | 2 +- templates/torrent_show.html.twig | 4 +- 9 files changed, 51 insertions(+), 28 deletions(-) rename src/{ => Magnetico}/Entity/File.php (91%) rename src/{ => Magnetico}/Entity/Torrent.php (91%) rename src/{ => Magnetico}/Repository/TorrentRepository.php (79%) diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 39536b6..ff0abee 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -7,17 +7,36 @@ parameters: doctrine: dbal: - # configure these for your database server - driver: 'pdo_sqlite' - url: '%env(resolve:DATABASE_URL)%' + default_connection: default + connections: + default: + driver: 'pdo_pgsql' + url: '%env(resolve:APP_DATABASE_URL)%' + magneticod: + driver: 'pdo_sqlite' + url: '%env(resolve:MAGNETICOD_DATABASE_URL)%' orm: auto_generate_proxy_classes: '%kernel.debug%' - naming_strategy: doctrine.orm.naming_strategy.underscore - auto_mapping: true - mappings: - App: - is_bundle: false - type: annotation - dir: '%kernel.project_dir%/src/Entity' - prefix: 'App\Entity' - alias: App + default_entity_manager: default + entity_managers: + default: + connection: default + naming_strategy: doctrine.orm.naming_strategy.underscore + auto_mapping: true + mappings: + App: + is_bundle: false + type: annotation + dir: '%kernel.project_dir%/src/Entity' + prefix: 'App\Entity' + alias: App + magneticod: + connection: magneticod + mappings: + Magnetico: + is_bundle: false + type: annotation + dir: '%kernel.project_dir%/src/Magnetico/Entity' + prefix: 'App\Magnetico' + alias: Magnetico + diff --git a/src/Api/V1/Controller/TorrentController.php b/src/Api/V1/Controller/TorrentController.php index a255c98..868f690 100644 --- a/src/Api/V1/Controller/TorrentController.php +++ b/src/Api/V1/Controller/TorrentController.php @@ -4,8 +4,8 @@ namespace App\Api\V1\Controller; use App\Api\V1\DTO\ApiResponse; use App\Api\V1\DTO\ListPage; -use App\Entity\Torrent; -use App\Repository\TorrentRepository; +use App\Magnetico\Entity\Torrent; +use App\Magnetico\Repository\TorrentRepository; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Pagerfanta; use Symfony\Bundle\FrameworkBundle\Controller\Controller; diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 1d22536..e2125a5 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -2,7 +2,7 @@ namespace App\Controller; -use App\Repository\TorrentRepository; +use App\Magnetico\Repository\TorrentRepository; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index 737fbed..a6974bd 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -2,8 +2,8 @@ namespace App\Controller; -use App\Entity\Torrent; -use App\Repository\TorrentRepository; +use App\Magnetico\Entity\Torrent; +use App\Magnetico\Repository\TorrentRepository; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Pagerfanta; use Symfony\Bundle\FrameworkBundle\Controller\Controller; diff --git a/src/Entity/File.php b/src/Magnetico/Entity/File.php similarity index 91% rename from src/Entity/File.php rename to src/Magnetico/Entity/File.php index 5d04e27..e27477b 100644 --- a/src/Entity/File.php +++ b/src/Magnetico/Entity/File.php @@ -1,6 +1,6 @@ select('COUNT(t.id)') ; - return (int) $qb->getQuery()->getSingleScalarResult(); + try { + return (int) $qb->getQuery()->getSingleScalarResult(); + } catch (\Exception $ex) { + return 0; + } } public function createFindLikeQueryBuilder(string $query): QueryBuilder diff --git a/templates/torrent_list.html.twig b/templates/torrent_list.html.twig index 6973ec5..5133f93 100644 --- a/templates/torrent_list.html.twig +++ b/templates/torrent_list.html.twig @@ -13,7 +13,7 @@ Discovered - {# @var torrent \App\Entity\Torrent #} + {# @var torrent \App\Magnetico\Entity\Torrent #} {% for torrent in torrents %} 🔗 diff --git a/templates/torrent_show.html.twig b/templates/torrent_show.html.twig index 1d8152d..3c49c47 100644 --- a/templates/torrent_show.html.twig +++ b/templates/torrent_show.html.twig @@ -1,7 +1,7 @@ {% extends 'base.html.twig' %} {% block content %} - {# @var torrent \App\Entity\Torrent #} + {# @var torrent \App\Magnetico\Entity\Torrent #} @@ -31,7 +31,7 @@ - {# @var file \App\Entity\File #} + {# @var file \App\Magnetico\Entity\File #} {% for file in torrent.files | sort %}
Name
{{ file.path }}