1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2020 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2020 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\CoreBundle\AnalyticsExport; |
18
|
|
|
|
19
|
|
|
use League\Flysystem\Filesystem; |
20
|
|
|
use SWP\Bundle\CoreBundle\Model\AnalyticsReportInterface; |
21
|
|
|
use Symfony\Component\Routing\RouterInterface; |
22
|
|
|
|
23
|
|
|
final class ReportFileUploader |
24
|
|
|
{ |
25
|
|
|
/** @var CsvReportFileLocationResolver */ |
26
|
|
|
private $assetLocationResolver; |
27
|
|
|
|
28
|
|
|
/** @var Filesystem */ |
29
|
|
|
private $filesystem; |
30
|
|
|
|
31
|
|
|
/** @var RouterInterface */ |
32
|
|
|
private $router; |
33
|
|
|
|
34
|
|
|
public function __construct( |
35
|
|
|
CsvReportFileLocationResolver $assetLocationResolver, |
36
|
|
|
Filesystem $filesystem, |
37
|
|
|
RouterInterface $router |
38
|
|
|
) { |
39
|
|
|
$this->assetLocationResolver = $assetLocationResolver; |
40
|
|
|
$this->filesystem = $filesystem; |
41
|
|
|
$this->router = $router; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function upload(AnalyticsReportInterface $file, string $sourcePath): string |
45
|
|
|
{ |
46
|
|
|
$uploadPath = $this->assetLocationResolver->getMediaBasePath().'/'.$file->getAssetId(); |
47
|
|
|
|
48
|
|
|
$stream = fopen($sourcePath, 'rb+'); |
49
|
|
|
$this->filesystem->writeStream($uploadPath, $stream); |
50
|
|
|
fclose($stream); |
51
|
|
|
|
52
|
|
|
return $this->router->generate('swp_export_analytics_download', [ |
53
|
|
|
'fileName' => $file->getAssetId(), |
54
|
|
|
], RouterInterface::ABSOLUTE_URL); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|