1
1
<?php
2
2
namespace TNW \Salesforce \Controller \Adminhtml \System \Log ;
3
3
4
+ use Exception ;
5
+ use InvalidArgumentException ;
6
+ use Magento \Backend \App \Action ;
7
+ use Magento \Backend \App \Action \Context ;
4
8
use Magento \Framework \App \Filesystem \DirectoryList ;
9
+ use Magento \Framework \App \Response \Http \FileFactory ;
10
+ use Magento \Framework \App \ResponseInterface ;
11
+ use Magento \Framework \Controller \ResultInterface ;
12
+ use Magento \Framework \Exception \NotFoundException ;
13
+ use TNW \Salesforce \Model \Config ;
5
14
6
- class Download extends \ Magento \ Backend \ App \ Action
15
+ class Download extends Action
7
16
{
8
17
/**
9
- * @var \Magento\Framework\App\Response\Http\ FileFactory
18
+ * @var FileFactory
10
19
*/
11
20
protected $ fileFactory ;
12
21
22
+ /** @var Config */
23
+ protected $ salesforceConfig ;
24
+
13
25
public function __construct (
14
- \Magento \Backend \App \Action \Context $ context ,
15
- \Magento \Framework \App \Response \Http \FileFactory $ fileFactory
26
+ Context $ context ,
27
+ FileFactory $ fileFactory ,
28
+ Config $ salesforceConfig
16
29
) {
17
30
$ this ->fileFactory = $ fileFactory ;
31
+ $ this ->salesforceConfig = $ salesforceConfig ;
18
32
parent ::__construct ($ context );
19
33
}
20
34
21
35
/**
22
36
* Dispatch request
23
37
*
24
- * @return \Magento\Framework\Controller\ ResultInterface|\Magento\Framework\App\ ResponseInterface
25
- * @throws \Magento\Framework\Exception\ NotFoundException
26
- * @throws \ InvalidArgumentException
27
- * @throws \ Exception
38
+ * @return ResultInterface|ResponseInterface
39
+ * @throws NotFoundException
40
+ * @throws InvalidArgumentException
41
+ * @throws Exception
28
42
*/
29
43
public function execute ()
30
44
{
45
+ $ baseDay = $ this ->salesforceConfig ->logBaseDay ();
46
+
47
+ $ filenamePath = sprintf ('log/sforce/%d_%d_%d.log ' , date ('Y ' ), $ baseDay , floor ((date ('z ' ) + 1 ) / $ baseDay ));
48
+
31
49
return $ this ->fileFactory ->create ('sforce.log ' , [
32
50
'type ' => 'filename ' ,
33
- 'value ' => ' log/sforce.log '
51
+ 'value ' => $ filenamePath
34
52
], DirectoryList::VAR_DIR );
35
53
}
36
- }
54
+ }
0 commit comments