Skip to content

Commit a75b679

Browse files
authored
Merge pull request #146 from discoverygarden/fix/avoid-spl-file-info
Avoid use of `\SplFileInfo()`.
2 parents 567ed28 + e829bb9 commit a75b679

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

modules/dgi_migrate_foxml_standard_mods/src/Plugin/migrate/process/FoxmlFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
9494
$row,
9595
$destination_property,
9696
),
97-
'direct' => static::ensureNonWritable($value),
97+
'direct' => $this->ensureNonWritable($value),
9898
};
9999
}
100100

src/Plugin/migrate/process/EnsureNonWritableTrait.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\dgi_migrate\Plugin\migrate\process;
44

5+
use Drupal\Core\File\FileSystemInterface;
56
use Drupal\migrate\MigrateSkipRowException;
67

78
/**
@@ -27,30 +28,28 @@ trait EnsureNonWritableTrait {
2728
* @throws \Drupal\migrate\MigrateSkipRowException
2829
* If the file appears to be writable/deletable.
2930
*/
30-
protected static function ensureNonWritable(string $path) : string {
31-
$file = new \SplFileInfo($path);
32-
33-
if (!$file->isFile()) {
31+
protected function ensureNonWritable(string $path) : string {
32+
if (!is_file($path)) {
3433
throw new MigrateSkipRowException(strtr('Source ({path}) does not appear to be a plain file; skipping row.', [
3534
'{path}' => $path,
3635
]));
3736
}
38-
if ($file->isDir()) {
37+
if (is_dir($path)) {
3938
throw new MigrateSkipRowException(strtr('Source ({path}) appears to be a directory; skipping row.', [
4039
'{path}' => $path,
4140
]));
4241
}
43-
if (!$file->isReadable()) {
42+
if (!is_readable($path)) {
4443
throw new MigrateSkipRowException(strtr('Source ({path}) does not appear to be readable; skipping row.', [
4544
'{path}' => $path,
4645
]));
4746
}
48-
if ($file->isWritable()) {
47+
if (is_writable($path)) {
4948
throw new MigrateSkipRowException(strtr('Source ({path}) appears to be writable(/deletable); skipping row.', [
5049
'{path}' => $path,
5150
]));
5251
}
53-
if ($file->getPathInfo()?->isWritable()) {
52+
if (is_writable($this->getFileSystem()->dirname($path))) {
5453
throw new MigrateSkipRowException(strtr('Directory of source ({path}) appears writable(/deletable); skipping row.', [
5554
'{path}' => $path,
5655
]));
@@ -59,4 +58,25 @@ protected static function ensureNonWritable(string $path) : string {
5958
return $path;
6059
}
6160

61+
/**
62+
* Drupal's file system service.
63+
*
64+
* @var \Drupal\Core\File\FileSystemInterface
65+
*/
66+
protected FileSystemInterface $fileSystem;
67+
68+
/**
69+
* Accessor for Drupal's file system service.
70+
*
71+
* @return \Drupal\Core\File\FileSystemInterface
72+
* Drupal's file system service.
73+
*/
74+
protected function getFileSystem() : FileSystemInterface {
75+
if (!isset($this->fileSystem)) {
76+
$this->fileSystem = \Drupal::service('file_system');
77+
}
78+
79+
return $this->fileSystem;
80+
}
81+
6282
}

src/Plugin/migrate/process/NonWritable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NonWritable extends ProcessPluginBase {
2626
* {@inheritDoc}
2727
*/
2828
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
29-
return static::ensureNonWritable($value);
29+
return $this->ensureNonWritable($value);
3030
}
3131

3232
}

0 commit comments

Comments
 (0)