1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Payone\Core\Model\System\Config\Backend; |
4
|
|
|
|
5
|
|
|
use Magento\Framework\Filesystem; |
|
|
|
|
6
|
|
|
use Magento\Framework\Filesystem\DirectoryList; |
|
|
|
|
7
|
|
|
|
8
|
|
|
class Upload extends \Magento\Framework\App\Config\Value |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var \Magento\Framework\Filesystem\Directory\ReadInterface |
|
|
|
|
12
|
|
|
*/ |
13
|
|
|
protected $_tmpDirectory; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var \Payone\Core\Helper\ApplePay |
17
|
|
|
*/ |
18
|
|
|
protected $applePayHelper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param \Magento\Framework\Model\Context $context |
22
|
|
|
* @param \Magento\Framework\Registry $registry |
23
|
|
|
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config |
24
|
|
|
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList |
25
|
|
|
* @param \Magento\Framework\Filesystem $filesystem |
26
|
|
|
* @param \Payone\Core\Helper\ApplePay $applePayHelper |
27
|
|
|
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource |
28
|
|
|
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection |
29
|
|
|
* @param array $data |
30
|
|
|
*/ |
31
|
|
|
public function __construct( |
32
|
|
|
\Magento\Framework\Model\Context $context, |
|
|
|
|
33
|
|
|
\Magento\Framework\Registry $registry, |
|
|
|
|
34
|
|
|
\Magento\Framework\App\Config\ScopeConfigInterface $config, |
|
|
|
|
35
|
|
|
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, |
|
|
|
|
36
|
|
|
\Magento\Framework\Filesystem $filesystem, |
37
|
|
|
\Payone\Core\Helper\ApplePay $applePayHelper, |
38
|
|
|
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, |
|
|
|
|
39
|
|
|
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, |
|
|
|
|
40
|
|
|
array $data = [] |
41
|
|
|
) |
42
|
|
|
{ |
43
|
|
|
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); |
44
|
|
|
$this->_tmpDirectory = $filesystem->getDirectoryRead(DirectoryList::SYS_TMP); |
45
|
|
|
$this->applePayHelper = $applePayHelper; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Process additional data before save config |
50
|
|
|
* |
51
|
|
|
* @return $this |
52
|
|
|
* @throws \Magento\Framework\Exception\LocalizedException |
53
|
|
|
*/ |
54
|
|
|
public function beforeSave() |
55
|
|
|
{ |
56
|
|
|
$value = $this->getValue(); |
57
|
|
|
|
58
|
|
|
if (!empty($value['value'])) { |
59
|
|
|
$this->setValue($value['value']); |
60
|
|
|
} elseif (!isset($value['value'])) { |
61
|
|
|
$this->setValue(''); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (is_array($value) && !empty($value['delete'])) { |
65
|
|
|
$sCurrentFile = $this->applePayHelper->getApplePayUploadPath().$value['value']; |
66
|
|
|
if (file_exists($sCurrentFile)) { |
67
|
|
|
unlink($sCurrentFile); |
68
|
|
|
} |
69
|
|
|
$this->setValue(''); |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (empty($value['tmp_name'])) { |
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$tmpPath = $this->_tmpDirectory->getRelativePath($value['tmp_name']); |
78
|
|
|
if ($tmpPath && $this->_tmpDirectory->isExist($tmpPath)) { |
79
|
|
|
if (!$this->_tmpDirectory->stat($tmpPath)['size']) { |
80
|
|
|
throw new \Magento\Framework\Exception\LocalizedException(__('The certificate file is empty.')); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
$this->setValue($value['name']); |
83
|
|
|
|
84
|
|
|
$this->moveFile($value['tmp_name'], $value['name']); |
85
|
|
|
} |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Copies file to upload path |
91
|
|
|
* |
92
|
|
|
* @param string $sFilePath |
93
|
|
|
* @param string $sFileName |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
protected function moveFile($sFilePath, $sFileName) |
97
|
|
|
{ |
98
|
|
|
$sUploadPath = $this->applePayHelper->getApplePayUploadPath(); |
99
|
|
|
if (!file_exists($sUploadPath)) { |
100
|
|
|
mkdir($sUploadPath); |
101
|
|
|
} |
102
|
|
|
move_uploaded_file($sFilePath, $sUploadPath.$sFileName); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths