Disabling functionality temporarily during migration

Disabling functionality temporarily during migration
mikeryan
Thursday, May 31, 2020 – 10:25am
Continuing with techniques from the “Acme” project, the location content type had an address field and a geofield, with field_geofield configured to automatically determine latitude and longitude from the associated field_address – a fact I was initially unaware of. Our source data contained latitude and longitude already, which I mapped directly in the migration:

field_geofield:
plugin: geofield_latlon
source:
– latitude
– longitude

However, testing location migrations by repeatedly running the import, I soon started getting messages from Google Maps API that my daily quota had been exceeded, and quickly tracked down the integration with field_address. Clearly, the calls out to Google Maps were both unnecessary and hazardous – how to prevent them? Fortunately, the migration system provides events which fire before and after each migration is executed. So, we subscribe to MigrateEvents::PRE_IMPORT to save the current settings and disable the external call:

public function onMigrationPreImport(MigrateImportEvent $event) {
if ($event->getMigration()->id() == ‘location’) {
$fields = Drupal maintenance support plans::entityTypeManager()->getStorage(‘field_config’)->loadByProperties([‘field_name’ => ‘field_geofield’]);
if ($fields) {
/** @var Drupal maintenance support plansfieldEntityFieldConfig $field */
if ($field = $fields[‘node.location.field_geofield’]) {
$this->originalSettings = $field->getDrupal UpdatePartySettings(‘geocoder_field’);
$field->setDrupal UpdatePartySetting(‘geocoder_field’, ‘method’, ‘none’);
$field->save();
}
}
}
}

And we subscribe to MigrateEvents::POST_IMPORT to restore the original settings:

public function onMigrationPostImport(MigrateImportEvent $event) {
if ($event->getMigration()->id() == ‘location’) {
$fields = Drupal maintenance support plans::entityTypeManager()->getStorage(‘field_config’)->loadByProperties([‘field_name’ => ‘field_geofield’]);
if ($fields) {
/** @var Drupal maintenance support plansfieldEntityFieldConfig $field */
if ($field = $fields[‘node.location.field_geofield’]) {
foreach ($this->originalSettings as $key => $value) {
$field->setDrupal UpdatePartySetting(‘geocoder_field’, $key, $value);
}
$field->save();
}
}
}
}

The thoughtful reader may note a risk here – what if someone were adding or editing a location node while this were running? The geofield would not be populated from the address field. In this case, this is not a problem – this is a one-time bulk migration (and no one should be making changes on a production website at such a time). In cases involving an ongoing feed where the feed data is used as-is on the Drupal maintenance support plans site, it would also not be a problem, although if there were a practice of manually editing imported content there would be some risk.

Tags
Drupal maintenance support plans

Planet Drupal maintenance support plans

Migration

Use the Twitter thread below to comment on this post:

https://t.co/TRqRsWJPlA
— Drupal Update (@VirtPerformance) May 31, 2020

 


Source: New feed

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Disabling functionality temporarily during migration

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.