2
2
3
3
namespace Drupal \dgi_migrate \Plugin \migrate \process ;
4
4
5
+ use Drupal \Core \File \FileSystemInterface ;
5
6
use Drupal \migrate \MigrateSkipRowException ;
6
7
7
8
/**
@@ -27,30 +28,28 @@ trait EnsureNonWritableTrait {
27
28
* @throws \Drupal\migrate\MigrateSkipRowException
28
29
* If the file appears to be writable/deletable.
29
30
*/
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 )) {
34
33
throw new MigrateSkipRowException (strtr ('Source ({path}) does not appear to be a plain file; skipping row. ' , [
35
34
'{path} ' => $ path ,
36
35
]));
37
36
}
38
- if ($ file -> isDir ( )) {
37
+ if (is_dir ( $ path )) {
39
38
throw new MigrateSkipRowException (strtr ('Source ({path}) appears to be a directory; skipping row. ' , [
40
39
'{path} ' => $ path ,
41
40
]));
42
41
}
43
- if (!$ file -> isReadable ( )) {
42
+ if (!is_readable ( $ path )) {
44
43
throw new MigrateSkipRowException (strtr ('Source ({path}) does not appear to be readable; skipping row. ' , [
45
44
'{path} ' => $ path ,
46
45
]));
47
46
}
48
- if ($ file -> isWritable ( )) {
47
+ if (is_writable ( $ path )) {
49
48
throw new MigrateSkipRowException (strtr ('Source ({path}) appears to be writable(/deletable); skipping row. ' , [
50
49
'{path} ' => $ path ,
51
50
]));
52
51
}
53
- if ($ file -> getPathInfo ()?->isWritable( )) {
52
+ if (is_writable ( $ this -> getFileSystem ()-> dirname ( $ path ) )) {
54
53
throw new MigrateSkipRowException (strtr ('Directory of source ({path}) appears writable(/deletable); skipping row. ' , [
55
54
'{path} ' => $ path ,
56
55
]));
@@ -59,4 +58,25 @@ protected static function ensureNonWritable(string $path) : string {
59
58
return $ path ;
60
59
}
61
60
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
+
62
82
}
0 commit comments