diff --git a/modules/dgi_migrate_foxml_standard_mods/src/Plugin/migrate/process/FoxmlFile.php b/modules/dgi_migrate_foxml_standard_mods/src/Plugin/migrate/process/FoxmlFile.php index 2bd412f..a3b16a6 100644 --- a/modules/dgi_migrate_foxml_standard_mods/src/Plugin/migrate/process/FoxmlFile.php +++ b/modules/dgi_migrate_foxml_standard_mods/src/Plugin/migrate/process/FoxmlFile.php @@ -94,7 +94,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $row, $destination_property, ), - 'direct' => static::ensureNonWritable($value), + 'direct' => $this->ensureNonWritable($value), }; } diff --git a/src/Plugin/migrate/process/EnsureNonWritableTrait.php b/src/Plugin/migrate/process/EnsureNonWritableTrait.php index 28558cb..5b69409 100644 --- a/src/Plugin/migrate/process/EnsureNonWritableTrait.php +++ b/src/Plugin/migrate/process/EnsureNonWritableTrait.php @@ -2,6 +2,7 @@ namespace Drupal\dgi_migrate\Plugin\migrate\process; +use Drupal\Core\File\FileSystemInterface; use Drupal\migrate\MigrateSkipRowException; /** @@ -27,30 +28,28 @@ trait EnsureNonWritableTrait { * @throws \Drupal\migrate\MigrateSkipRowException * If the file appears to be writable/deletable. */ - protected static function ensureNonWritable(string $path) : string { - $file = new \SplFileInfo($path); - - if (!$file->isFile()) { + protected function ensureNonWritable(string $path) : string { + if (!is_file($path)) { throw new MigrateSkipRowException(strtr('Source ({path}) does not appear to be a plain file; skipping row.', [ '{path}' => $path, ])); } - if ($file->isDir()) { + if (is_dir($path)) { throw new MigrateSkipRowException(strtr('Source ({path}) appears to be a directory; skipping row.', [ '{path}' => $path, ])); } - if (!$file->isReadable()) { + if (!is_readable($path)) { throw new MigrateSkipRowException(strtr('Source ({path}) does not appear to be readable; skipping row.', [ '{path}' => $path, ])); } - if ($file->isWritable()) { + if (is_writable($path)) { throw new MigrateSkipRowException(strtr('Source ({path}) appears to be writable(/deletable); skipping row.', [ '{path}' => $path, ])); } - if ($file->getPathInfo()?->isWritable()) { + if (is_writable($this->getFileSystem()->dirname($path))) { throw new MigrateSkipRowException(strtr('Directory of source ({path}) appears writable(/deletable); skipping row.', [ '{path}' => $path, ])); @@ -59,4 +58,25 @@ protected static function ensureNonWritable(string $path) : string { return $path; } + /** + * Drupal's file system service. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected FileSystemInterface $fileSystem; + + /** + * Accessor for Drupal's file system service. + * + * @return \Drupal\Core\File\FileSystemInterface + * Drupal's file system service. + */ + protected function getFileSystem() : FileSystemInterface { + if (!isset($this->fileSystem)) { + $this->fileSystem = \Drupal::service('file_system'); + } + + return $this->fileSystem; + } + } diff --git a/src/Plugin/migrate/process/NonWritable.php b/src/Plugin/migrate/process/NonWritable.php index 5825f8d..d1fc3e9 100644 --- a/src/Plugin/migrate/process/NonWritable.php +++ b/src/Plugin/migrate/process/NonWritable.php @@ -26,7 +26,7 @@ class NonWritable extends ProcessPluginBase { * {@inheritDoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - return static::ensureNonWritable($value); + return $this->ensureNonWritable($value); } }