From eefe3a87b96ce1c9cf3d3ba6dd48a6911c0e6cc1 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 4 Oct 2022 21:46:13 +0100
Subject: [PATCH] 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

---
 core/modules/migrate/src/Plugin/Migration.php  | 13 +++++++++++++
 .../migrate/src/Plugin/MigrationInterface.php  | 15 +++++++++++++++
 .../migrate/src/Plugin/migrate/id_map/Sql.php  |  4 +---
 .../tests/src/Kernel/Plugin/MigrationTest.php  |  5 +++++
 .../migrate/tests/src/Unit/MigrationTest.php   | 18 ++++++++++++++++++
 5 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/core/modules/migrate/src/Plugin/Migration.php b/core/modules/migrate/src/Plugin/Migration.php
index 8e3b3eac0a0a..78c194d62c4d 100644
--- a/core/modules/migrate/src/Plugin/Migration.php
+++ b/core/modules/migrate/src/Plugin/Migration.php
@@ -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;
   }
 
diff --git a/core/modules/migrate/src/Plugin/MigrationInterface.php b/core/modules/migrate/src/Plugin/MigrationInterface.php
index 61942a21f6fb..da8cdd819e37 100644
--- a/core/modules/migrate/src/Plugin/MigrationInterface.php
+++ b/core/modules/migrate/src/Plugin/MigrationInterface.php
@@ -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();
 
diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
index 4b76e4fbc68f..34bf477264e4 100644
--- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
@@ -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();
-    }
+    $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);
diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
index 706318e83534..8523f6b63ab9 100644
--- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
+++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
@@ -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());
diff --git a/core/modules/migrate/tests/src/Unit/MigrationTest.php b/core/modules/migrate/tests/src/Unit/MigrationTest.php
index b4fb8a96de35..3656584d0d2e 100644
--- a/core/modules/migrate/tests/src/Unit/MigrationTest.php
+++ b/core/modules/migrate/tests/src/Unit/MigrationTest.php
@@ -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);
+  }
+
 }
 
 /**
-- 
GitLab