Skip to content

Commit ffbeb34

Browse files
authored
Optimalizace doctrine, refactoring settings (#796)
1 parent d183fa2 commit ffbeb34

File tree

168 files changed

+3450
-1788
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+3450
-1788
lines changed

.github/workflows/deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
CONFIG_SKAUTIS_TEST_MODE: true
2727
CONFIG_RECAPTCHA_SITE_KEY: 6LfQAuMZAAAAAL6xbQzujWRZDw-ivJmDF79ch5uQ
2828
CONFIG_RECAPTCHA_SECRET_KEY: ${{ secrets.SRS_CONFIG_RECAPTCHA_SECRET_KEY }}
29-
DEPLOY_DIRECTORY: "~"
29+
DEPLOY_DIRECTORY: '$HOME'
3030
DEPLOY_SSH_HOST: srs.skauting.cz
3131
DEPLOY_SSH_IP: 81.31.46.138
3232
DEPLOY_SSH_KEY: ${{ secrets.SRS_DEPLOY_SSH_KEY }}
@@ -89,7 +89,7 @@ jobs:
8989
CONFIG_SKAUTIS_TEST_MODE: true
9090
CONFIG_RECAPTCHA_SITE_KEY: 6LfQAuMZAAAAAL6xbQzujWRZDw-ivJmDF79ch5uQ
9191
CONFIG_RECAPTCHA_SECRET_KEY: ${{ secrets.TEST_SRS_CONFIG_RECAPTCHA_SECRET_KEY }}
92-
DEPLOY_DIRECTORY: "~"
92+
DEPLOY_DIRECTORY: '$HOME'
9393
DEPLOY_SSH_HOST: test-srs.skauting.cz
9494
DEPLOY_SSH_IP: 81.31.46.138
9595
DEPLOY_SSH_KEY: ${{ secrets.TEST_SRS_DEPLOY_SSH_KEY }}

app/ActionModule/Presenters/BankPresenter.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
namespace App\ActionModule\Presenters;
66

7-
use App\Model\Settings\Exceptions\SettingsException;
7+
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
8+
use App\Model\Settings\Queries\SettingDateValueQuery;
89
use App\Model\Settings\Settings;
910
use App\Services\BankService;
10-
use App\Services\ISettingsService;
11+
use App\Services\QueryBus;
1112
use Nette\Application\Responses\TextResponse;
1213
use Throwable;
1314

@@ -19,20 +20,20 @@
1920
class BankPresenter extends ActionBasePresenter
2021
{
2122
/** @inject */
22-
public BankService $bankService;
23+
public QueryBus $queryBus;
2324

2425
/** @inject */
25-
public ISettingsService $settingsService;
26+
public BankService $bankService;
2627

2728
/**
2829
* Zkontroluje splatnost přihlášek.
2930
*
30-
* @throws SettingsException
31+
* @throws SettingsItemNotFoundException
3132
* @throws Throwable
3233
*/
3334
public function actionCheck(): void
3435
{
35-
$from = $this->settingsService->getDateValue(Settings::BANK_DOWNLOAD_FROM);
36+
$from = $this->queryBus->handle(new SettingDateValueQuery(Settings::BANK_DOWNLOAD_FROM));
3637
$this->bankService->downloadTransactions($from);
3738

3839
$response = new TextResponse(null);

app/ActionModule/Presenters/MailingPresenter.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
use App\Model\Acl\Permission;
88
use App\Model\Acl\SrsResource;
9-
use App\Model\Settings\Exceptions\SettingsException;
9+
use App\Model\Settings\Commands\SetSettingStringValue;
10+
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
11+
use App\Model\Settings\Queries\SettingStringValueQuery;
1012
use App\Model\Settings\Settings;
11-
use App\Services\ISettingsService;
13+
use App\Services\CommandBus;
14+
use App\Services\QueryBus;
1215
use Nette\Application\AbortException;
1316
use Throwable;
1417

@@ -20,23 +23,26 @@
2023
class MailingPresenter extends ActionBasePresenter
2124
{
2225
/** @inject */
23-
public ISettingsService $settingsService;
26+
public CommandBus $commandBus;
27+
28+
/** @inject */
29+
public QueryBus $queryBus;
2430

2531
/**
2632
* Ověří e-mail semináře.
2733
*
28-
* @throws SettingsException
34+
* @throws SettingsItemNotFoundException
2935
* @throws AbortException
3036
* @throws Throwable
3137
*/
3238
public function actionVerify(string $code): void
3339
{
34-
if ($code === $this->settingsService->getValue(Settings::SEMINAR_EMAIL_VERIFICATION_CODE)) {
35-
$newEmail = $this->settingsService->getValue(Settings::SEMINAR_EMAIL_UNVERIFIED);
36-
$this->settingsService->setValue(Settings::SEMINAR_EMAIL, $newEmail);
40+
if ($code === $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_EMAIL_VERIFICATION_CODE))) {
41+
$newEmail = $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_EMAIL_UNVERIFIED));
42+
$this->commandBus->handle(new SetSettingStringValue(Settings::SEMINAR_EMAIL, $newEmail));
3743

38-
$this->settingsService->setValue(Settings::SEMINAR_EMAIL_UNVERIFIED, null);
39-
$this->settingsService->setValue(Settings::SEMINAR_EMAIL_VERIFICATION_CODE, null);
44+
$this->commandBus->handle(new SetSettingStringValue(Settings::SEMINAR_EMAIL_UNVERIFIED, null));
45+
$this->commandBus->handle(new SetSettingStringValue(Settings::SEMINAR_EMAIL_VERIFICATION_CODE, null));
4046

4147
$this->flashMessage('admin.configuration.mailing_email_verification_successful', 'success');
4248
} else {

app/ActionModule/Presenters/MaturityPresenter.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
use App\Model\Enums\ApplicationState;
1010
use App\Model\Mailing\Template;
1111
use App\Model\Mailing\TemplateVariable;
12-
use App\Model\Settings\Exceptions\SettingsException;
12+
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
13+
use App\Model\Settings\Queries\SettingIntValueQuery;
14+
use App\Model\Settings\Queries\SettingStringValueQuery;
1315
use App\Model\Settings\Settings;
1416
use App\Model\User\Repositories\UserRepository;
1517
use App\Services\ApplicationService;
1618
use App\Services\IMailService;
17-
use App\Services\ISettingsService;
19+
use App\Services\QueryBus;
1820
use App\Utils\Helpers;
1921
use DateTimeImmutable;
2022
use Doctrine\Common\Collections\ArrayCollection;
@@ -31,6 +33,9 @@
3133
*/
3234
class MaturityPresenter extends ActionBasePresenter
3335
{
36+
/** @inject */
37+
public QueryBus $queryBus;
38+
3439
/** @inject */
3540
public EntityManagerInterface $em;
3641

@@ -46,18 +51,15 @@ class MaturityPresenter extends ActionBasePresenter
4651
/** @inject */
4752
public ApplicationService $applicationService;
4853

49-
/** @inject */
50-
public ISettingsService $settingsService;
51-
5254
/**
5355
* Zruší přihlášky po splatnosti.
5456
*
55-
* @throws SettingsException
57+
* @throws SettingsItemNotFoundException
5658
* @throws Throwable
5759
*/
5860
public function actionCancelApplications(): void
5961
{
60-
$cancelRegistration = $this->settingsService->getIntValue(Settings::CANCEL_REGISTRATION_AFTER_MATURITY);
62+
$cancelRegistration = $this->queryBus->handle(new SettingIntValueQuery(Settings::CANCEL_REGISTRATION_AFTER_MATURITY));
6163
if ($cancelRegistration !== null) {
6264
$cancelRegistrationDate = (new DateTimeImmutable())->setTime(0, 0)->modify('-' . $cancelRegistration . ' days');
6365
} else {
@@ -109,13 +111,13 @@ public function actionCancelApplications(): void
109111
/**
110112
* Rozešle přípomínky splatnosti.
111113
*
112-
* @throws SettingsException
114+
* @throws SettingsItemNotFoundException
113115
* @throws Throwable
114116
* @throws MailingMailCreationException
115117
*/
116118
public function actionSendReminders(): void
117119
{
118-
$maturityReminder = $this->settingsService->getIntValue(Settings::MATURITY_REMINDER);
120+
$maturityReminder = $this->queryBus->handle(new SettingIntValueQuery(Settings::MATURITY_REMINDER));
119121
if ($maturityReminder !== null) {
120122
$maturityReminderDate = (new DateTimeImmutable())->setTime(0, 0)->modify('+' . $maturityReminder . ' days');
121123
} else {
@@ -128,7 +130,7 @@ public function actionSendReminders(): void
128130

129131
if ($maturityReminderDate == $maturityDate) {
130132
$this->mailService->sendMailFromTemplate(new ArrayCollection([$application->getUser()]), null, Template::MATURITY_REMINDER, [
131-
TemplateVariable::SEMINAR_NAME => $this->settingsService->getValue(Settings::SEMINAR_NAME),
133+
TemplateVariable::SEMINAR_NAME => $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_NAME)),
132134
TemplateVariable::APPLICATION_MATURITY => $maturityDate->format(Helpers::DATE_FORMAT),
133135
]);
134136
}

app/AdminModule/Components/UsersGridControl.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
use App\Model\Enums\ApplicationState;
2020
use App\Model\Enums\PaymentType;
2121
use App\Model\Enums\SkautIsEventType;
22-
use App\Model\Settings\Exceptions\SettingsException;
22+
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
23+
use App\Model\Settings\Queries\SettingIntValueQuery;
24+
use App\Model\Settings\Queries\SettingStringValueQuery;
2325
use App\Model\Settings\Settings;
2426
use App\Model\User\Repositories\UserRepository;
2527
use App\Model\User\User;
2628
use App\Services\AclService;
2729
use App\Services\ApplicationService;
2830
use App\Services\ExcelExportService;
29-
use App\Services\ISettingsService;
31+
use App\Services\QueryBus;
3032
use App\Services\SkautIsEventEducationService;
3133
use App\Services\SkautIsEventGeneralService;
3234
use App\Services\SubeventService;
@@ -60,14 +62,14 @@
6062
*/
6163
class UsersGridControl extends Control
6264
{
65+
private QueryBus $queryBus;
66+
6367
private ITranslator $translator;
6468

6569
private EntityManagerInterface $em;
6670

6771
private UserRepository $userRepository;
6872

69-
private ISettingsService $settingsService;
70-
7173
private CustomInputRepository $customInputRepository;
7274

7375
private RoleRepository $roleRepository;
@@ -91,10 +93,10 @@ class UsersGridControl extends Control
9193
private SubeventService $subeventService;
9294

9395
public function __construct(
96+
QueryBus $queryBus,
9497
ITranslator $translator,
9598
EntityManagerInterface $em,
9699
UserRepository $userRepository,
97-
ISettingsService $settingsService,
98100
CustomInputRepository $customInputRepository,
99101
RoleRepository $roleRepository,
100102
ExcelExportService $excelExportService,
@@ -106,10 +108,10 @@ public function __construct(
106108
SkautIsEventGeneralService $skautIsEventGeneralService,
107109
SubeventService $subeventService
108110
) {
111+
$this->queryBus = $queryBus;
109112
$this->translator = $translator;
110113
$this->em = $em;
111114
$this->userRepository = $userRepository;
112-
$this->settingsService = $settingsService;
113115
$this->customInputRepository = $customInputRepository;
114116
$this->roleRepository = $roleRepository;
115117
$this->excelExportService = $excelExportService;
@@ -136,7 +138,7 @@ public function render(): void
136138
/**
137139
* Vytvoří komponentu.
138140
*
139-
* @throws SettingsException
141+
* @throws SettingsItemNotFoundException
140142
* @throws Throwable
141143
* @throws DataGridColumnStatusException
142144
* @throws DataGridException
@@ -166,7 +168,7 @@ public function createComponentUsersGrid(string $name): DataGrid
166168
$grid->addGroupAction('admin.users.users_group_action_mark_paid_today', $this->preparePaymentMethodOptionsWithoutEmpty())
167169
->onSelect[] = [$this, 'groupMarkPaidToday'];
168170

169-
switch ($this->settingsService->getValue(Settings::SKAUTIS_EVENT_TYPE)) {
171+
switch ($this->queryBus->handle(new SettingStringValueQuery(Settings::SKAUTIS_EVENT_TYPE))) {
170172
case SkautIsEventType::GENERAL:
171173
$grid->addGroupAction('admin.users.users_group_action_insert_into_skaut_is')
172174
->onSelect[] = [$this, 'groupInsertIntoSkautIs'];
@@ -699,14 +701,14 @@ public function groupInsertIntoSkautIs(array $ids, bool $accept): void
699701

700702
$p = $this->getPresenter();
701703

702-
$eventId = $this->settingsService->getIntValue(Settings::SKAUTIS_EVENT_ID);
704+
$eventId = $this->queryBus->handle(new SettingIntValueQuery(Settings::SKAUTIS_EVENT_ID));
703705

704706
if ($eventId === null) {
705707
$p->flashMessage('admin.users.users_group_action_insert_into_skaut_is_error_not_connected', 'danger');
706708
$this->redirect('this');
707709
}
708710

709-
switch ($this->settingsService->getValue(Settings::SKAUTIS_EVENT_TYPE)) {
711+
switch ($this->queryBus->handle(new SettingStringValueQuery(Settings::SKAUTIS_EVENT_TYPE))) {
710712
case SkautIsEventType::GENERAL:
711713
$skautIsEventService = $this->skautIsEventGeneralService;
712714
break;

app/AdminModule/ConfigurationModule/Forms/ApplicationFormFactory.php

+19-11
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
namespace App\AdminModule\ConfigurationModule\Forms;
66

77
use App\AdminModule\Forms\BaseFormFactory;
8-
use App\Model\Settings\Exceptions\SettingsException;
8+
use App\Model\Settings\Commands\SetSettingDateValue;
9+
use App\Model\Settings\Commands\SetSettingStringValue;
10+
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
11+
use App\Model\Settings\Queries\SettingDateValueQuery;
12+
use App\Model\Settings\Queries\SettingStringValueQuery;
913
use App\Model\Settings\Settings;
10-
use App\Services\ISettingsService;
14+
use App\Services\CommandBus;
15+
use App\Services\QueryBus;
1116
use Nette;
1217
use Nette\Application\UI\Form;
1318
use Nextras\FormComponents\Controls\DateControl;
@@ -25,18 +30,21 @@ class ApplicationFormFactory
2530

2631
private BaseFormFactory $baseFormFactory;
2732

28-
private ISettingsService $settingsService;
33+
private CommandBus $commandBus;
2934

30-
public function __construct(BaseFormFactory $baseForm, ISettingsService $settingsService)
35+
private QueryBus $queryBus;
36+
37+
public function __construct(BaseFormFactory $baseForm, CommandBus $commandBus, QueryBus $queryBus)
3138
{
3239
$this->baseFormFactory = $baseForm;
33-
$this->settingsService = $settingsService;
40+
$this->commandBus = $commandBus;
41+
$this->queryBus = $queryBus;
3442
}
3543

3644
/**
3745
* Vytvoří formulář.
3846
*
39-
* @throws SettingsException
47+
* @throws SettingsItemNotFoundException
4048
* @throws Throwable
4149
*/
4250
public function create(): Form
@@ -53,8 +61,8 @@ public function create(): Form
5361
$form->addSubmit('submit', 'admin.common.save');
5462

5563
$form->setDefaults([
56-
'applicationAgreement' => $this->settingsService->getValue(Settings::APPLICATION_AGREEMENT),
57-
'editCustomInputsTo' => $this->settingsService->getDateValue(Settings::EDIT_CUSTOM_INPUTS_TO),
64+
'applicationAgreement' => $this->queryBus->handle(new SettingStringValueQuery(Settings::APPLICATION_AGREEMENT)),
65+
'editCustomInputsTo' => $this->queryBus->handle(new SettingDateValueQuery(Settings::EDIT_CUSTOM_INPUTS_TO)),
5866
]);
5967

6068
$form->onSuccess[] = [$this, 'processForm'];
@@ -65,12 +73,12 @@ public function create(): Form
6573
/**
6674
* Zpracuje formulář.
6775
*
68-
* @throws SettingsException
76+
* @throws SettingsItemNotFoundException
6977
* @throws Throwable
7078
*/
7179
public function processForm(Form $form, stdClass $values): void
7280
{
73-
$this->settingsService->setValue(Settings::APPLICATION_AGREEMENT, $values->applicationAgreement);
74-
$this->settingsService->setDateValue(Settings::EDIT_CUSTOM_INPUTS_TO, $values->editCustomInputsTo);
81+
$this->commandBus->handle(new SetSettingStringValue(Settings::APPLICATION_AGREEMENT, $values->applicationAgreement));
82+
$this->commandBus->handle(new SetSettingDateValue(Settings::EDIT_CUSTOM_INPUTS_TO, $values->editCustomInputsTo));
7583
}
7684
}

app/AdminModule/ConfigurationModule/Forms/BankFormFactory.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
namespace App\AdminModule\ConfigurationModule\Forms;
66

77
use App\AdminModule\Forms\BaseFormFactory;
8-
use App\Model\Settings\Exceptions\SettingsException;
8+
use App\Model\Settings\Commands\SetSettingStringValue;
9+
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
910
use App\Model\Settings\Settings;
1011
use App\Services\BankService;
11-
use App\Services\ISettingsService;
12+
use App\Services\CommandBus;
1213
use DateTimeImmutable;
1314
use FioApi\Exceptions\InternalErrorException;
1415
use Nette;
@@ -34,17 +35,14 @@ class BankFormFactory
3435

3536
private BaseFormFactory $baseFormFactory;
3637

37-
private ISettingsService $settingsService;
38+
private CommandBus $commandBus;
3839

3940
private BankService $bankService;
4041

41-
public function __construct(
42-
BaseFormFactory $baseForm,
43-
ISettingsService $settingsService,
44-
BankService $bankService
45-
) {
42+
public function __construct(BaseFormFactory $baseForm, CommandBus $commandBus, BankService $bankService)
43+
{
4644
$this->baseFormFactory = $baseForm;
47-
$this->settingsService = $settingsService;
45+
$this->commandBus = $commandBus;
4846
$this->bankService = $bankService;
4947
}
5048

@@ -83,7 +81,7 @@ public function create(): Form
8381
/**
8482
* Zpracuje formulář.
8583
*
86-
* @throws SettingsException
84+
* @throws SettingsItemNotFoundException
8785
* @throws Throwable
8886
*/
8987
public function processForm(Form $form, stdClass $values): void
@@ -93,7 +91,7 @@ public function processForm(Form $form, stdClass $values): void
9391

9492
try {
9593
$this->bankService->downloadTransactions($from, $token);
96-
$this->settingsService->setValue(Settings::BANK_TOKEN, $token);
94+
$this->commandBus->handle(new SetSettingStringValue(Settings::BANK_TOKEN, $token));
9795
} catch (InternalErrorException $ex) {
9896
Debugger::log($ex, ILogger::WARNING);
9997
$bankTokenInput = $form['bankToken'];

0 commit comments

Comments
 (0)