Verified Commit eefe3a87 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3198608 by quietone, swirt, indytechcook, benjifisher, mrinalini9,...

Issue #3198608 by quietone, swirt, indytechcook, benjifisher, mrinalini9, mikelutz, longwave, heddn: trackLastImported YAML key to enable tracking the last import date of a row is undocumented and confusing
parent 22582080
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -216,6 +216,11 @@ class Migration extends PluginBase implements MigrationInterface, RequirementsIn
   * 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;

@@ -359,6 +364,11 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    foreach (NestedArray::mergeDeepArray([$plugin_definition, $configuration], TRUE) as $key => $value) {
      $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);
    }

  }

  /**
@@ -670,6 +680,7 @@ public function mergeProcessOfProperty($property, array $process_of_property) {
   * {@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;
  }

@@ -677,6 +688,7 @@ public function isTrackLastImported() {
   * {@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;
  }
@@ -757,6 +769,7 @@ public function getSourceConfiguration() {
   * {@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;
  }

+15 −0
Original line number Diff line number Diff line
@@ -263,6 +263,11 @@ public function mergeProcessOfProperty($property, array $process_of_property);
   *
   * @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();

@@ -273,6 +278,11 @@ public function isTrackLastImported();
   *   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);

@@ -305,6 +315,11 @@ public function getSourceConfiguration();
   *
   * @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();

+0 −2
Original line number Diff line number Diff line
@@ -699,9 +699,7 @@ public function saveIdMapping(Row $row, array $destination_id_values, $source_ro
      $this->message->display($this->t('Could not save to map table due to missing destination id values'), 'error');
      return;
    }
    if ($this->migration->getTrackLastImported()) {
    $fields['last_imported'] = time();
    }
    $keys = [$this::SOURCE_IDS_HASH => $this->getSourceIdsHash($source_id_values)];
    // Notify anyone listening of the map row we're about to save.
    $this->eventDispatcher->dispatch(new MigrateMapSaveEvent($this, $fields), MigrateEvents::MAP_SAVE);
+5 −0
Original line number Diff line number Diff line
@@ -174,8 +174,13 @@ public function testGetDestinationIds() {
   *
   * @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());
+18 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
namespace Drupal\Tests\migrate\Unit;

use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\migrate\Plugin\MigrateDestinationPluginManager;
use Drupal\migrate\Plugin\MigratePluginManagerInterface;
use Drupal\migrate\Plugin\MigrateSourcePluginManager;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\Migration;
use Drupal\migrate\Exception\RequirementsException;
@@ -195,6 +198,21 @@ public function getValidMigrationDependenciesProvider() {
    ];
  }

  /**
   * Test trackLastImported deprecation message in Migration constructor.
   *
   * @group legacy
   */
  public function testTrackLastImportedDeprecation() {
    $this->expectDeprecation("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");
    $migration_plugin_manager = $this->createMock(MigrationPluginManagerInterface::class);
    $source_plugin_manager = $this->createMock(MigrateSourcePluginManager::class);
    $process_Plugin_manager = $this->createMock(MigratePluginManagerInterface::class);
    $destination_plugin_manager = $this->createMock(MigrateDestinationPluginManager::class);
    $id_map_plugin_manager = $this->createMock(MigratePluginManagerInterface::class);
    new Migration([], 'test', ['trackLastImported' => TRUE], $migration_plugin_manager, $source_plugin_manager, $process_Plugin_manager, $destination_plugin_manager, $id_map_plugin_manager);
  }

}

/**