Commit ff3c5699 authored by Zoltan Attila Horvath's avatar Zoltan Attila Horvath Committed by Zoltan Attila Horvath
Browse files

Issue #3294768 by huzooka, svendecabooter, codebymikey: MigMagLookup shouldn't...

Issue #3294768 by huzooka, svendecabooter, codebymikey: MigMagLookup shouldn't (implicitly) depend on Migrate Drupal
parent fefc4b6c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
    "require-dev": {
        "drupal/eme": "^1@alpha",
        "drupal/smart_sql_idmap": "^1.1@beta",
        "drupal/tecla": "^1@RC",
        "drush/drush": "^10 || ^11"
    },
    "replace": {
+8 −10
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ namespace Drupal\migmag_process\Plugin\migrate\process;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\migmag\Traits\MigMagMigrationConfigurationTrait;
use Drupal\migmag\Utility\MigMagSourceUtility;
use Drupal\migmag_process\MigMagMigrateStub;
use Drupal\migrate\Exception\RequirementsException;
@@ -18,8 +19,8 @@ use Drupal\migrate\Plugin\migrate\process\MigrationLookup;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\MigrationConfigurationTrait;
use Drupal\migrate_drupal\NodeMigrateType;
use Drupal\migrate_drupal\Plugin\migrate\source\Variable;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
@@ -122,9 +123,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 */
class MigMagLookup extends MigrationLookup {

  use MigrationConfigurationTrait {
    getLegacyDrupalVersion as private;
  }
  use MigMagMigrationConfigurationTrait;

  /**
   * The migrate stub service.
@@ -463,7 +462,7 @@ class MigMagLookup extends MigrationLookup {
    }
    catch (RequirementsException $e) {
    }
    if (!$variable_source_plugin) {
    if (!$variable_source_plugin instanceof Variable) {
      // If the 'variable' source plugin is not available or its requirements
      // are not met, then we can assume that this is not a Drupal to Drupal
      // migration.
@@ -473,11 +472,10 @@ class MigMagLookup extends MigrationLookup {
      ];
    }
    $source_db = $variable_source_plugin->getDatabase();
    $legacy_core_version = static::getLegacyDrupalVersion($source_db);
    // @codingStandardsIgnoreLine
    $node_migration_is_complete = class_exists(NodeMigrateType::class) && is_callable([NodeMigrateType::class, 'getNodeMigrateType'])
      ? NodeMigrateType::getNodeMigrateType($source_db, $legacy_core_version) === NodeMigrateType::NODE_MIGRATE_TYPE_COMPLETE
      : FALSE;
    $legacy_core_version = static::getSourceDrupalVersion($source_db);
    $node_migration_is_complete = class_exists(NodeMigrateType::class)
      && is_callable([NodeMigrateType::class, 'getNodeMigrateType'])
      && NodeMigrateType::getNodeMigrateType($source_db, $legacy_core_version) === NodeMigrateType::NODE_MIGRATE_TYPE_COMPLETE;

    return [
      'legacy_core_version' => $legacy_core_version,
+3 −3
Original line number Diff line number Diff line
@@ -24,13 +24,13 @@ class MigMagLookupTest extends MigrateTestBase {

  /**
   * {@inheritdoc}
   *
   * Access level should be public for Drupal core 8.9.x.
   */
  public static $modules = [
  protected static $modules = [
    'migmag',
    'migmag_lookup_test_migrations',
    'migmag_process',
    'migrate_events_test',
    'tecla',
  ];

  /**
+55 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\migmag\Traits;

use Drupal\Core\Database\Connection;
use Drupal\migrate_drupal\MigrationConfigurationTrait;

if (trait_exists(MigrationConfigurationTrait::class, FALSE)) {
  /**
   * Shim trait for determining source Drupal version.
   */
  trait MigMagMigrationConfigurationTrait {

    use MigrationConfigurationTrait {
      getLegacyDrupalVersion as private;
    }

    /**
     * Determines what version of Drupal the source database contains.
     *
     * @param \Drupal\Core\Database\Connection $connection
     *   The database connection object.
     *
     * @return string|false
     *   A string representing the major branch of Drupal core (e.g. '6' for
     *   Drupal 6.x), or FALSE if no valid version is matched.
     */
    private static function getSourceDrupalVersion(Connection $connection) {
      return static::getLegacyDrupalVersion($connection);
    }

  }
}
else {
  /**
   * Shim trait for determining source Drupal version.
   */
  trait MigMagMigrationConfigurationTrait {

    /**
     * Determines what version of Drupal the source database contains.
     *
     * @param \Drupal\Core\Database\Connection $connection
     *   The database connection object.
     *
     * @return string|false
     *   A string representing the major branch of Drupal core (e.g. '6' for
     *   Drupal 6.x), or FALSE if no valid version is matched.
     */
    private static function getSourceDrupalVersion(Connection $connection) {
      return FALSE;
    }

  }
}