Verified Commit 166f3a39 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3439369 by fromme, quietone, pradhumanjain2311, smustgrave, alexpott:...

Issue #3439369 by fromme, quietone, pradhumanjain2311, smustgrave, alexpott: Remove deprecated code in migration system
parent 7f4b5f18
Loading
Loading
Loading
Loading
Loading
+6 −60
Original line number Diff line number Diff line
@@ -194,18 +194,6 @@ class Migration extends PluginBase implements MigrationInterface, RequirementsIn
   */
  protected $sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED;

  /**
   * Track time of last import if TRUE.
   *
   * @var bool
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   * replacement.
   *
   * @see https://www.drupal.org/node/3282894
   */
  protected $trackLastImported = FALSE;

  /**
   * These migrations must be already executed before this migration can run.
   *
@@ -334,14 +322,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
      $this->$key = $value;
    }

    if (isset($plugin_definition['trackLastImported'])) {
      @trigger_error("The key 'trackLastImported' is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3282894", E_USER_DEPRECATED);
    }

    $this->migration_dependencies = ($this->migration_dependencies ?: []) + ['required' => [], 'optional' => []];
    if (count($this->migration_dependencies) !== 2 || !is_array($this->migration_dependencies['required']) || !is_array($this->migration_dependencies['optional'])) {
      @trigger_error("Invalid migration dependencies for {$this->id()} is deprecated in drupal:10.1.0 and will cause an error in drupal:11.0.0. See https://www.drupal.org/node/3266691", E_USER_DEPRECATED);
    }
  }

  /**
@@ -607,9 +588,6 @@ public function set($property_name, $value) {
    }
    elseif ($property_name === 'migration_dependencies') {
      $value = ($value ?: []) + ['required' => [], 'optional' => []];
      if (count($value) !== 2 || !is_array($value['required']) || !is_array($value['optional'])) {
        @trigger_error("Invalid migration dependencies for {$this->id()} is deprecated in drupal:10.1.0 and will cause an error in drupal:11.0.0. See https://www.drupal.org/node/3266691", E_USER_DEPRECATED);
      }
    }
    $this->{$property_name} = $value;
    return $this;
@@ -655,47 +633,23 @@ public function mergeProcessOfProperty($property, array $process_of_property) {
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function isTrackLastImported() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3282894', E_USER_DEPRECATED);
    return $this->trackLastImported;
  }

  /**
   * {@inheritdoc}
   */
  public function setTrackLastImported($track_last_imported) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3282894', E_USER_DEPRECATED);
    $this->trackLastImported = (bool) $track_last_imported;
    return $this;
  }

  /**
   * Get the dependencies for this migration.
   *
   * @param bool $expand
   *   Will issue a deprecation in Drupal 10 if set to FALSE. See
   *   https://www.drupal.org/node/3266691.
   *
   * @return array
   *   The dependencies for this migrations.
   *   The dependencies for this migration.
   */
  public function getMigrationDependencies(bool $expand = FALSE) {
    if (!$expand) {
      @trigger_error('Calling Migration::getMigrationDependencies() without expanding the plugin IDs is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. In most cases, use getMigrationDependencies(TRUE). See https://www.drupal.org/node/3266691', E_USER_DEPRECATED);
  public function getMigrationDependencies() {
    if (func_num_args() > 0) {
      @trigger_error('Calling ' . __METHOD__ . ' with the $expand parameter is deprecated in drupal:11.0.0 and is removed drupal:12.0.0. See https://www.drupal.org/node/3442785', E_USER_DEPRECATED);
    }
    // @todo Before Drupal 11.0.0, remove ::set() and these checks.
    // @see https://www.drupal.org/project/drupal/issues/3262395

    $this->migration_dependencies = ($this->migration_dependencies ?: []) + ['required' => [], 'optional' => []];
    if (count($this->migration_dependencies) !== 2 || !is_array($this->migration_dependencies['required']) || !is_array($this->migration_dependencies['optional'])) {
      throw new InvalidPluginDefinitionException($this->id(), "Invalid migration dependencies configuration for migration {$this->id()}");
    }
    $this->migration_dependencies['optional'] = array_unique(array_merge($this->migration_dependencies['optional'], $this->findMigrationDependencies($this->process)));
    if (!$expand) {
      return $this->migration_dependencies;
    }

    return array_map(
      [$this->migrationPluginManager, 'expandPluginIds'],
      $this->migration_dependencies
@@ -762,14 +716,6 @@ public function getSourceConfiguration() {
    return $this->source;
  }

  /**
   * {@inheritdoc}
   */
  public function getTrackLastImported() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3282894', E_USER_DEPRECATED);
    return $this->trackLastImported;
  }

  /**
   * {@inheritdoc}
   */
+0 −41
Original line number Diff line number Diff line
@@ -256,34 +256,6 @@ public function setProcessOfProperty($property, $process_of_property);
   */
  public function mergeProcessOfProperty($property, array $process_of_property);

  /**
   * Checks if the migration should track time of last import.
   *
   * @return bool
   *   TRUE if the migration is tracking last import time.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   * replacement.
   *
   * @see https://www.drupal.org/node/3282894
   */
  public function isTrackLastImported();

  /**
   * Set if the migration should track time of last import.
   *
   * @param bool $track_last_imported
   *   Boolean value to indicate if the migration should track last import time.
   *
   * @return $this
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   * replacement.
   *
   * @see https://www.drupal.org/node/3282894
   */
  public function setTrackLastImported($track_last_imported);

  /**
   * Get the dependencies for this migration.
   *
@@ -308,19 +280,6 @@ public function getDestinationConfiguration();
   */
  public function getSourceConfiguration();

  /**
   * If true, track time of last import.
   *
   * @return bool
   *   Flag to determine desire of tracking time of last import.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   * replacement.
   *
   * @see https://www.drupal.org/node/3282894
   */
  public function getTrackLastImported();

  /**
   * The destination identifiers.
   *
+2 −2
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ public function createInstances($migration_id, array $configuration = []) {
    // @todo Remove loop when the ability to call ::getMigrationDependencies()
    //   without expanding plugins is removed.
    foreach ($instances as $migration) {
      $migration->set('migration_dependencies', $migration->getMigrationDependencies(TRUE));
      $migration->set('migration_dependencies', $migration->getMigrationDependencies());
    }

    // Sort the migrations based on their dependencies.
@@ -169,7 +169,7 @@ public function buildDependencyMigration(array $migrations, array $dynamic_ids)
      $id = $migration->id();
      $requirements[$id] = [];
      $dependency_graph[$id]['edges'] = [];
      $migration_dependencies = $migration->getMigrationDependencies(TRUE);
      $migration_dependencies = $migration->getMigrationDependencies();

      if (isset($migration_dependencies['required'])) {
        foreach ($migration_dependencies['required'] as $dependency) {
+0 −21
Original line number Diff line number Diff line
@@ -187,11 +187,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    $this->mapTableName = mb_substr($this->mapTableName, 0, 63 - $prefix_length);
    $this->messageTableName = 'migrate_message_' . mb_strtolower($machine_name);
    $this->messageTableName = mb_substr($this->messageTableName, 0, 63 - $prefix_length);

    if (!$migration_plugin_manager) {
      @trigger_error('Calling Sql::__construct() without the $migration_manager argument is deprecated in drupal:9.5.0 and the $migration_manager argument will be required in drupal:11.0.0. See https://www.drupal.org/node/3277306', E_USER_DEPRECATED);
      $migration_plugin_manager = \Drupal::service('plugin.manager.migration');
    }
    $this->migrationPluginManager = $migration_plugin_manager;
  }

@@ -1011,22 +1006,6 @@ public function valid(): bool {
    return $this->currentRow !== FALSE;
  }

  /**
   * Returns the migration plugin manager.
   *
   * @return \Drupal\migrate\Plugin\MigrationPluginManagerInterface
   *   The migration plugin manager.
   *
   * @deprecated in drupal:9.5.0 and is removed from drupal:11.0.0. Use
   *   $this->migrationPluginManager instead.
   *
   * @see https://www.drupal.org/node/3277306
   */
  protected function getMigrationPluginManager() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:9.5.0 and is removed from drupal:11.0.0. Use $this->migrationPluginManager instead. See https://www.drupal.org/node/3277306', E_USER_DEPRECATED);
    return $this->migrationPluginManager;
  }

  /**
   * {@inheritdoc}
   */
+1 −19
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ public function testGetMigrationDependencies() {
      ],
    ];
    $migration = $plugin_manager->createStubMigration($plugin_definition);
    $this->assertSame(['required' => [], 'optional' => ['m1', 'm2', 'm3', 'm4', 'm5']], $migration->getMigrationDependencies(TRUE));
    $this->assertSame(['required' => [], 'optional' => ['m1', 'm2', 'm3', 'm4', 'm5']], $migration->getMigrationDependencies());
  }

  /**
@@ -169,24 +169,6 @@ public function testGetDestinationIds() {
    $this->assertEquals(['foo' => 'bar'], $destination_ids, 'Destination ids match the expected values.');
  }

  /**
   * Tests Migration::getTrackLastImported()
   *
   * @covers ::getTrackLastImported
   * @covers ::isTrackLastImported
   *
   * @group legacy
   */
  public function testGetTrackLastImported() {
    $this->expectDeprecation('Drupal\migrate\Plugin\Migration::setTrackLastImported() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3282894');
    $this->expectDeprecation('Drupal\migrate\Plugin\Migration::getTrackLastImported() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3282894');
    $this->expectDeprecation('Drupal\migrate\Plugin\Migration::isTrackLastImported() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3282894');
    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration([]);
    $migration->setTrackLastImported(TRUE);
    $this->assertEquals(TRUE, $migration->getTrackLastImported());
    $this->assertEquals(TRUE, $migration->isTrackLastImported());
  }

  /**
   * Tests Migration::getDestinationPlugin()
   *
Loading