Separated Entity Managers for magneticod SQLite database and app's PostgreSQL database implemented. Some refactoring has been made.

This commit is contained in:
Alexey Skobkin 2018-06-23 17:57:10 +03:00
parent 70f8fef9a2
commit 11d89c8a10
9 changed files with 51 additions and 28 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,6 +1,6 @@
<?php
namespace App\Entity;
namespace App\Magnetico\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
@ -24,7 +24,7 @@ class File
/**
* @var Torrent
*
* @ORM\ManyToOne(targetEntity="App\Entity\Torrent", inversedBy="files")
* @ORM\ManyToOne(targetEntity="App\Magnetico\Entity\Torrent", inversedBy="files")
* @ORM\JoinColumn(name="torrent_id")
*/
private $torrent;

View File

@ -1,6 +1,6 @@
<?php
namespace App\Entity;
namespace App\Magnetico\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
@ -11,7 +11,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
* @ORM\Index(name="discovered_on_index", columns={"discovered_on"}),
* @ORM\Index(name="info_hash_index", columns={"info_hash"})
* })
* @ORM\Entity(readOnly=true, repositoryClass="App\Repository\TorrentRepository")
* @ORM\Entity(readOnly=true, repositoryClass="App\Magnetico\Repository\TorrentRepository")
*/
class Torrent
{
@ -71,7 +71,7 @@ class Torrent
*
* @Serializer\Groups({"api_v1_show"})
*
* @ORM\OneToMany(targetEntity="App\Entity\File", fetch="EXTRA_LAZY", mappedBy="torrent")
* @ORM\OneToMany(targetEntity="App\Magnetico\Entity\File", fetch="EXTRA_LAZY", mappedBy="torrent")
*/
private $files;

View File

@ -1,6 +1,6 @@
<?php
namespace App\Repository;
namespace App\Magnetico\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
@ -10,7 +10,7 @@ class TorrentRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, \App\Entity\Torrent::class);
parent::__construct($registry, \App\Magnetico\Entity\Torrent::class);
}
public function getTorrentsTotalCount(): int
@ -19,7 +19,11 @@ class TorrentRepository extends ServiceEntityRepository
->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

View File

@ -13,7 +13,7 @@
<th scope="col">Discovered</th>
</tr>
</thead>
{# @var torrent \App\Entity\Torrent #}
{# @var torrent \App\Magnetico\Entity\Torrent #}
{% for torrent in torrents %}
<tr>
<td><a href="{{ magnet(torrent.name, torrent.infoHash) }}">&#128279;</a></td>

View File

@ -1,7 +1,7 @@
{% extends 'base.html.twig' %}
{% block content %}
{# @var torrent \App\Entity\Torrent #}
{# @var torrent \App\Magnetico\Entity\Torrent #}
<table class="table">
<tr>
<td>Name</td>
@ -31,7 +31,7 @@
</tr>
</thead>
<tbody>
{# @var file \App\Entity\File #}
{# @var file \App\Magnetico\Entity\File #}
{% for file in torrent.files | sort %}
<tr>
<td>{{ file.path }}</td>