Which property should I set to save the last imported time in the migration map (SQL)?

I've seen that adding:

  track_changes: true


The hash is been calculated but no idea how to set the calculation of the time.


  • Did you find any solution? – ilazgo Dec 12 '17 at 9:14

You have to set setTrackLastImported to TRUE.

What I've done is create a new source plugin that extends the source plugin that I was using and set to true the last imported property.

 * Source plugin that extends "url" source plugin and saves the last imported
 * date.
 * @MigrateSource(
 *   id = "url_last_import"
 * )
class UrlLastImport extends Url {

public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);

I don't know if it's the best solution, but it works.

| improve this answer | |

The last import date for a migration is stored in the key_value store.

See Drupal\migrate_tools\Controller\MigrationListBuilder.php for an example on how to get the timestamp of the last import for a given migration:

  $migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported');
  $last_imported = $migrate_last_imported_store->get($migration->id(), FALSE);

Next to the last imported timestamp it's also possible to get a timestamp for each row (with setTrackLastImported(), see Drupal\migrate\Plugin\migrate\id_map\Sql).

| improve this answer | |
  • The value retrieved is in milliseconds so make sure you divide by 1000. Example can be found in modules/contrib/migrate_tools/src/Controller/MigrationListBuilder.php. – nbaosullivan Apr 24 '19 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.