Adds custom migration source and process plugins.

This commit is contained in:
2022-02-15 18:43:50 +00:00
parent 0c6f3f58b4
commit 65868007b9
5 changed files with 443 additions and 0 deletions
@@ -0,0 +1,54 @@
<?php
namespace Drupal\cdesai_migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Row;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drush\Drush;
/**
* Provides a 'Extract File Contents' migrate process plugin.
*
* Extracts contents of a file.
*
* @MigrateProcessPlugin(
* id = "extract_file_contents"
* )
*/
class ExtractFileContents extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* @throws \Drupal\migrate\MigrateSkipRowException
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$error = FALSE;
$page = $row->get('page');
if (is_null($value) || trim($value) === '') {
$error = "Skipping because content filepath is empty for {$page}.";
}
elseif (!is_file($value)) {
$error = "Skipping because content file is missing for {$page}.";
}
else {
$contents = file_get_contents($value);
if ($contents !== FALSE) {
return $contents;
}
$error = "Skipping because content file is unreadable for {$page}.";
}
if ($error) {
Drush::output()->writeln($error);
throw new MigrateSkipRowException($error);
}
return '';
}
}