Skip to content

Commit

Permalink
Added hs_migrate_update_8007 to remove selected unused importers conf…
Browse files Browse the repository at this point in the history
…iguration and database tables.
  • Loading branch information
Seth Hendrick committed Jan 15, 2025
1 parent c6a31d1 commit 2644e27
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docroot/modules/humsci/hs_migrate/hs_migrate.install
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,56 @@ function hs_migrate_update_8006() {
}
}
}

/**
* Remove unused importers.
*/
function hs_migrate_update_8007() {
$unused_importers = [
'hs_d7_gallery_nodes',
'hs_d7_gallery_paragraphs',
'hs_d7_people',
'hs_d7_publications',
'hs_news_rss',
'custm_cesta_publications',
'custm_dlcl_research',
'custm_dlcl_research_unit_group',
'custm_em1060_manuscript',
'custm_facultyaffairs_users',
'custm_hs_d7_gc_publication_component',
'custm_hshr_client',
'custm_sgs_d7_degrees_offered',
'custm_sgs_d7_fund_opp',
'custm_sgs_d7_testimonials',
'custm_stats_tech_reports',
'custm_hs_wmlcp_users',
'hs_d7_news'
];

// Get site name to prevent removing hs_d7_news from MRC.
$site_name = \Drupal::config('system.site')->get('name');
$is_mrc = str_contains($site_name, 'Mathematics Research Center');

$config_factory = \Drupal::configFactory();
$schema = \Drupal::database()->schema();

foreach ($unused_importers as $importer) {
$is_hs_d7_news = str_contains($importer, 'hs_d7_news');

if (!$is_mrc || !$is_hs_d7_news) {
// Remove migration importer configuration.
$config_name = 'migrate_plus.migration.' . $importer;
$config_factory->getEditable($config_name)->delete();

// Drop migration database tables.
$migrate_map_table = 'migrate_map_' . $importer;
if ($schema->tableExists($migrate_map_table)) {
$schema->dropTable($migrate_map_table);
}
$migrate_message_table = 'migrate_message_' . $importer;
if ($schema->tableExists($migrate_message_table)) {
$schema->dropTable($migrate_message_table);
}
}
}
}

0 comments on commit 2644e27

Please sign in to comment.