Browse Source

Removed all files after drupal.org migration.

Frederic G. MARAND 6 years ago
parent
commit
a14b245d84

+ 3 - 29
README.md

@@ -1,33 +1,7 @@
 # Reinstall
 
-## Usage notes
+This module is now provided on drupal.org instead
 
-### Support for term hierarchy
+https://www.drupal.org/sandbox/fgm/2904227
 
-This mechanism supports multiple parents on terms. However, it needs the 
-migrations to include its callback, within a process pipeline like:
-
-```yaml
-# In migrate_plus.migration.reinstall_terms_foo
-process:
-  parent_id:
-    -
-      plugin: skip_on_empty
-      method: process
-      source: parent
-    -
-      # This step is needed to transform the terms parents to usable values.
-      # Without it, all terms will be at level 0 in the target vocabulary.
-      plugin: callback
-      callable:
-        - '\Drupal\reinstall\Plugin\migrate\source\ReinstallTermSource'
-        - 'getParent'
-    -
-      plugin: migration
-      # Notice the reference to the current migration.
-      migration: reinstall_terms_foo
-  parent:
-    plugin: default_value
-    default_value: 0
-    source: '@parent_id'
-```
+Please go there instead and update your composer.json by removing the code.osinet.fr entries in the repositories section.@

+ 0 - 17
composer.json

@@ -1,17 +0,0 @@
-{
-    "authors": [
-        {
-            "name": "Frederic G. MARAND",
-            "email": "fgm@osinet.fr"
-        }
-    ],
-    "description": "Export and re-import the contents of a Drupal site.",
-    "license": "GPL-2.0+",
-    "minimum-stability": "dev",
-    "name": "drupal/reinstall",
-    "require": {
-        "drupal/migrate_plus": "^4.0@beta",
-        "drupal/migrate_tools": "^4.0"
-    },
-    "type": "drupal-module"
-}

+ 0 - 37
reinstall.drush.inc

@@ -1,37 +0,0 @@
-<?php
-
-/**
- * @file
- * Export content into YAML files.
- */
-
-/**
- * Implements hook_drush_command().
- */
-function reinstall_drush_command() {
-  $items['reinstall-export'] = [
-    'description' => 'Export site content.',
-    'arguments' => [],
-    'required-arguments' => 0,
-    'aliases' => ['rex'],
-    'options' => [],
-    'drupal dependencies' => [],
-  ];
-
-  return $items;
-}
-
-/**
- * Drush callback for reinstall-export.
- *
- * @param string $entity_type
- *   The entity type.
- * @param array $bundles
- *   An array of bundle names to export.
- */
-function drush_reinstall_export($entity_type = NULL, ...$bundles) {
-
-  /** @var \Drupal\reinstall\Dumper $dumper */
-  $dumper = \Drupal::service('reinstall.dumper');
-  $dumper->dump($entity_type, $bundles);
-}

+ 0 - 11
reinstall.info.yml

@@ -1,11 +0,0 @@
-name: Reinstall
-type: module
-description: "Export the content of a site to flat files and import it again."
-core: 8.x
-package: OSInet
-php: 7.0
-dependencies:
-  - drupal:migrate
-  - drupal:migrate_plus
-  - drupal:migrate_tools
-  - drupal:serialization

+ 0 - 41
reinstall.install

@@ -1,41 +0,0 @@
-<?php
-
-/**
- * @file
- * Reinstall install file.
- */
-
-/**
- * Remove migration tables.
- *
- * @param string $table
- *   The base name of the table to drop.
- */
-function reinstall_remove_migration_tables($table) {
-  $db = \Drupal::database();
-  $logger = \Drupal::logger('reinstall');
-
-  $db->schema()->dropTable('migrate_map_' . $table);
-  $logger->notice('Table migrate_map_@table dropped', [
-    '@table' => $table,
-  ]);
-
-  $db->schema()->dropTable('migrate_message_' . $table);
-  $logger->notice('Table migrate_message_@table dropped', [
-    '@table' => $table,
-  ]);
-}
-
-/**
- * Implements hook_uninstall().
- */
-function reinstall_uninstall() {
-  // Get all migrations.
-  $manager = \Drupal::service('plugin.manager.config_entity_migration');
-  $plugins = $manager->createInstances([]);
-
-  // Remove migration tables.
-  foreach ($plugins as $migration) {
-    reinstall_remove_migration_tables($migration->id());
-  }
-}

+ 0 - 37
reinstall.services.yml

@@ -1,37 +0,0 @@
-parameters:
-  reinstall.path: '../data'
-
-services:
-  logger.channel.reinstall:
-    parent: logger.channel_base
-    arguments: ['reinstall']
-
-  reinstall.dumper:
-    class: 'Drupal\reinstall\Dumper'
-    arguments:
-      - '@account_switcher'
-      - '@entity_type.bundle.info'
-      - '@entity_type.manager'
-      - '@app.root'
-      - '@serializer'
-      - '@event_dispatcher'
-      - '%reinstall.path%'
-      - '@logger.channel.reinstall'
-
-  reinstall.post_dump.file:
-    class: 'Drupal\reinstall\EventSubscriber\FilePostDump'
-    arguments:
-      - '@file_system'
-      - '%reinstall.path%'
-    tags:
-      - { name: 'event_subscriber' }
-
-  reinstall.pre_dump.taxonomy_term:
-    class: 'Drupal\reinstall\EventSubscriber\TermPreDump'
-    tags:
-      - { name: 'event_subscriber' }
-
-  reinstall.pre_import:
-    class: 'Drupal\reinstall\EventSubscriber\UserPreImport'
-    tags:
-      - { name: 'event_subscriber' }

+ 0 - 425
src/Dumper.php

@@ -1,425 +0,0 @@
-<?php
-
-namespace Drupal\reinstall;
-
-use Drupal\Core\Entity\ContentEntityStorageInterface;
-use Drupal\Core\Entity\ContentEntityTypeInterface;
-use Drupal\Core\Entity\EntityStorageInterface;
-use Drupal\Core\Entity\EntityTypeBundleInfo;
-use Drupal\Core\Entity\EntityTypeInterface;
-use Drupal\Core\Entity\EntityTypeManagerInterface;
-use Drupal\Core\Session\AccountSwitcherInterface;
-use Drupal\Core\Session\UserSession;
-use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\Serializer\Serializer;
-use Symfony\Component\Yaml\Yaml;
-
-/**
- * Class Dumper provides export for content entities.
- *
- * @see \Drupal\reinstall\ReinstallEvents
- */
-class Dumper {
-
-  /**
-   * Should probably be a service parameter in the future.
-   */
-  const BATCH_SIZE = 50;
-
-  /**
-   * The interface used to ensure the dump request is for content entities.
-   */
-  const CONTENT_INTERFACE = 'Drupal\Core\Entity\ContentEntityInterface';
-
-  /**
-   * The path to the data files to import, relative to app.root.
-   */
-  const IMPORT_PATH = '../data';
-
-  /**
-   * The structure depth at which the YAML dump switched to inline format.
-   */
-  const INLINE_DEPTH = 5;
-
-  /**
-   * The account_switcher service.
-   *
-   * @var \Drupal\Core\Session\AccountSwitcherInterface
-   */
-  protected $accountSwitcher;
-
-  /**
-   * The entity_type.bundle_info service.
-   *
-   * @var \Drupal\Core\Entity\EntityTypeBundleInfo
-   */
-
-  protected $entityTypeBundleInfo;
-
-  /**
-   * The entity_type.manager service.
-   *
-   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
-   */
-  protected $entityTypeManager;
-
-  /**
-   * The event_dispatcher service.
-   *
-   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
-   */
-  protected $eventDispatcher;
-
-  /**
-   * The actual path from which to perform imports.
-   *
-   * Derived from @app_root and %rdcm.reinstall_path%.
-   *
-   * @var string
-   */
-  protected $importPath = self::IMPORT_PATH;
-
-  /**
-   * The reinstall logger channel service.
-   *
-   * @var \Psr\Log\LoggerInterface
-   */
-  protected $logger;
-
-  /**
-   * The app.root parameter service.
-   *
-   * @var string
-   */
-  protected $root;
-
-  /**
-   * The serializer service.
-   *
-   * @var \Symfony\Component\Serializer\Serializer
-   */
-  protected $serializer;
-
-  /**
-   * Dumper constructor.
-   *
-   * @param \Drupal\Core\Session\AccountSwitcherInterface $accountSwitcher
-   *   The account_switcher service.
-   * @param \Drupal\Core\Entity\EntityTypeBundleInfo $bundleInfo
-   *   The entity_type.bundle_info service.
-   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
-   *   The entity_type.manager service.
-   * @param string $root
-   *   The value of the app.root "parameter service".
-   * @param \Symfony\Component\Serializer\Serializer $serializer
-   *   The serializer service.
-   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
-   *   The event_dispatcher service.
-   * @param string $path
-   *   The import path.
-   * @param \Psr\Log\LoggerInterface $logger
-   *   The reinstall logger channel service.
-   */
-  public function __construct(
-    AccountSwitcherInterface $accountSwitcher,
-    EntityTypeBundleInfo $bundleInfo,
-    EntityTypeManagerInterface $entityTypeManager,
-    string $root,
-    Serializer $serializer,
-    EventDispatcherInterface $eventDispatcher,
-    string $path,
-    LoggerInterface $logger
-    ) {
-    $this->accountSwitcher = $accountSwitcher;
-    $this->entityTypeBundleInfo = $bundleInfo;
-    $this->entityTypeManager = $entityTypeManager;
-    $this->logger = $logger;
-    $this->root = $root;
-    $this->serializer = $serializer;
-    $this->eventDispatcher = $eventDispatcher;
-
-    $this->setPath($path);
-  }
-
-  /**
-   * Gets a hash of the content entity definitions on the site.
-   *
-   * @param string $requestedTypeName
-   *   If specified, the types hash will only contain the key for that type.
-   *
-   * @return array
-   *   A machine-name-indexed hash of entity type definitions. If $typeName was
-   *   not specified, the definitions are returned for all entity types.
-   */
-  public function contentEntityTypes(string $requestedTypeName = NULL) {
-    $definitions = $this->entityTypeManager->getDefinitions();
-    $entityTypes = [];
-    foreach ($definitions as $machine => $type) {
-      $class = $type->getClass();
-      $implements = class_implements($class);
-      if (isset($implements[static::CONTENT_INTERFACE])) {
-        $entityTypes[$machine] = $type;
-      }
-    }
-
-    if (!empty($requestedTypeName)) {
-      $entityTypes = [$requestedTypeName => $entityTypes[$requestedTypeName]];
-    }
-
-    return $entityTypes;
-  }
-
-  /**
-   * Dump the entities in the selected bundle of the entity type.
-   *
-   * @param string $typeName
-   *   The name of the entity type from which to dump a bundle.
-   * @param \Drupal\Core\Entity\EntityTypeInterface $entityType
-   *   The entity type instance.
-   * @param string $bundle
-   *   The name of the bundle to dump. Assumed to be valid.
-   *
-   * @see \Drupal\reinstall\Dumper::validateBundles()
-   */
-  protected function dumpEntitiesBundle($typeName, EntityTypeInterface $entityType, string $bundle) {
-    $t0 = microtime(TRUE);
-    $storage = $this->entityTypeManager->getStorage($typeName);
-    $bundleKey = $this->entityTypeManager->getDefinition($typeName)->getKey('bundle');
-    $countQuery = $storage->getQuery();
-    if ($bundleKey) {
-      $countQuery = $countQuery->condition($bundleKey, $bundle);
-    }
-    $count = $countQuery
-      ->count()
-      ->execute();
-
-    $query = $storage->getQuery();
-    if ($bundleKey) {
-      $query = $query->condition($bundleKey, $bundle);
-    }
-    $ids = $query->execute();
-    $chunks = array_chunk($ids, static::BATCH_SIZE);
-
-    $path = $this->prepareDestination($typeName, $bundle);
-    $fp = fopen($path, "w");
-
-    foreach ($chunks as $chunk) {
-      $this->dumpEntitiesChunk($fp, $typeName, $bundle, $storage, $chunk);
-    }
-
-    // Ensure files always contain at least an empty array.
-    if (empty($chunks)) {
-      fwrite($fp, '{  }');
-    }
-
-    fclose($fp);
-    $t1 = microtime(TRUE);
-
-    $this->logger->info('Dumped @count entities for @type/@bundle in @sec seconds.', [
-      '@count' => $count,
-      '@type' => $typeName,
-      '@bundle' => $bundle,
-      '@sec' => sprintf('%.1f', $t1 - $t0),
-    ]);
-
-  }
-
-  /**
-   * Dump a chunk of entities from a common bundle in an existing opened file.
-   *
-   * @param resource $fp
-   *   A file pointer to which to write.
-   * @param string $typeName
-   *   The name of the entity type from which to dump a chunk of entities.
-   * @param string $bundle
-   *   The bundle name.
-   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
-   *   The entity storage for the entity type.
-   * @param array $chunk
-   *   An array of entities to dump.
-   */
-  protected function dumpEntitiesChunk(
-    $fp,
-    string $typeName,
-    string $bundle,
-    EntityStorageInterface $storage,
-    array $chunk
-  ) {
-    $entities = $storage->loadMultiple($chunk);
-
-    // Allow adding data to entities before exporting, like term parents.
-    $eventPre = new DumperEvent($storage, $bundle, $entities);
-    $this->eventDispatcher->dispatch(ReinstallEvents::PRE_DUMP, $eventPre);
-
-    $this->dumpEntities($fp, $typeName, $bundle, $entities);
-
-    // Allow extra work after exporting, like copying files.
-    $eventPost = new DumperEvent($storage, $bundle, $entities);
-    $this->eventDispatcher->dispatch(ReinstallEvents::POST_DUMP, $eventPost);
-  }
-
-  /**
-   * Load entities for a given entity bundle.
-   *
-   * @param \Drupal\Core\Entity\ContentEntityTypeInterface $type
-   *   The entity type object.
-   * @param \Drupal\Core\Entity\ContentEntityStorageInterface $storage
-   *   The entity storage for the entity type.
-   *
-   * @return array
-   *   A hash of entities by id.
-   */
-  protected function loadMultiBundleEntities(ContentEntityTypeInterface $type,
-    ContentEntityStorageInterface $storage
-  ) {
-    $bundleNames = array_keys($this->entityTypeBundleInfo->getBundleInfo($type->id()));
-    $key = $type->getKey('bundle');
-
-    $entities = [];
-    foreach ($bundleNames as $bundleName) {
-      $bundleEntities = $storage->loadByProperties([$key => $bundleName]);
-      $entities[$bundleName] = $bundleEntities;
-    }
-
-    return $entities;
-  }
-
-  /**
-   * Dump entities to YAML files.
-   *
-   * @param string $typeName
-   *   The name of the entity type for which to export entities.
-   * @param array $bundles
-   *   Optional. An array of bundles to export. Only used if an entity type is
-   *   specified, since $requestedTypeName is itself optional.
-   *
-   * @see https://www.drupal.org/node/218104
-   */
-  public function dump($typeName, array $bundles = []) {
-    $this->accountSwitcher->switchTo(new UserSession(['uid' => 1]));
-
-    $entityType = current($this->contentEntityTypes($typeName));
-    $validBundles = $this->validateBundles($typeName, $bundles);
-
-    foreach ($validBundles as $bundle) {
-      $this->dumpEntitiesBundle($typeName, $entityType, $bundle);
-    }
-
-    $this->accountSwitcher->switchBack();
-  }
-
-  /**
-   * Generate import YAML for entities.
-   *
-   * @param resource $fp
-   *   The file into which to write.
-   * @param string $entityTypeName
-   *   The entity type.
-   * @param string $bundleName
-   *   The bundle name.
-   * @param array $entities
-   *   The entities.
-   */
-  public function dumpEntities($fp, string $entityTypeName, string $bundleName, array $entities) {
-    $array = $this->toArray($entities);
-    fwrite($fp, Yaml::dump($array, static::INLINE_DEPTH, 2));
-    fflush($fp);
-  }
-
-  /**
-   * Prepare the dump destination directory and return the file name within it.
-   *
-   * @param string $entityTypeName
-   *   The type of the entities to dump.
-   * @param string $bundleName
-   *   The bundle of the entities to dump.
-   *
-   * @return string
-   *   The path of the dump file.
-   */
-  protected function prepareDestination(string $entityTypeName, string $bundleName): string {
-    $importPath = $this->importPath;
-    $dir = "$importPath/$entityTypeName";
-    if (!file_exists($dir)) {
-      mkdir($dir, 0777, TRUE);
-    }
-
-    $path = "${dir}/${bundleName}.yml";
-    return $path;
-  }
-
-  /**
-   * Store the absolute path to the import directory.
-   *
-   * @param string $path
-   *
-   *   The Drupal-root-relative import path.
-   *
-   * @throws \InvalidArgumentException
-   *   If the directory does not exist.
-   */
-  public function setPath(string $path) {
-    $completePath = $this->root . '/' . $path;
-    $real = realpath($completePath);
-    if (!is_dir($real)) {
-      drupal_set_message("Non-existent base dump directory: $completePath.", "error");
-      throw new \InvalidArgumentException("Non-existent base dump directory: $completePath.");
-    }
-
-    $this->importPath = $real;
-  }
-
-  /**
-   * Like NormalizerInterface::normalize(), but for an array.
-   *
-   * @param array $entities
-   *   The entities to convert to arrays.
-   *
-   * @return mixed
-   *   The array representing the entities.
-   */
-  protected function toArray(array $entities): array {
-    $json_options = [];
-    $json = $this->serializer->serialize($entities, 'json', $json_options);
-    $hash = json_decode($json, TRUE);
-
-    return $hash;
-  }
-
-  /**
-   * Deduplicate the bundles list and remove invalid bundle names.
-   *
-   * @param string $entityTypeName
-   *   The name of the entity type for which to validate bundle names.
-   * @param array $bundles
-   *   Bundle names to be validated.
-   *
-   * @return array
-   *   Valid bundles to dump.
-   */
-  protected function validateBundles(string $entityTypeName, array $bundles) {
-    sort($bundles);
-    $bundleInfo = $this->entityTypeBundleInfo->getBundleInfo($entityTypeName);
-
-    // Note: array_flip will ensure requested bundles are only asked once.
-    $flippedBundles = array_flip($bundles);
-
-    $validFlippedBundles = array_intersect_key($flippedBundles, $bundleInfo);
-    $uniqueValidBundles = array_flip($validFlippedBundles);
-
-    sort($uniqueValidBundles);
-    if ($bundles !== $uniqueValidBundles) {
-      throw new \InvalidArgumentException(
-          "\nRequested bundles: " . implode(', ', $bundles)
-        . "\nValid bundles: " . implode(', ', $uniqueValidBundles) . "\n");
-    }
-
-    if (empty($uniqueValidBundles)) {
-      $uniqueValidBundles = array_keys($bundleInfo);
-    }
-
-    return $uniqueValidBundles;
-  }
-
-}

+ 0 - 53
src/DumperEvent.php

@@ -1,53 +0,0 @@
-<?php
-
-namespace Drupal\reinstall;
-
-use Drupal\Core\Entity\EntityStorageInterface;
-use Symfony\Component\EventDispatcher\Event;
-
-/**
- * Wraps a dump event for event listeners.
- *
- * @see \Drupal\reinstall\ReinstallEvents::REINSTALL_SERIALIZE_POST
- * @see \Drupal\reinstall\ReinstallEvents::SERIALIZE_PRE
- */
-class DumperEvent extends Event {
-
-  /**
-   * The name of the bundle for which a dump is being performed.
-   *
-   * @var string
-   */
-  public $bundleName;
-
-  /**
-   * The entities to dump.
-   *
-   * @var \Drupal\Core\Entity\EntityInterface[]
-   */
-  public $entities = [];
-
-  /**
-   * The storage handler for the entity type of the entities to dump.
-   *
-   * @var \Drupal\Core\Entity\EntityStorageInterface
-   */
-  public $storage;
-
-  /**
-   * DumperEvent constructor.
-   *
-   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
-   *   The entity storage.
-   * @param string $bundleName
-   *   The name of the bundle being dumped.
-   * @param array $entities
-   *   The entities to dump.
-   */
-  public function __construct(EntityStorageInterface $storage, string $bundleName, array $entities) {
-    $this->storage = $storage;
-    $this->bundleName = $bundleName;
-    $this->entities = $entities;
-  }
-
-}

+ 0 - 144
src/EventSubscriber/FilePostDump.php

@@ -1,144 +0,0 @@
-<?php
-
-namespace Drupal\reinstall\EventSubscriber;
-
-use Drupal\Component\Utility\Unicode;
-use Drupal\Core\File\FileSystem;
-use Drupal\Core\File\FileSystemInterface;
-use Drupal\file\Entity\File;
-use Drupal\reinstall\DumperEvent;
-use Drupal\reinstall\ReinstallEvents;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-/**
- * Class FilePostDump performs physical file copy on file dump.
- */
-class FilePostDump implements EventSubscriberInterface {
-
-  /**
-   * The file_system service.
-   *
-   * @var \Drupal\Core\File\FileSystemInterface
-   */
-  protected $fileSystem;
-
-  /**
-   * The export/import path.
-   *
-   * @var string
-   */
-  protected $importPath;
-
-  /**
-   * FilePostDump constructor.
-   *
-   * @param \Drupal\Core\File\FileSystemInterface $fileSystem
-   *   The file_system service.
-   * @param string $importPath
-   *   The reinstall.path parameter.
-   */
-  public function __construct(FileSystemInterface $fileSystem, string $importPath) {
-    $this->fileSystem = $fileSystem;
-    $this->importPath = $importPath;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function getSubscribedEvents() {
-    return [
-      ReinstallEvents::POST_DUMP => 'onDumpPost',
-    ];
-  }
-
-  /**
-   * Callback for POST_DUMP event.
-   *
-   * @param \Drupal\reinstall\DumperEvent $event
-   *   The post-dump event.
-   */
-  public function onDumpPost(DumperEvent $event) {
-    if ($event->storage->getEntityTypeId() !== 'file') {
-      return;
-    }
-
-    $this->dumpFiles($event->bundleName, $event->entities);
-  }
-
-  /**
-   * Dump the actual files for a file entity bundle.
-   *
-   * @param string $bundleName
-   *   The bundle name.
-   * @param array $files
-   *   The file URLs.
-   */
-  public function dumpFiles(string $bundleName, array $files) {
-    $importPath = $this->importPath;
-    $dir = "$importPath/$bundleName";
-    $usedNamespaces = array_keys(array_reduce($files, [__CLASS__, 'namespacesReducer'], []));
-    $lists = [];
-
-    foreach ($usedNamespaces as $ns) {
-      // XXX Consider using \0 to support xargs: file names MAY contain spaces.
-      $path = "$dir/$ns.list.txt";
-
-      $nsDir = "$dir/$ns";
-      if (!is_dir($nsDir)) {
-        echo "Creating $nsDir\n";
-        mkdir($nsDir, 0777, TRUE);
-      }
-
-      // fopen() is in text mode by default.
-      $lists[$ns] = [
-        'dir' => $nsDir,
-        'handle' => fopen($path, 'w'),
-      ];
-    }
-
-    /** @var \Drupal\file\Entity\File $file */
-    foreach ($files as $file) {
-      $uri = $file->getFileUri();
-      $target = file_uri_target($uri);
-      $ns = $this->fileSystem->uriScheme($uri);
-      fwrite($lists[$ns]['handle'], $target . "\n");
-      $dest = $lists[$ns]['dir'] . '/' . $target;
-
-      $dir = dirname($dest);
-      if (!is_dir($dir)) {
-        mkdir($dir, 0777, TRUE);
-      }
-      file_unmanaged_copy($uri, $dest, FILE_EXISTS_REPLACE);
-    }
-
-    foreach ($lists as $list) {
-      fclose($list['handle']);
-    }
-  }
-
-  /**
-   * An array_reduce() callback to collect namespaces from file entities.
-   *
-   * @param string[] $accu
-   *   The namespaces accumulator.
-   * @param \Drupal\file\Entity\File $fileItem
-   *   A file description.
-   *
-   * @return string[]
-   *   An array of namespaces used on the site.
-   *
-   * @see \Drupal\reinstall\Dumper::dumpFiles()
-   */
-  protected static function namespacesReducer(array $accu, File $fileItem) {
-    $uri = $fileItem->getFileUri();
-    // Plain filenames without a namespace. Should not happen, but...
-    if (FALSE === ($len = Unicode::strpos($uri, '://'))) {
-      return $accu;
-    };
-
-    $namespace = Unicode::substr($uri, 0, $len);
-    $accu[$namespace] = TRUE;
-    return $accu;
-  }
-
-}

+ 0 - 57
src/EventSubscriber/TermPreDump.php

@@ -1,57 +0,0 @@
-<?php
-
-namespace Drupal\reinstall\EventSubscriber;
-
-use Drupal\reinstall\DumperEvent;
-use Drupal\reinstall\ReinstallEvents;
-use Drupal\taxonomy\TermInterface;
-use Drupal\taxonomy\TermStorageInterface;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-/**
- * Class TermPreDump adds the parents target_id values on a term.
- */
-class TermPreDump implements EventSubscriberInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function getSubscribedEvents() {
-    return [
-      ReinstallEvents::PRE_DUMP => 'onDumpPre',
-    ];
-  }
-
-  /**
-   * Set the parents on the term.
-   *
-   * @param \Drupal\taxonomy\TermInterface $term
-   *   The term to complete.
-   * @param int $tid
-   *   The term id.
-   * @param \Drupal\taxonomy\TermStorageInterface $storage
-   *   The term storage.
-   */
-  protected static function setParents(TermInterface $term, $tid, TermStorageInterface $storage) {
-    $parents = $storage->loadParents($term->id());
-    if (!empty($parents)) {
-      $term->set('parent', array_keys($parents));
-    }
-  }
-
-  /**
-   * Callback for PRE_DUMP event.
-   *
-   * @param \Drupal\reinstall\DumperEvent $event
-   *   The pre-dump event.
-   */
-  public static function onDumpPre(DumperEvent $event) {
-    $storage = $event->storage;
-    if ($storage->getEntityTypeId() !== 'taxonomy_term') {
-      return;
-    }
-
-    array_walk($event->entities, [__CLASS__, 'setParents'], $storage);
-  }
-
-}

+ 0 - 52
src/EventSubscriber/UserPreImport.php

@@ -1,52 +0,0 @@
-<?php
-
-namespace Drupal\reinstall\EventSubscriber;
-
-use Drupal\reinstall\ReinstallEvents;
-use Drupal\reinstall\SourceEvent;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-/**
- * Class UserPreImport is an EventSubscriber filtering user sources.
- */
-class UserPreImport implements EventSubscriberInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function getSubscribedEvents() {
-    return [
-      ReinstallEvents::POST_SOURCE_PARSE => 'onPreImport',
-    ];
-  }
-
-  /**
-   * Event callback for POST_SOURCE_PARSE.
-   *
-   * @param \Drupal\reinstall\SourceEvent $event
-   *   The event.
-   */
-  public function onPreImport(SourceEvent $event) {
-    $source = $event->source;
-    if ($source->getConfiguration()['type'] !== 'user') {
-      return;
-    }
-
-    $event->source->records = array_filter($event->source->records, [$this, 'filter01']);
-  }
-
-  /**
-   * Skip users 0 and 1 in imports, as they are core-provided.
-   *
-   * @param array $record
-   *   The description of a user entity.
-   *
-   * @return bool
-   *   Include it (1) or filter it (0).
-   */
-  public function filter01(array $record) {
-    $ret = ($record['uid'] ?? 0) > 1;
-    return $ret;
-  }
-
-}

+ 0 - 40
src/Plugin/migrate/process/TermParent.php

@@ -1,40 +0,0 @@
-<?php
-
-namespace Drupal\reinstall\Plugin\migrate\process;
-
-use Drupal\migrate\MigrateExecutableInterface;
-use Drupal\migrate\ProcessPluginBase;
-use Drupal\migrate\Row;
-
-/**
- * Class TermParent works in conjunction with ReinstallTermSource.
- *
- * With the latter using the heavy-handed SimpleSource::flattenRow() method,
- * the parents obtained when migrating hierarchical vocabularies can be wrong,
- * especially with terms having multiple parents (i.e. non-tree graphs), and
- * this method allows the migration to obtain proper parent target_id values.
- *
- * @MigrateProcessPlugin(
- *   id = "reinstall_term_parents"
- * )
- */
-class TermParent extends ProcessPluginBase {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function transform(
-    $value,
-    MigrateExecutableInterface $migrate_executable,
-    Row $row,
-    $destination_property
-  ) {
-    if (is_scalar($value)) {
-      return $value;
-    }
-    elseif (isset($value['target_id'])) {
-      return $value['target_id'];
-    }
-  }
-
-}

+ 0 - 271
src/Plugin/migrate/source/ReinstallSourceBase.php

@@ -1,271 +0,0 @@
-<?php
-
-namespace Drupal\reinstall\Plugin\migrate\source;
-
-use Drupal\Component\Plugin\ConfigurablePluginInterface;
-use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
-use Drupal\migrate\MigrateException;
-use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
-use Drupal\migrate\Plugin\MigrationInterface;
-use Drupal\migrate\Row;
-use Drupal\reinstall\ReinstallEvents;
-use Drupal\reinstall\SourceEvent;
-use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\Yaml\Exception\ParseException;
-use Symfony\Component\Yaml\Yaml;
-
-/**
- * Class SimpleSource provides the basic mechanisms to load a YML entity dump.
- *
- * @MigrateSource(
- *   id = "reinstall_base"
- * )
- */
-class ReinstallSourceBase extends SourcePluginBase implements ContainerFactoryPluginInterface, ConfigurablePluginInterface {
-  use SimpleSourceTrait;
-
-  /**
-   * The event_dispatcher service.
-   *
-   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
-   */
-  protected $eventDispatcher;
-
-  /**
-   * The source records.
-   *
-   * MAY be altered by subscribing to MigrateEvents::PRE_IMPORT.
-   *
-   * @var array
-   */
-  public $records;
-
-  /**
-   * ReinstallSourceBase constructor.
-   *
-   * @param array $configuration
-   *   The plugin configuration.
-   * @param string $plugin_id
-   *   The plugin id.
-   * @param mixed $plugin_definition
-   *   The plugin definition.
-   * @param \Drupal\migrate\Plugin\MigrationInterface $migration
-   *   The migration on which the plugin is invoked.
-   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
-   *   The event_dispatcher service.
-   */
-  public function __construct(
-    array $configuration,
-    $plugin_id,
-    $plugin_definition,
-    MigrationInterface $migration,
-    EventDispatcherInterface $eventDispatcher
-  ) {
-    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
-    $this->eventDispatcher = $eventDispatcher;
-    $this->records = array_map([$this, 'flattenRecord'], $this->initialParse($configuration));
-    $eventDispatcher->dispatch(ReinstallEvents::POST_SOURCE_PARSE, new SourceEvent($this));
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function create(
-    ContainerInterface $container,
-    array $configuration,
-    $pluginId,
-    $pluginDefinition,
-    MigrationInterface $migration = NULL
-  ) {
-    $importPath = $container->getParameter('reinstall.path');
-    $configuration['importPath'] = $importPath;
-    $dispatcher = $container->get('event_dispatcher');
-    return new static($configuration, $pluginId, $pluginDefinition, $migration, $dispatcher);
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function doCount() {
-    return count($this->records);
-  }
-
-  /**
-   * Flatten the field hierarchy. Not correct for all cases.
-   *
-   * @param array $record
-   *   The raw source values.
-   *
-   * @return array
-   *   The flattened values.
-   *
-   * @see \Drupal\reinstall\Plugin\migrate\process\TermParent
-   */
-  protected function flattenRecord(array $record) {
-    $row = new Row($record);
-    $this->flattenRow($row);
-    return $row->getSource();
-  }
-
-  /**
-   * Flatten a typical Drupal 8 field array to a 1-level array.
-   */
-  protected function flattenRow(Row $row) {
-    $source = $row->getSource();
-    foreach ($source as $key => &$item_list) {
-      if (is_scalar($item_list)) {
-        continue;
-      }
-      if (count($item_list) > 1) {
-        $item = $item_list;
-      }
-      else {
-        $item = reset($item_list);
-      }
-
-      // Handle bundle['target_id']
-      // Exclude image field to keep metadata (alt / title)
-      if (isset($item['target_id']) && !isset($item['alt']) && !isset($item['title'])) {
-        $value = $item['target_id'];
-      }
-      elseif (is_scalar($item) || (count($item) != 1 && !isset($item['width']) && !isset($item['pid']))) {
-        $value = $item;
-      }
-      elseif (isset($item['value'])) {
-        $value = $item['value'];
-      }
-      elseif (isset($item['pid'])) {
-        $value = $item['alias'];
-      }
-      else {
-        $value = $item;
-      }
-
-      if (empty($item)) {
-        $value = NULL;
-      }
-      $row->setSourceProperty($key, $value);
-    }
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function initializeIterator() {
-    if (!isset($this->iterator)) {
-      $this->iterator = new \ArrayIterator($this->records);
-    }
-    return $this->iterator;
-  }
-
-  /**
-   * Load then parse the file requested in configuration and return its records.
-   *
-   * @param array $configuration
-   *   The source configuration from the migration source section.
-   * @param string $key
-   *   Optional. A top-level key for the source document. If empty, items will
-   *   be parsed from the root of the source document.
-   *
-   * @return array
-   *   An array of entity descriptions.
-   *
-   * @throws \Drupal\migrate\MigrateException
-   */
-  protected function initialParse(array $configuration, string $key = NULL) {
-    $this->sstEntityType = $type = $configuration['type'];
-    $bundle = $configuration['bundle'];
-
-    $baseFilePath = $this->configuration['file'] ?? "${type}/${bundle}.yml";
-
-    $importPath = $configuration['importPath'] ?? NULL;
-    $filePath = "$importPath/$baseFilePath";
-    $realPath = realpath($filePath);
-    if (!is_file($realPath) || !is_readable($realPath)) {
-      throw new MigrateException("${filePath} is not a readable file.");
-    }
-
-    try {
-      $raw = file_get_contents($filePath);
-      $data = Yaml::parse($raw);
-    }
-    catch (ParseException $e) {
-      throw new MigrateException("Cannot parse the contents of ${filePath}.");
-    }
-
-    if ($key) {
-      return $data[$key] ?? [];
-    }
-
-    return $data ?? [];
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function __toString() {
-    $current = $this->getIterator()->current();
-    $ret = json_encode($current, JSON_PRETTY_PRINT);
-    return $ret;
-  }
-
-  /**
-   * Gets this plugin's configuration.
-   *
-   * @return array
-   *   An array of this plugin's configuration.
-   */
-  public function getConfiguration() {
-    return $this->configuration;
-  }
-
-  /**
-   * Sets the configuration for this plugin instance.
-   *
-   * @param array $configuration
-   *   An associative array containing the plugin's configuration.
-   */
-  public function setConfiguration(array $configuration) {
-    $this->configuration = $configuration;
-  }
-
-  /**
-   * Gets default configuration for this plugin.
-   *
-   * @return array
-   *   An associative array with the default configuration.
-   */
-  public function defaultConfiguration() {
-    return [];
-  }
-
-  /**
-   * Calculates dependencies for the configured plugin.
-   *
-   * Dependencies are saved in the plugin's configuration entity and are used to
-   * determine configuration synchronization order. For example, if the plugin
-   * integrates with specific user roles, this method should return an array of
-   * dependencies listing the specified roles.
-   *
-   * @return array
-   *   An array of dependencies grouped by type (config, content, module,
-   *   theme). For example:
-   *
-   * @code
-   *   array(
-   *     'config' => array('user.role.anonymous', 'user.role.authenticated'),
-   *     'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'),
-   *     'module' => array('node', 'user'),
-   *     'theme' => array('seven'),
-   *   );
-   * @endcode
-   *
-   * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
-   * @see \Drupal\Core\Entity\EntityInterface::getConfigDependencyName()
-   */
-  public function calculateDependencies() {
-    return [];
-  }
-
-}

+ 0 - 155
src/Plugin/migrate/source/SimpleSourceTrait.php

@@ -1,155 +0,0 @@
-<?php
-
-namespace Drupal\reinstall\Plugin\migrate\source;
-
-/**
- * Class SimpleSourceTrait provides shared features for entity field handling.
- */
-trait SimpleSourceTrait {
-
-  /**
-   * The entity_type.bundle.info service.
-   *
-   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
-   */
-  protected $sstEntityTypeBundleInfo;
-
-  /**
-   * The entity_field.manager service.
-   *
-   * @var \Drupal\Core\Entity\EntityFieldManagerInterface
-   */
-  protected $sstEntityFieldManager;
-
-  /**
-   * The name of the entity type being handled.
-   *
-   * @var string
-   */
-  protected $sstEntityType;
-
-  /**
-   * The entity_type.manager service.
-   *
-   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
-   */
-  protected $sstEntityTypeManager;
-
-  /**
-   * {@inheritdoc}
-   */
-  public function fields() {
-    $bundles = $this->getEntityTypeBundleInfo()
-      ->getBundleInfo($typeName = $this->getEntityType());
-    $rows = [];
-
-    foreach ($bundles as $bundleName => $bundle) {
-      $fieldDefinitions = $this->getEntityFieldManager()
-        ->getFieldDefinitions($typeName, $bundleName);
-      foreach ($fieldDefinitions as $fieldName => $fieldDefinition) {
-        $rows[$fieldName][$bundleName] = $fieldDefinition->getLabel();
-      }
-    }
-
-    $fields = [];
-    $singleBundle = count($bundles) === 1;
-    foreach ($rows as $fieldName => $labels) {
-      if ($singleBundle) {
-        $fields[$fieldName] = reset($labels);
-        continue;
-      }
-
-      if (count(array_unique($labels)) === 1) {
-        $fields[$fieldName] = reset($labels);
-        continue;
-      }
-
-      $ret = [];
-      ksort($labels);
-      foreach ($labels as $ct => $label) {
-        $ret[] = $this->t('@ct: @label', ['@ct' => $ct, '@label' => $label]);
-      }
-      $fields[$fieldName] = implode(', ', $ret);
-    }
-
-    ksort($fields);
-    return $fields;
-  }
-
-  /**
-   * Getter for the entity_type.bundle.info service.
-   *
-   * @return \Drupal\Core\Entity\EntityTypeBundleInfoInterface
-   *   The service.
-   */
-  protected function getEntityTypeBundleInfo() {
-    if (!isset($this->sstEntityTypeBundleInfo)) {
-      $this->sstEntityTypeBundleInfo = \Drupal::service('entity_type.bundle.info');
-    }
-
-    return $this->sstEntityTypeBundleInfo;
-  }
-
-  /**
-   * Getter for the entity_field.manager service.
-   *
-   * @return \Drupal\Core\Entity\EntityFieldManagerInterface|mixed
-   *   The service.
-   */
-  protected function getEntityFieldManager() {
-    if (!isset($this->sstEntityFieldManager)) {
-      $this->sstEntityFieldManager = \Drupal::service('entity_field.manager');
-    }
-
-    return $this->sstEntityFieldManager;
-  }
-
-  /**
-   * Getter for the current entity type.
-   *
-   * @return string
-   *   The machine name of the type.
-   */
-  protected function getEntityType() {
-    assert(isset($this->sstEntityType));
-    return $this->sstEntityType;
-  }
-
-  /**
-   * Getter for the entity_type.manager service.
-   *
-   * @return \Drupal\Core\Entity\EntityTypeManagerInterface|mixed
-   *   The service.
-   */
-  protected function getEntityTypeManager() {
-    if (!isset($this->sstEntityTypeManager)) {
-      $this->sstEntityTypeManager = \Drupal::service('entity_type.manager');
-    }
-
-    return $this->sstEntityTypeManager;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getIds() {
-    $typeName = $this->getEntityType();
-
-    $typeDefinition = $this->getEntityTypeManager()->getDefinition($typeName);
-    $idName = $typeDefinition->getKey('id');
-    assert(!empty($idName));
-
-    $definitions = $this->getEntityFieldManager()->getBaseFieldDefinitions($typeName);
-    assert(isset($definitions[$idName]));
-    $idDefinition = $definitions[$idName];
-    $idType = $idDefinition->getType();
-    $ids = [
-      $idName => [
-        'type' => $idType,
-      ],
-    ];
-
-    return $ids;
-  }
-
-}

+ 0 - 55
src/ReinstallEvents.php

@@ -1,55 +0,0 @@
-<?php
-
-namespace Drupal\reinstall;
-
-/**
- * Defines events for the Dumper system.
- *
- * @see \Drupal\reinstall\Dumper
- */
-final class ReinstallEvents {
-
-  /**
-   * Name of the event fired when entities have been dumped.
-   *
-   * This event allows modules to perform an action whenever content entities
-   * of a given entity type bundle are exported, usually to perform extra
-   * operations, like:
-   * - copying/moving the actual files on file export.
-   *
-   * The event listener method receives a \Drupal\reinstall\SerializeEvent
-   * instance, carrying an array of all entites indexed by $entity->id().
-   *
-   * Note that this assumes entity types with an ID, which is not stricly
-   * required by the Entity API, but common enough for most needs.
-   *
-   * @Event
-   *
-   * @var string
-   */
-  const POST_DUMP = 'reinstall.dump.post';
-
-  /**
-   * Name of the event fired when readying entities for dump.
-   *
-   * This event allows modules to perform an action whenever content entities
-   * of a given entity type bundle are exported, usually to add data to the
-   * export, like:
-   * - parent on taxonomy_term.
-   * - path on any entity with a canonical path.
-   *
-   * The event listener method receives a \Drupal\reinstall\DumperEvent
-   * instance, carrying an array of all entites indexed by $entity->id().
-   *
-   * Note that this assumes entity types with an ID, which is not stricly
-   * required by the Entity API, but common enough for most needs.
-   *
-   * @Event
-   *
-   * @var string
-   */
-  const PRE_DUMP = 'reinstall.dump.pre';
-
-  const POST_SOURCE_PARSE = 'reinstall.source_parse.post';
-
-}

+ 0 - 32
src/SourceEvent.php

@@ -1,32 +0,0 @@
-<?php
-
-namespace Drupal\reinstall;
-
-use Drupal\reinstall\Plugin\migrate\source\ReinstallSourceBase;
-use Symfony\Component\EventDispatcher\Event;
-
-/**
- * And event being triggered during dumps.
- *
- * @see \Drupal\reinstall\ReinstallEvents::POST_SOURCE_PARSE
- */
-class SourceEvent extends Event {
-
-  /**
-   * The source for the migration.
-   *
-   * @var \Drupal\migrate\Plugin\MigrateSourceInterface
-   */
-  public $source;
-
-  /**
-   * DumperEvent constructor.
-   *
-   * @param \Drupal\reinstall\Plugin\migrate\source\ReinstallSourceBase $source
-   *   The data source.
-   */
-  public function __construct(ReinstallSourceBase $source) {
-    $this->source = $source;
-  }
-
-}