Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ServiceEntityRepository #3395

Merged
merged 17 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/config/base_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ services:
public: true
arguments:
- "@fork.settings"
- "@ForkCMS\\Google\\TagManager\\DataLayer"
- "@ForkCMS\\Privacy\\ConsentDialog"
- '@ForkCMS\Google\TagManager\DataLayer'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

' or " ? Should we decide on one format? (the line above is inconsistent - "@fork.settings")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing that in the symfony 5 branch

- '@ForkCMS\Privacy\ConsentDialog'

ForkCMS\Privacy\ConsentDialog:
public: true
Expand Down
7 changes: 5 additions & 2 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ parameters:
fork.is_installed: true

services:
_defaults:
autowire: true
autoconfigure: true
public: true

templating:
class: Frontend\Core\Engine\TwigTemplate
public: true
arguments:
- "@twig"
- "@templating.name_parser"
- "@templating.locator"

translator:
class: Common\Language
public: true
arguments:
- "@translator.selector"

Expand Down
2 changes: 1 addition & 1 deletion app/config/console.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ services:
forkcms.console.thumbnails.generate:
class: Console\Thumbnails\GenerateThumbnailsCommand
arguments:
- "@ForkCMS\\Utility\\Thumbnails"
- '@ForkCMS\Utility\Thumbnails'
tags:
- { name: console.command }
16 changes: 6 additions & 10 deletions app/config/doctrine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ doctrine_orm_bridge:
connection: default

services:
fork.entity.create_schema:
class: Common\Doctrine\Entity\CreateSchema
_defaults:
autowire: true
autoconfigure: true
public: true
arguments:
- "@doctrine.orm.entity_manager"

fork.repository.meta:
class: Common\Doctrine\Repository\MetaRepository
public: true
factory: ["@doctrine.orm.entity_manager", getRepository]
arguments:
- Common\Doctrine\Entity\Meta
Common\Doctrine\Entity\CreateSchema:

Common\Doctrine\Repository\MetaRepository:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we define an alias so modules can still use 'fork.repository.meta'? Or just break forward with Fork v6?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do a break here.
It is way cleaner to use these type of service name.
Unless we make these private and where needed things like fork.repository.meta public.

29 changes: 12 additions & 17 deletions app/config/form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,35 @@ parameters:
block-editor: 'Block Editor'

services:
Common\BlockEditor\Blocks\:
_defaults:
autowire: true
autoconfigure: true
public: true

Common\BlockEditor\Blocks\:
resource: '../../src/Common/BlockEditor/Blocks'
tags: ['fork.block_editor.block']

fork.datepicker.form:
class: Common\Form\DatePickerType
arguments:
- "@service_container"
Common\Form\DatePickerType:
tags:
- { name: form.type }
form.type.editor:
class: Backend\Form\Type\EditorType
autowire: true

Backend\Form\Type\EditorType:
tags:
- { name: form.type, alias: editor}
form.type.meta:
class: Backend\Form\Type\MetaType
arguments:
- "@fork.repository.meta"
- "@translator"

Backend\Form\Type\MetaType:
tags:
- { name: form.type, alias: meta}

Common\Form\ImageType:
arguments:
- "@validator"
tags:
- { name: form.type, alias: image}

Common\Form\FileType:
arguments:
- "@validator"
tags:
- { name: form.type, alias: file}

Common\Form\Extension\DateTypeExtension:
tags:
- { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\DateType }
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ services:
- "80:80"
- "443:443"
depends_on:
- db
- db6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP? 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c7be020 nope, did this on purpose.
We can change it when merging in master but this makes switching between branches during development way easier

env_file: ./var/docker/.env
volumes:
- .:/var/www/html:cached
- ./src/Frontend/Files:/var/www/html/src/Frontend/Files:cached
- fork-cms-var:/var/www/html/var
- fork-cms6-var:/var/www/html/var

db:
db6:
image: "mysql:5.7"
restart: always
ports:
Expand All @@ -32,10 +32,10 @@ services:
# Uncomment the next line if you want to keep mysql in a data container
# - db-data:/var/lib/mysql:rw
# By default, use a bind-mounted host directory instead. It's harder to accidentally lose all your db data!
- ./var/docker/db/data:/var/lib/mysql:rw
- ./var/docker/db/data6:/var/lib/mysql:rw
- ./tests/data/test_db.sql:/test_db.sql:ro
- ./var/docker/db/scripts:/docker-entrypoint-initdb.d:ro

volumes:
fork-cms-var: {}
db-data: {}
fork-cms6-var: {}
db6-data: {}
3 changes: 2 additions & 1 deletion src/Backend/Core/Ajax/GenerateUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Backend\Core\Engine\Base\AjaxAction as BackendBaseAJAXAction;
use Backend\Core\Language\Locale;
use Common\Doctrine\Repository\MetaRepository;
use Symfony\Component\HttpFoundation\Response;

/**
Expand All @@ -26,7 +27,7 @@ public function execute(): void
$parameters = @unserialize($parameters, ['allowed_classes' => [Locale::class]]);

// fetch generated meta url
$url = urldecode($this->get('fork.repository.meta')->generateUrl($url, $className, $methodName, $parameters));
$url = urldecode($this->get(MetaRepository::class)->generateUrl($url, $className, $methodName, $parameters));

// output
$this->output(Response::HTTP_OK, $url);
Expand Down
3 changes: 2 additions & 1 deletion src/Backend/Core/Engine/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Backend\Core\Engine;

use Common\Doctrine\Entity\Meta as MetaEntity;
use Common\Doctrine\Repository\MetaRepository;
use Common\Uri as CommonUri;
use Backend\Core\Engine\Model as BackendModel;
use Backend\Core\Language\Language as BackendLanguage;
Expand Down Expand Up @@ -118,7 +119,7 @@ public function __construct(
*/
public function generateUrl(string $url): string
{
return Model::get('fork.repository.meta')->generateUrl(
return Model::get(MetaRepository::class)->generateUrl(
$url,
$this->callback['class'],
$this->callback['method'],
Expand Down
3 changes: 2 additions & 1 deletion src/Backend/Core/Installer/CoreInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Backend\Core\Engine\Model;
use Backend\Modules\Pages\Domain\ModuleExtra\ModuleExtra;
use Common\Doctrine\Entity\CreateSchema;

/**
* Installer for the core
Expand Down Expand Up @@ -211,7 +212,7 @@ private function configureDefaultSettings(): void

private function configureEntities(): void
{
Model::get('fork.entity.create_schema')->forEntityClasses(
Model::get(CreateSchema::class)->forEntityClasses(
[
ModuleExtra::class,
]
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/Core/Installer/ModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ protected function insertPage(array $revision, array $meta = null, array ...$blo
$revision = $this->completePageRevisionRecord($revision, (array) $meta);

/** @var MetaRepository $metaRepository */
$metaRepository = BackendModel::get('fork.repository.meta');
$metaRepository = BackendModel::get(MetaRepository::class);
/** @var Meta $meta */
$meta = $metaRepository->find($revision['meta_id']);

Expand Down
16 changes: 14 additions & 2 deletions src/Backend/Modules/Blog/Domain/Category/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@

use Common\Core\Model;
use Common\Locale;
use Doctrine\ORM\EntityRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

class CategoryRepository extends EntityRepository
/**
* @method Category|null find($id, $lockMode = null, $lockVersion = null)
* @method Category|null findOneBy(array $criteria, array $orderBy = null)
* @method Category[] findAll()
* @method Category[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
final class CategoryRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Category::class);
}

public function findOneByUrl(string $url, Locale $locale): Category
{
return $this
Expand Down
16 changes: 14 additions & 2 deletions src/Backend/Modules/Blog/Domain/Comment/CommentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@

use Common\Locale;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

class CommentRepository extends EntityRepository
/**
* @method Comment|null find($id, $lockMode = null, $lockVersion = null)
* @method Comment|null findOneBy(array $criteria, array $orderBy = null)
* @method Comment[] findAll()
* @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
final class CommentRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Comment::class);
}

public function listCountPerStatus(Locale $locale): array
{
$builder = $this->createQueryBuilder('c')
Expand Down