migrate http://lobsterr.me/ en How to run migration programmatically as a batch operations in Drupal 9? http://lobsterr.me/post/how-run-migration-programmatically-batch-operations-drupal-9 <span class="field field--name-title field--type-string field--label-hidden">How to run migration programmatically as a batch operations in Drupal 9?</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">LOBsTerr</span></span> <span class="field field--name-created field--type-created field--label-hidden">01/26/2021</span> <div class="field field--name-f-content field--type-entity-reference-revisions field--label-hidden field__items"> <div class="field__item"> <div class="paragraph paragraph--type--l-text paragraph--view-mode--default"> <div class="clearfix text-formatted field field--name-f-text field--type-text-long field--label-hidden field__item"><p>It is quite easy to do instead of <strong>MigrateExecutable </strong>class, we need to use <strong>MigrateBatchExecutable </strong>and instead of <strong>import </strong>we need to use <strong>batchImport</strong></p> <pre> <code class="language-php">use Drupal\migrate_tools\MigrateExecutable; $migration = \Drupal::service('plugin.manager.migration')-&gt;createInstance($migration_id); if (!empty($migration)) { // here we can set additional options like limit, update or force the import. $options = [ 'limit' =&gt; 0, 'update' =&gt; 1, 'force' =&gt; 1, ]; $executable = new MigrateBatchExecutable($migration, new MigrateMessage(), $options); $executable-&gt;batchImport(); }</code></pre> <p> </p> </div> </div> </div> </div> <div class="field field--name-f-tags field--type-entity-reference field--label-hidden field__items"> <div class="field__item btn btn-secondary"><a href="/tags/migrate" hreflang="en">migrate</a></div> <div class="field__item btn btn-secondary"><a href="/tags/drupal-9" hreflang="en">Drupal 9</a></div> </div> <div class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush"> <div class="field__label">Related items</div> <ul class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush field__items"> <li class="field__item list-group-item"><a href="/post/how-run-migration-programmatically-drupal-9" hreflang="en">How to run a migration programmatically in Drupal 9?</a></li> </ul> </div> <section class="field field--name-f-comments field--type-comment field--label-above comment-wrapper"> </section> Tue, 26 Jan 2021 16:34:06 +0000 LOBsTerr 29 at http://lobsterr.me How to run a migration programmatically in Drupal 9? http://lobsterr.me/post/how-run-migration-programmatically-drupal-9 <span class="field field--name-title field--type-string field--label-hidden">How to run a migration programmatically in Drupal 9?</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">LOBsTerr</span></span> <span class="field field--name-created field--type-created field--label-hidden">11/19/2019</span> <div class="field field--name-f-content field--type-entity-reference-revisions field--label-hidden field__items"> <div class="field__item"> <div class="paragraph paragraph--type--l-text paragraph--view-mode--default"> <div class="clearfix text-formatted field field--name-f-text field--type-text-long field--label-hidden field__item"><p>The code bellow display how to execute the migration not through the command line, but through the code</p> <p>First we need to load Migration. You can create it from a plugin, in this case the migration file is stored in <strong>migrations </strong>folder</p> <p> </p> <pre> <code class="language-php">use Drupal\migrate\MigrateMessage; use Drupal\migrate_plus\Entity\Migration; use Drupal\migrate_tools\MigrateExecutable; // Load migration plugin. $migration = \Drupal::service('plugin.manager.migration')-&gt;createInstance($migration_id);</code></pre> <p>or load it it from config entity</p> <pre> <code class="language-php">// Load migration from config entity. $migration = \Drupal\migrate_plus\Entity\Migration::load($migration_id);</code></pre> <p>And then run the import</p> <pre> <code class="language-php">$executable = new MigrateExecutable($migration, new MigrateMessage()); $executable-&gt;import().</code></pre> </div> </div> </div> </div> <div class="field field--name-f-tags field--type-entity-reference field--label-hidden field__items"> <div class="field__item btn btn-secondary"><a href="/tags/migrate" hreflang="en">migrate</a></div> <div class="field__item btn btn-secondary"><a href="/tags/drupal-9" hreflang="en">Drupal 9</a></div> </div> <div class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush"> <div class="field__label">Related items</div> <ul class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush field__items"> <li class="field__item list-group-item"><a href="/post/how-run-migration-programmatically-batch-operations-drupal-9" hreflang="en">How to run migration programmatically as a batch operations in Drupal 9?</a></li> </ul> </div> <section class="field field--name-f-comments field--type-comment field--label-above comment-wrapper"> </section> Tue, 19 Nov 2019 14:56:41 +0000 LOBsTerr 19 at http://lobsterr.me How to update URL for migration programmatically in Drupal 8? http://lobsterr.me/post/how-update-url-migration-programmatically-drupal-8 <span class="field field--name-title field--type-string field--label-hidden">How to update URL for migration programmatically in Drupal 8?</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">LOBsTerr</span></span> <span class="field field--name-created field--type-created field--label-hidden">11/19/2019</span> <div class="field field--name-f-content field--type-entity-reference-revisions field--label-hidden field__items"> <div class="field__item"> <div class="paragraph paragraph--type--l-text paragraph--view-mode--default"> <div class="clearfix text-formatted field field--name-f-text field--type-text-long field--label-hidden field__item"><p>Sometimes we need to dynamically set URL for migrations, for example we have specific parameters restricting results.</p> <p>We have default configuration</p> <pre> <code class="language-yaml">source: plugin: url data_fetcher_plugin: http data_parser_plugin: json urls: - 'http://your_domain/data.php'</code></pre> <p> </p> <pre> <code class="language-php">// Get configuration factory. $config_factory = \Drupal::configFactory(); // Load your migration configuration. // Replace with your migration ID. $migration_config = $config_factory-&gt;getEditable('migrate_plus.migration.[MIGRATION_ID]'); // Set your URL here. $migration_config -&gt;set('source.urls', ['YOUR_URL']); $migration_config -&gt;save();</code></pre> <p> </p> </div> </div> </div> </div> <div class="field field--name-f-tags field--type-entity-reference field--label-hidden field__items"> <div class="field__item btn btn-secondary"><a href="/tags/migrate" hreflang="en">migrate</a></div> <div class="field__item btn btn-secondary"><a href="/tags/drupal-9" hreflang="en">Drupal 9</a></div> </div> <section class="field field--name-f-comments field--type-comment field--label-above comment-wrapper"> </section> Tue, 19 Nov 2019 14:47:46 +0000 LOBsTerr 18 at http://lobsterr.me