Skip to content

Commit dc75554

Browse files
authored
Merge pull request #33 from userwiths/fix/svg-media-storage
fix: SVG upload issues
2 parents b4be0ae + 3999e44 commit dc75554

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
namespace Experius\WysiwygDownloads\Setup\Patch\Data;
3+
4+
use Magento\Framework\Setup\ModuleDataSetupInterface;
5+
use Magento\Framework\Setup\Patch\DataPatchInterface;
6+
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
7+
use Magento\Framework\App\Config\ScopeConfigInterface;
8+
use Magento\Framework\App\Config\Storage\WriterInterface;
9+
use Magento\MediaStorage\Model\File\Validator\NotProtectedExtension;
10+
11+
class ProtectedExtensions implements DataPatchInterface, PatchRevertableInterface
12+
{
13+
/**
14+
* @var ModuleDataSetupInterface
15+
*/
16+
private $moduleDataSetup;
17+
18+
/**
19+
* @var ScopeConfigInterface
20+
*/
21+
private $scopeConfig;
22+
23+
/**
24+
* @var WriterInterface
25+
*/
26+
private $configWriter;
27+
28+
/**
29+
* @var \Magento\Store\Model\StoreManagerInterface
30+
*/
31+
private $storeManager;
32+
33+
/**
34+
* @param ModuleDataSetupInterface $moduleDataSetup
35+
*/
36+
public function __construct(
37+
ModuleDataSetupInterface $moduleDataSetup,
38+
ScopeConfigInterface $scopeConfig,
39+
WriterInterface $configWriter,
40+
\Magento\Store\Model\StoreManagerInterface $storeManager
41+
) {
42+
$this->moduleDataSetup = $moduleDataSetup;
43+
$this->scopeConfig = $scopeConfig;
44+
$this->configWriter = $configWriter;
45+
$this->storeManager = $storeManager;
46+
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function apply()
52+
{
53+
$this->moduleDataSetup->getConnection()->startSetup();
54+
$protectedExtensions = $this->getCurrentValue();
55+
$protectedExtensions = array_diff($protectedExtensions, ['svg', 'svgz']);
56+
$protectedExtensions = implode(',', $protectedExtensions);
57+
$this->configWriter->save(
58+
NotProtectedExtension::XML_PATH_PROTECTED_FILE_EXTENSIONS,
59+
$protectedExtensions,
60+
'default',
61+
'default'
62+
);
63+
$this->moduleDataSetup->getConnection()->endSetup();
64+
}
65+
66+
/**
67+
* @inheritdoc
68+
*/
69+
public static function getDependencies()
70+
{
71+
return [];
72+
}
73+
74+
public function revert()
75+
{
76+
$this->moduleDataSetup->getConnection()->startSetup();
77+
$protectedExtensions = $this->getCurrentValue();
78+
$protectedExtensions = array_merge($protectedExtensions, ['svg', 'svgz']);
79+
$this->configWriter->save(
80+
NotProtectedExtension::XML_PATH_PROTECTED_FILE_EXTENSIONS,
81+
implode(',', $protectedExtensions),
82+
'default',
83+
'default'
84+
);
85+
$this->moduleDataSetup->getConnection()->endSetup();
86+
}
87+
88+
public function getCurrentValue()
89+
{
90+
$configValue = $this->scopeConfig->getValue(
91+
NotProtectedExtension::XML_PATH_PROTECTED_FILE_EXTENSIONS,
92+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
93+
);
94+
if(is_string($configValue)) {
95+
return explode(',', $configValue);
96+
}
97+
return $configValue ?? [];
98+
}
99+
100+
/**
101+
* @inheritdoc
102+
*/
103+
public function getAliases()
104+
{
105+
return [];
106+
}
107+
}

etc/adminhtml/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@
7676
<arguments>
7777
<argument name="imageExtensions" xsi:type="array">
7878
<item name="pdf" xsi:type="string">pdf</item>
79+
<item name="svg" xsi:type="string">svg</item>
7980
</argument>
8081
</arguments>
8182
</type>
8283
<type name="Magento\MediaGalleryRenditions\Model\Queue\FetchRenditionPathsBatches">
8384
<arguments>
8485
<argument name="fileExtensions" xsi:type="array">
8586
<item name="pdf" xsi:type="string">pdf</item>
87+
<item name="svg" xsi:type="string">svg</item>
8688
</argument>
8789
</arguments>
8890
</type>

0 commit comments

Comments
 (0)