Skip to content

Commit a0c731e

Browse files
committed
feat: refactoring
1 parent 8bf095e commit a0c731e

23 files changed

+381
-116
lines changed

components/ImportExportBundle/src/bundle/Controller/Admin/JobController.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use AlmaviaCX\Bundle\IbexaImportExport\Job\JobService;
1212
use AlmaviaCX\Bundle\IbexaImportExport\Workflow\WorkflowRegistry;
1313
use Doctrine\Common\Collections\Criteria;
14+
use Doctrine\Common\Collections\Selectable;
1415
use Exception;
1516
use Ibexa\Contracts\AdminUi\Controller\Controller;
1617
use Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface;
@@ -34,6 +35,9 @@
3435
use Symfony\Component\HttpFoundation\RequestStack;
3536
use Symfony\Component\HttpFoundation\Response;
3637

38+
/**
39+
* @SuppressWarnings("PHPMD.TooManyPublicMethods")
40+
*/
3741
class JobController extends Controller implements TranslationContainerInterface
3842
{
3943
public function __construct(
@@ -137,7 +141,7 @@ public function view(Request $request, Job $job, ?Execution $execution = null):
137141

138142
$page = $request->query->get('page') ?? 1;
139143
$pagerfanta = new Pagerfanta(
140-
new CollectionAdapter($executions->matching($criteria))
144+
new CollectionAdapter($executions instanceof Selectable ? $executions->matching($criteria) : $executions)
141145
);
142146

143147
$pagerfanta->setMaxPerPage(5);
@@ -204,7 +208,17 @@ public function run(Job $job, int $batchLimit = null, bool $reset = false): Redi
204208
]));
205209
}
206210

207-
public function pause(Execution $execution): Response
211+
public function runExecution(Execution $execution, int $batchLimit = null): RedirectResponse
212+
{
213+
$this->jobService->runExecution($execution, $batchLimit);
214+
215+
return new RedirectResponse($this->generateUrl('import_export.job.execution.view', [
216+
'id' => $execution->getJob()->getId(),
217+
'executionId' => $execution->getId(),
218+
]));
219+
}
220+
221+
public function pauseExecution(Execution $execution): Response
208222
{
209223
$this->jobService->pauseJobExecution($execution);
210224

@@ -214,7 +228,7 @@ public function pause(Execution $execution): Response
214228
]));
215229
}
216230

217-
public function cancel(Execution $execution): RedirectResponse
231+
public function cancelExecution(Execution $execution): RedirectResponse
218232
{
219233
$this->jobService->cancelJobExecution($execution);
220234

@@ -224,7 +238,7 @@ public function cancel(Execution $execution): RedirectResponse
224238
]));
225239
}
226240

227-
public function debug(Execution $execution, int $index): RedirectResponse
241+
public function debugExecution(Execution $execution, int $index): RedirectResponse
228242
{
229243
$this->jobService->debugJobExecution($execution, $index);
230244

components/ImportExportBundle/src/bundle/Resources/config/event_subscriber.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
services:
2-
AlmaviaCX\Bundle\IbexaImportExport\Event\Subscriber\RemoveWrittenFilesEventSubscriber:
3-
arguments:
4-
$fileHandler: '@AlmaviaCX\Bundle\IbexaImportExport\File\FileHandler'
5-
tags:
6-
- kernel.event_subscriber
7-
82
AlmaviaCX\Bundle\IbexaImportExport\Event\Subscriber\PostJobCreateFormSubmitEventSubscriber:
93
arguments:
104
$fileHandler: '@AlmaviaCX\Bundle\IbexaImportExport\File\FileHandler'

components/ImportExportBundle/src/bundle/Resources/config/routes.yaml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ import_export.job.run:
1919
path: /import-export/job/{id}/run
2020
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::run }
2121

22-
import_export.job.pause:
23-
path: /import-export/job/{id}/pause
24-
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::pause }
25-
26-
import_export.job.cancel:
27-
path: /import-export/job/{id}/cancel
28-
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::cancel }
29-
30-
import_export.job.debug:
31-
path: /import-export/job/{id}/debug/{index}
32-
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::debug }
33-
3422
import_export.job.run_w_limit:
3523
path: /import-export/job/{id}/run/{batchLimit}
3624
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::run }
@@ -50,8 +38,30 @@ import_export.job.reset_run_w_limit:
5038
reset: true|false
5139
batchLimit: '\d+'
5240

41+
import_export.execution.run:
42+
path: /import-export/execution/{id}/run
43+
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::runExecution }
44+
45+
import_export.execution.run_w_limit:
46+
path: /import-export/execution/{id}/run/{batchLimit}
47+
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::runExecution }
48+
requirements:
49+
batchLimit: '\d+'
50+
51+
import_export.execution.pause:
52+
path: /import-export/execution/{id}/pause
53+
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::pauseExecution }
54+
55+
import_export.execution.cancel:
56+
path: /import-export/execution/{id}/cancel
57+
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::cancelExecution }
58+
59+
import_export.execution.debug:
60+
path: /import-export/execution/{id}/debug/{index}
61+
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::debugExecution }
62+
5363
import_export.job.delete:
54-
path: /import-export/job/{id}/delete
64+
path: /import-export/execution/{id}/delete
5565
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::delete }
5666

5767
import_export.writer.download_file:

components/ImportExportBundle/src/bundle/Resources/views/themes/admin/import_export/job/view.html.twig

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,18 @@
118118
{% if execution.isCancelable() %}
119119
<a
120120
title="{{ 'job.execution.cancel'|trans|desc('Cancel') }}"
121-
href="{{ path('import_export.job.cancel', {'id': execution.id}) }}"
121+
href="{{ path('import_export.execution.cancel', {'id': execution.id}) }}"
122122
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"
123123
>
124124
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--edit">
125125
<use xlink:href="{{ ibexa_icon_path('discard') }}"></use>
126126
</svg>
127127
</a>
128-
{% elseif execution.isRunning() %}
128+
{% endif %}
129+
{% if execution.isRunning() %}
129130
<a
130131
title="{{ 'job.execution.pause'|trans|desc('pause') }}"
131-
href="{{ path('import_export.job.pause', {'id': execution.id}) }}"
132+
href="{{ path('import_export.execution.pause', {'id': execution.id}) }}"
132133
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"
133134
>
134135
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--edit">
@@ -138,7 +139,7 @@
138139
{% elseif execution.canRun() %}
139140
<a
140141
title="{{ 'job.execution.run'|trans|desc('Run') }}"
141-
href="{{ path('import_export.job.run', {'id': execution.id}) }}"
142+
href="{{ path('import_export.execution.run', {'id': execution.id}) }}"
142143
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"
143144
>
144145
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--edit">
@@ -206,7 +207,7 @@
206207

207208
{% if current_execution.isCancelable() %}
208209
<a
209-
href="{{ path('import_export.job.cancel', {'id': current_execution.id}) }}"
210+
href="{{ path('import_export.execution.cancel', {'id': current_execution.id}) }}"
210211
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"
211212
>
212213
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--edit">
@@ -216,9 +217,10 @@
216217
{{ 'job.execution.cancel'|trans|desc('Cancel') }}
217218
</span>
218219
</a>
219-
{% elseif current_execution.isRunning() %}
220+
{% endif %}
221+
{% if current_execution.isRunning() %}
220222
<a
221-
href="{{ path('import_export.job.pause', {'id': current_execution.id}) }}"
223+
href="{{ path('import_export.execution.pause', {'id': current_execution.id}) }}"
222224
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"
223225
>
224226
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--edit">
@@ -230,7 +232,7 @@
230232
</a>
231233
{% elseif current_execution.canRun() %}
232234
<a
233-
href="{{ path('import_export.job.run', {'id': job.id}) }}"
235+
href="{{ path('import_export.execution.run', {'id': current_execution.id}) }}"
234236
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"
235237
>
236238
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--edit">

components/ImportExportBundle/src/lib/Component/AbstractComponent.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use AlmaviaCX\Bundle\IbexaImportExport\Monolog\WorkflowLoggerInterface;
88
use AlmaviaCX\Bundle\IbexaImportExport\Reference\ReferenceBag;
9+
use AlmaviaCX\Bundle\IbexaImportExport\Workflow\WorkflowState;
910
use InvalidArgumentException;
1011

1112
/**
@@ -71,8 +72,8 @@ public function setLogger(WorkflowLoggerInterface $logger): void
7172
$this->logger = $logger;
7273
}
7374

74-
public function setReferenceBag(ReferenceBag $referenceBag): void
75+
public function setState(WorkflowState $state): void
7576
{
76-
$this->referenceBag = $referenceBag;
77+
$this->referenceBag = $state->getReferenceBag();
7778
}
7879
}

components/ImportExportBundle/src/lib/Component/ComponentInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace AlmaviaCX\Bundle\IbexaImportExport\Component;
66

77
use AlmaviaCX\Bundle\IbexaImportExport\Monolog\WorkflowLoggerInterface;
8-
use AlmaviaCX\Bundle\IbexaImportExport\Reference\ReferenceBag;
8+
use AlmaviaCX\Bundle\IbexaImportExport\Workflow\WorkflowState;
99
use Symfony\Component\Translation\TranslatableMessage;
1010

1111
/**
@@ -36,9 +36,9 @@ public function clean(): void;
3636

3737
public function setLogger(WorkflowLoggerInterface $logger): void;
3838

39-
public function setReferenceBag(ReferenceBag $referenceBag): void;
40-
4139
public function prepare(): void;
4240

4341
public function finish(): void;
42+
43+
public function setState(WorkflowState $state): void;
4444
}

components/ImportExportBundle/src/lib/Event/Subscriber/RemoveWrittenFilesEventSubscriber.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

components/ImportExportBundle/src/lib/Execution/Execution.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ public function getLoggerRecords(): Collection
110110
}
111111

112112
/**
113-
* @return \Doctrine\Common\Collections\Selectable<string, ExecutionRecord>
113+
* @return \Doctrine\Common\Collections\Selectable<string, ExecutionRecord>|null
114114
*/
115-
public function getRecordsForLevel(int $level): Selectable
115+
public function getRecordsForLevel(int $level): ?Selectable
116116
{
117117
$criteria = new Criteria();
118118
$criteria->where(new Comparison('level', '=', $level));
119119

120-
return $this->loggerRecords->matching($criteria);
120+
return $this->loggerRecords instanceof Selectable ? $this->loggerRecords->matching($criteria) : null;
121121
}
122122

123123
/**

components/ImportExportBundle/src/lib/Execution/ExecutionRunner.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public function __invoke(Execution $execution, int $batchLimit = -1): int
3636

3737
$this->eventDispatcher->dispatch(new PreJobRunEvent($execution, $workflow));
3838

39-
if (null !== $execution->getWorkflowState()) {
40-
$workflow->setState($execution->getWorkflowState());
41-
}
39+
$workflow->setState($execution->getWorkflowState());
4240
$execution->setStatus(Execution::STATUS_RUNNING);
4341
$this->executionRepository->save($execution);
4442

components/ImportExportBundle/src/lib/Item/Iterator/DoctrineSeekableItemIterator.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@
44

55
namespace AlmaviaCX\Bundle\IbexaImportExport\Item\Iterator;
66

7-
use AlmaviaCX\Bundle\IbexaImportExport\Accessor\ArrayAccessor;
8-
use AlmaviaCX\Bundle\IbexaImportExport\Reader\ReaderIteratorInterface;
97
use Doctrine\DBAL\Connection;
10-
use Iterator;
11-
use SeekableIterator;
128

13-
/**
14-
* @implements Iterator<int, ArrayAccessor>
15-
* @implements SeekableIterator<int, ArrayAccessor>
16-
*/
17-
class DoctrineSeekableItemIterator extends PaginatedQueryIterator implements ReaderIteratorInterface, SeekableIterator
9+
class DoctrineSeekableItemIterator extends PaginatedQueryIterator
1810
{
1911
public function __construct(
2012
protected Connection $connection,

0 commit comments

Comments
 (0)