Now the files migration does not die when a file is missing.

It now just ignore that file and continue with the rest.
This commit is contained in:
David Valdez 2019-08-30 12:54:44 -05:00
parent e62dcf96f4
commit d7e81b4703
2 changed files with 42 additions and 3 deletions

View file

@ -9,7 +9,7 @@ source:
plugin: d7_file
scheme: public
constants:
source_base_path: '/var/www/html/d7/'
source_base_path: '../d7/'
process:
fid:
-
@ -29,11 +29,11 @@ process:
-
plugin: urlencode
uri:
-
plugin: file_copy
- plugin: geo_file_exists
source:
- '@source_full_path'
- uri
- plugin: file_copy
filemime:
-
plugin: get

View file

@ -0,0 +1,39 @@
<?php
namespace Drupal\geo_upgrade\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* @MigrateProcessPlugin(
* id = "geo_file_exists"
* )
*/
class FileExists extends ProcessPluginBase {
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($source, $destination) = $value;
// Ensure the source file exists.
if (!file_exists($source)) {
throw new MigrateSkipRowException("File '$source' does not exist");
}
return $value;
}
}