Skip to content

Commit da57a85

Browse files
committed
Add Support for php etl 1.0 .
1 parent 1d78092 commit da57a85

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.0.0
2+
- :confetti_ball: :tada: First stable release :tada: :confetti_ball:
3+
- :star2: Added support for php etl 1.0 stable release.
4+
- :star2: Added support for symfony 6
5+
- :wrench: Download of ETL file execution will now work with even big files. (Not limited by memory)
16

27
# 1.0.0 Alpha #2
38

Controller/Admin/EtlDownloadFileController.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,26 @@
66
use Oliverde8\PhpEtlBundle\Entity\EtlExecution;
77
use Oliverde8\PhpEtlBundle\Security\EtlExecutionVoter;
88
use Oliverde8\PhpEtlBundle\Services\ChainWorkDirManager;
9+
use Oliverde8\PhpEtlBundle\Services\ExecutionContextFactory;
910
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
1011
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
12+
use Symfony\Component\HttpFoundation\HeaderUtils;
1113
use Symfony\Component\HttpFoundation\Request;
1214
use Symfony\Component\HttpFoundation\Response;
15+
use Symfony\Component\HttpFoundation\StreamedResponse;
1316
use Symfony\Component\Routing\Annotation\Route;
1417

1518
class EtlDownloadFileController extends AbstractController
1619
{
17-
/** @var ChainWorkDirManager */
18-
protected $chainWorkDirManager;
20+
/** @var ExecutionContextFactory */
21+
protected $executionContextFactory;
1922

2023
/**
21-
* EtlDownloadFileController constructor.
22-
* @param ChainWorkDirManager $chainWorkDirManager
24+
* @param ExecutionContextFactory $executionContextFactory
2325
*/
24-
public function __construct(ChainWorkDirManager $chainWorkDirManager)
26+
public function __construct(ExecutionContextFactory $executionContextFactory)
2527
{
26-
$this->chainWorkDirManager = $chainWorkDirManager;
28+
$this->executionContextFactory = $executionContextFactory;
2729
}
2830

2931
/**
@@ -34,10 +36,20 @@ public function index(EtlExecution $execution, string $filename): Response
3436
{
3537
$this->denyAccessUnlessGranted(EtlExecutionVoter::DOWNLOAD, EtlExecution::class);
3638

37-
//TODO add Acl here for future proofing.
38-
return $this->file(
39-
$this->chainWorkDirManager->getWorkDir($execution) . "/" . $filename,
39+
$context = $this->executionContextFactory->get(['etl' => ['execution' => $execution]]);
40+
$file = $context->getFileSystem()->readStream($filename);
41+
42+
$response = new StreamedResponse(function () use ($file) {
43+
$outputStream = fopen('php://output', 'wb');
44+
stream_copy_to_stream($file, $outputStream);
45+
});
46+
47+
$disposition = HeaderUtils::makeDisposition(
48+
HeaderUtils::DISPOSITION_ATTACHMENT,
4049
"execution-{$execution->getName()}-{$execution->getId()}-" . $filename
4150
);
51+
$response->headers->set('Content-Disposition', $disposition);
52+
53+
return $response;
4254
}
4355
}

Controller/Admin/EtlExecutionCrudController.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,30 @@
2020
use Oliverde8\PhpEtlBundle\Security\EtlExecutionVoter;
2121
use Oliverde8\PhpEtlBundle\Services\ChainProcessorsManager;
2222
use Oliverde8\PhpEtlBundle\Services\ChainWorkDirManager;
23+
use Oliverde8\PhpEtlBundle\Services\ExecutionContextFactory;
2324

2425
class EtlExecutionCrudController extends AbstractCrudController
2526
{
26-
/** @var ChainWorkDirManager */
27-
protected $chainWorkDirManager;
27+
/** @var ExecutionContextFactory */
28+
protected $executionContextFactory;
2829

2930
/** @var ChainProcessorsManager */
3031
protected $chainProcessorManager;
3132

3233
/** @var AdminUrlGenerator */
3334
protected $adminUrlGenerator;
3435

35-
/**
36-
* EtlExecutionCrudController constructor.
37-
* @param ChainWorkDirManager $chainWorkDirManager
38-
* @param ChainProcessorsManager $chainProcessorManager
39-
* @param AdminUrlGenerator $adminUrlGenerator
40-
*/
4136
public function __construct(
42-
ChainWorkDirManager $chainWorkDirManager,
37+
ExecutionContextFactory $executionContextFactory,
4338
ChainProcessorsManager $chainProcessorManager,
4439
AdminUrlGenerator $adminUrlGenerator
4540
) {
46-
$this->chainWorkDirManager = $chainWorkDirManager;
41+
$this->executionContextFactory = $executionContextFactory;
4742
$this->chainProcessorManager = $chainProcessorManager;
4843
$this->adminUrlGenerator = $adminUrlGenerator;
4944
}
5045

46+
5147
public static function getEntityFqcn(): string
5248
{
5349
return EtlExecution::class;
@@ -105,21 +101,35 @@ public function configureFields(string $pageName): iterable
105101
TextField::new('Files')->formatValue(function ($value, EtlExecution $entity) {
106102
$urls = [];
107103
if ($this->isGranted(EtlExecutionVoter::DOWNLOAD, EtlExecution::class)) {
108-
$files = $this->chainWorkDirManager->listFiles($entity);
104+
105+
$context = $this->executionContextFactory->get(['etl' => ['execution' => $entity]]);
106+
$files = $context->getFileSystem()->listContents("/");
109107
foreach ($files as $file) {
110-
$url = $this->adminUrlGenerator
111-
->setRoute("etl_execution_download_file", ['execution' => $entity->getId(), 'filename' => $file])
112-
->generateUrl();
108+
if (strpos($file, '.') !== 0) {
109+
$url = $this->adminUrlGenerator
110+
->setRoute("etl_execution_download_file", ['execution' => $entity->getId(), 'filename' => $file])
111+
->generateUrl();
113112

114-
$urls[$url] = $file;
113+
$urls[$url] = $file;
114+
}
115115
}
116116
}
117117

118118
return $urls;
119119
})->setTemplatePath('@Oliverde8PhpEtlEasyAdmin/fields/files.html.twig'),
120+
120121
CodeEditorField::new('errorMessage')->setTemplatePath('@Oliverde8PhpEtlEasyAdmin/fields/code_editor.html.twig'),
121122
TextField::new('Logs')->formatValue(function ($value, EtlExecution $entity) {
122-
$logs = $this->chainWorkDirManager->getFirstLogLines($entity, 100);
123+
$context = $this->executionContextFactory->get(['etl' => ['execution' => $entity]]);
124+
$logs = [];
125+
$file = $context->getFileSystem()->readStream("execution.log");
126+
$i = 0;
127+
while ($i < 100 && $line = fgets($file)) {
128+
$logs[] = $line;
129+
$i++;
130+
}
131+
fclose($file);
132+
123133
$url = "";
124134
$moreLogs = false;
125135
if (!empty($logs)) {

0 commit comments

Comments
 (0)