Skip to content

Commit 28b6cf1

Browse files
committed
Merge branch 'PR-28' into v1
2 parents 918b682 + 8fbc1b8 commit 28b6cf1

File tree

6 files changed

+89
-4
lines changed

6 files changed

+89
-4
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_file.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

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ In the Magento admin, you can find the results in:
6464
- for Magento 2.1.x: Products > Data Integrity Checker
6565
- for Magento 2.2.0 and higher: Catalog > Data Integrity Checker
6666

67-
The results of the checkers are currently stored in the directory `var/tmp` as `.json` files.
67+
The results of the checkers are currently stored by default in the directory `var/tmp` as `.json` files.
68+
But you can change the path in the backend settings under Stores > Configuration > Catalog > Url Data Integrity Checker by entering a relative path starting from the Magento installation directory or an absolute path. The directory you enter there needs to exist before it will work.
6869

6970
## Some screenshots
7071

Storage/FileStorage.php

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

77
use Baldwin\UrlDataIntegrityChecker\Exception\SerializationException;
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
89
use Magento\Framework\App\Filesystem\DirectoryList;
910
use Magento\Framework\Exception\FileSystemException;
1011
use Magento\Framework\Filesystem;
12+
use Magento\Framework\Filesystem\Directory\ReadFactory;
13+
use Magento\Framework\Filesystem\Directory\WriteFactory;
14+
use Magento\Framework\Filesystem\Driver\File as FileDriver;
1115

1216
class FileStorage extends AbstractStorage implements StorageInterface
1317
{
18+
const CONFIG_PATH = 'url_data_integrity_checker/configuration/filestorage_path';
19+
1420
private $filesystem;
21+
private $scopeConfig;
22+
private $writeFactory;
23+
private $readFactory;
24+
private $fileDriver;
1525

1626
public function __construct(
17-
Filesystem $filesystem
27+
Filesystem $filesystem,
28+
ScopeConfigInterface $scopeConfig,
29+
WriteFactory $writeFactory,
30+
ReadFactory $readFactory,
31+
FileDriver $fileDriver
1832
) {
1933
$this->filesystem = $filesystem;
34+
$this->scopeConfig = $scopeConfig;
35+
$this->writeFactory = $writeFactory;
36+
$this->readFactory = $readFactory;
37+
$this->fileDriver = $fileDriver;
2038
}
2139

2240
public function write(string $identifier, array $data): bool
2341
{
24-
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
42+
$directory = $this->writeFactory->create($this->getPath());
2543
$directory->create();
2644
$filename = $this->getFilename($identifier);
2745

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

4058
public function read(string $identifier): array
4159
{
42-
$directory = $this->filesystem->getDirectoryRead(DirectoryList::TMP);
60+
$directory = $this->readFactory->create($this->getPath());
4361
$filename = $this->getFilename($identifier);
4462

4563
$data = '';
@@ -57,4 +75,34 @@ private function getFilename(string $identifier): string
5775
{
5876
return 'baldwin-url-data-integrity-checker-' . $identifier . '.json';
5977
}
78+
79+
private function getPath(): string
80+
{
81+
$path = $this->scopeConfig->getValue(
82+
self::CONFIG_PATH
83+
);
84+
85+
if ($path === '' || $path === null) {
86+
$path = 'var/tmp';
87+
}
88+
89+
if ($this->fileDriver->getRealPath($path) === false) {
90+
$rootDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
91+
$path = $rootDir . '/' . $path;
92+
93+
if ($this->fileDriver->getRealPath($path) === false) {
94+
$path = $this->filesystem->getDirectoryRead(DirectoryList::TMP)->getAbsolutePath();
95+
}
96+
} else {
97+
$path = $this->fileDriver->getRealPath($path);
98+
// hack: these next 3 lines won't ever trigger in real life, but is to satisfy phpstan
99+
// (I think this is a bug in phpstan)
100+
if ($path === true) {
101+
$path = '';
102+
}
103+
// end hack
104+
}
105+
106+
return $path;
107+
}
60108
}

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_data_integrity" title="Data Integrity Checker Config"/>
13+
</resource>
14+
</resource>
15+
</resource>
916
</resource>
1017
</resources>
1118
</acl>

etc/adminhtml/system.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
<section id="url_data_integrity_checker" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" translate="label">
5+
<label>Url Data Integrity Checker</label>
6+
<tab>catalog</tab>
7+
<resource>Baldwin_UrlDataIntegrityChecker::config_data_integrity</resource>
8+
<group id="configuration" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" translate="label">
9+
<label>Configuration</label>
10+
<field id="filestorage_path" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" translate="label">
11+
<label>Path to store results</label>
12+
<comment>Path where to store json files, can be either an absolute or a relative path</comment>
13+
</field>
14+
</group>
15+
</section>
16+
</system>
17+
</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_data_integrity_checker>
5+
<configuration>
6+
<filestorage_path>var/tmp</filestorage_path>
7+
</configuration>
8+
</url_data_integrity_checker>
9+
</default>
10+
</config>

0 commit comments

Comments
 (0)