Skip to content

Commit 07f1e2d

Browse files
committed
Configurable paths
1 parent aa47d04 commit 07f1e2d

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ checkstyle:
2020
checkquality:
2121
vendor/bin/phpstan analyse
2222

23+
xmllint --noout --schema vendor/magento/module-store/etc/config.xsd etc/config.xml
2324
xmllint --noout --schema vendor/magento/module-backend/etc/menu.xsd etc/adminhtml/menu.xml
2425
xmllint --noout --schema vendor/magento/framework/App/etc/routes.xsd etc/adminhtml/routes.xml
26+
xmllint --noout --schema vendor/magento/module-config/etc/system.xsd etc/adminhtml/system.xml
2527
xmllint --noout --schema vendor/magento/framework/Acl/etc/acl.xsd etc/acl.xml
2628
xmllint --noout --schema vendor/magento/module-cron/etc/cron_groups.xsd etc/cron_groups.xml
2729
xmllint --noout --schema vendor/magento/module-cron/etc/crontab.xsd etc/crontab.xml

Storage/FileStorage.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@
55
namespace Baldwin\UrlDataIntegrityChecker\Storage;
66

77
use Baldwin\UrlDataIntegrityChecker\Exception\SerializationException;
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Store\Model\ScopeInterface;
810
use Magento\Framework\App\Filesystem\DirectoryList;
911
use Magento\Framework\Exception\FileSystemException;
1012
use Magento\Framework\Filesystem;
1113

1214
class FileStorage extends AbstractStorage implements StorageInterface
1315
{
16+
const CONFIG_PATH = 'url/checker/path';
17+
1418
private $filesystem;
19+
private $scopeConfig;
1520

1621
public function __construct(
17-
Filesystem $filesystem
22+
Filesystem $filesystem,
23+
ScopeConfigInterface $scopeConfig
1824
) {
1925
$this->filesystem = $filesystem;
26+
$this->scopeConfig = $scopeConfig;
2027
}
2128

2229
public function write(string $identifier, array $data): bool
2330
{
24-
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
31+
$directory = $this->filesystem->getDirectoryWrite($this->getPath() ?: DirectoryList::TMP);
2532
$directory->create();
2633
$filename = $this->getFilename($identifier);
2734

@@ -39,7 +46,7 @@ public function write(string $identifier, array $data): bool
3946

4047
public function read(string $identifier): array
4148
{
42-
$directory = $this->filesystem->getDirectoryRead(DirectoryList::TMP);
49+
$directory = $this->filesystem->getDirectoryRead($this->getPath() ?: DirectoryList::TMP);
4350
$filename = $this->getFilename($identifier);
4451

4552
$data = '';
@@ -57,4 +64,12 @@ private function getFilename(string $identifier): string
5764
{
5865
return 'baldwin-url-data-integrity-checker-' . $identifier . '.json';
5966
}
67+
68+
private function getPath(): string
69+
{
70+
return $this->scopeConfig->getValue(
71+
self::CONFIG_PATH,
72+
ScopeInterface::SCOPE_STORE
73+
);
74+
}
6075
}

etc/acl.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
<resource id="Magento_Catalog::catalog">
77
<resource id="Baldwin_UrlDataIntegrityChecker::catalog_data_integrity" title="Data Integrity Checker" translate="title" sortOrder="100"/>
88
</resource>
9+
<resource id="Magento_Backend::stores">
10+
<resource id="Magento_Backend::stores_settings">
11+
<resource id="Magento_Config::config">
12+
<resource id="Baldwin_UrlDataIntegrityChecker::config_baldwin_urldataintegritychecker" title="url"/>
13+
</resource>
14+
</resource>
15+
</resource>
916
</resource>
1017
</resources>
1118
</acl>

etc/adminhtml/system.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
3+
<system>
4+
<tab id="baldwin" translate="label" sortOrder="500">
5+
<label>Baldwin</label>
6+
</tab>
7+
<section id="url" sortOrder="10" showInWebsite="0" showInStore="0" showInDefault="1" translate="label">
8+
<label>Url Data Integrity Checker</label>
9+
<tab>baldwin</tab>
10+
<resource>Baldwin_UrlDataIntegrityChecker::config_baldwin_urldataintegritychecker</resource>
11+
<group id="checker" sortOrder="10" showInWebsite="0" showInStore="0" showInDefault="1" translate="label">
12+
<label>Config</label>
13+
<field id="path" type="text" sortOrder="10" showInWebsite="0" showInStore="0" showInDefault="1" translate="label">
14+
<label>Path</label>
15+
<comment>Path where to store json files eg tmp or media</comment>
16+
</field>
17+
</group>
18+
</section>
19+
</system>
20+
</config>

etc/config.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
3+
<default>
4+
<url>
5+
<checker>
6+
<path>tmp</path>
7+
</checker>
8+
</url>
9+
</default>
10+
</config>

0 commit comments

Comments
 (0)