Commit 121440c6 authored by Ravikant Mane's avatar Ravikant Mane Committed by James Gilliland
Browse files

Issue #2977966 by andrewmacpherson, xurizaemon, ravimane23: Upgrade Migrate Manifest to Drush 10

parent b4db1ee2
Loading
Loading
Loading
Loading
+11 −1
Changes for composer.json: 11 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -17,5 +17,15 @@
    "source": "https://cgit.drupalcode.org/migrate_manifest"
  },
  "minimum-stability": "dev",
  "require": {}
  "require": {},
  "conflict": {
    "drush/drush": "<9.7"
  },
  "extra": {
    "drush": {
      "services": {
        "drush.services.yml": "^9"
      }
    }
  }
}
−105

File deleted.

+11 −4
Changes for src/Commands/MigrateManifestCommands.php: 11 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@ namespace Drupal\migrate_manifest\Commands;

use Drupal\migrate_manifest\MigrateManifest;
use Drush\Commands\DrushCommands;
use Drush\Drush;
use Consolidation\SiteAlias\SiteAliasManagerAwareInterface;
use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
use Psr\Log\LoggerInterface;

/**
 * Drush 9 Migrate manifest command.
@@ -15,7 +19,9 @@ use Drush\Commands\DrushCommands;
 *   - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
 *   - http://cgit.drupalcode.org/devel/tree/drush.services.yml
 */
class MigrateManifestCommands extends DrushCommands {
class MigrateManifestCommands extends DrushCommands implements SiteAliasManagerAwareInterface {

  use SiteAliasManagerAwareTrait;

  /**
   * Execute the migrations as specified in a manifest file.
@@ -39,15 +45,16 @@ class MigrateManifestCommands extends DrushCommands {
  ]) {
    try {
      $migration_manager = \Drupal::service('plugin.manager.migration');
      $manifest_runner = new MigrateManifest($migration_manager, $options['force'], $options['update']);
      $manifest_runner = new MigrateManifest($migration_manager, $this->logger(), $options['force'], $options['update']);
      MigrateManifest::setDbState($options['legacy-db-key'], $options['legacy-db-url'], $options['legacy-db-prefix']);
      $manifest_runner->import($manifest);
    }
    catch (\Exception $e) {
      drush_set_error('MIGRATE_ERROR', $e->getMessage());
      $this->logger()->error($e->getMessage());
    }

    drush_invoke_process('@self', 'cache-rebuild', [], [], FALSE);
    $process = Drush::drush($this->siteAliasManager()->getSelf(), 'cache-rebuild');
    $process->mustRun();
  }

  /**
+24 −1
Changes for src/DrushLogMigrateMessage.php: 24 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Drupal\migrate_manifest;

use Drupal\migrate\MigrateMessageInterface;
use Drush\Drush;
use Psr\Log\LoggerInterface;

/**
 * Simple Migrate Message implementation that uses drush to output.
@@ -11,11 +13,32 @@ use Drupal\migrate\MigrateMessageInterface;
 */
class DrushLogMigrateMessage implements MigrateMessageInterface {

  /**
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  public function __construct(LoggerInterface $logger = NULL) {
    if (!isset($logger)) {
      $logger = Drush::logger();
    }
    $this->logger = $logger;
  }

  /**
   * @inheritdoc
   */
  public function display($message, $type = 'status') {
    drush_log($message, $type);
    if (method_exists($this->logger, $type)) {
      $this->logger->$type($message);
    }
    elseif ($type == 'status') {
      $this->logger->info($message);
    }
    else {
      $this->logger->warning('Logger called with unknown type: @type', ['@type' => $type]);
      $this->logger->info($message);
    }
  }

}
+13 −6
Changes for src/MigrateManifest.php: 13 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ namespace Drupal\migrate_manifest;

use Drupal\Core\Database\Database;
use Drupal\migrate\Plugin\MigrationInterface;
use Drush\Drush;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\Yaml\Yaml;

@@ -24,6 +26,11 @@ class MigrateManifest {
   */
  protected $manager;

  /**
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * Constructs a new MigrateManifest object.
   *
@@ -33,10 +40,11 @@ class MigrateManifest {
   * @param bool $update
   *   Update previously imported items with current data.
   */
  public function __construct($migration_manager, $force = FALSE, $update = FALSE) {
  public function __construct($migration_manager, LoggerInterface $logger, $force = FALSE, $update = FALSE) {
    $this->force = $force;
    $this->update = $update;
    $this->manager = $migration_manager;
    $this->logger = $logger;
  }

  /**
@@ -122,9 +130,8 @@ class MigrateManifest {

    // Warn the user if any migrations were not found.
    if (count($nonexistent_migrations) > 0) {
      drush_log(dt('The following migrations were not found: @migrations', [
        '@migrations' => implode(', ', $nonexistent_migrations),
      ]), 'warning');
      $this->logger->warning(dt('The following migrations were not found: @migrations', [
        '@migrations' => implode(',', $nonexistent_migrations)]));
    }

    return $run_migrations;
@@ -180,8 +187,8 @@ class MigrateManifest {
   */
  protected function executeMigration(MigrationInterface $migration) {
    $run_migration = unserialize(serialize($migration));
    drush_log('Running ' . $run_migration->id(), 'ok');
    $executable = new MigrateExecutable($run_migration, new DrushLogMigrateMessage());
    $this->logger->info(dt('Running @id', ['@id' => $run_migration->id()]));
    $executable = new MigrateExecutable($run_migration, new DrushLogMigrateMessage($this->logger));
    // drush_op() provides --simulate support.

    return drush_op([$executable, 'import']);
Loading