Skip to content

Commit

Permalink
Move function.
Browse files Browse the repository at this point in the history
  • Loading branch information
joegl committed Feb 3, 2025
1 parent e8b89ec commit 65f47ab
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 68 deletions.
68 changes: 68 additions & 0 deletions docroot/modules/humsci/hs_migrate/hs_migrate.install
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,71 @@ function hs_migrate_update_8008() {

_hs_migrate_remove_importers($unused_importers);
}

/**
* Deletes importer configuration and drops migration tables.
*
* This function takes either a single string or an array of importer names as
* strings, removes their configuration, migration tables, and logs the results.
*
* @param string|string[] $input
* A single string or an array of importer names to process.
*
* @throws \InvalidArgumentException
* When the input is neither a string nor an array of strings.
*/
function _hs_migrate_remove_importers(string|array $input): void {
// Convert single string to array for consistent processing
$importers = is_array($input) ? $input : [$input];

// Validate all elements are strings
foreach ($importers as $importer) {
if (!is_string($importer)) {
throw new \InvalidArgumentException(
'All elements in the input array must be strings.'
);
}
}

foreach ($importers as $importer) {
// Verify migration entity exists.
$migration = \Drupal::entityTypeManager()
->getStorage('migration')
->load($importer);

if (!$migration) {
continue;
}

// Initialize logger and schema for the first importer found.
if (!isset($logger)) {
$logger = \Drupal::logger('hs_migrate');
$schema = \Drupal::database()->schema();
}

// Remove migration importer configuration.
$migration->delete();
$message = t('Deleted @config', [
'@config' => 'migrate_plus.migration.' . $importer,
]);
$logger->notice($message);

// Drop migration database tables.
$migrate_map_table = 'migrate_map_' . $importer;
if ($schema->tableExists($migrate_map_table)) {
$schema->dropTable($migrate_map_table);
$message = t('Dropped table @table', [
'@table' => $migrate_map_table,
]);
$logger->notice($message);
}
$migrate_message_table = 'migrate_message_' . $importer;
if ($schema->tableExists($migrate_message_table)) {
$schema->dropTable($migrate_message_table);
$message = t('Dropped table @table', [
'@table' => $migrate_message_table,
]);
$logger->notice($message);
}
}
}
68 changes: 0 additions & 68 deletions docroot/modules/humsci/hs_migrate/hs_migrate.module
Original file line number Diff line number Diff line change
Expand Up @@ -129,71 +129,3 @@ function _hs_migrate_media_imported($media_id) {

return FALSE;
}

/**
* Deletes importer configuration and drops migration tables.
*
* This function takes either a single string or an array of importer names as
* strings, removes their configuration, migration tables, and logs the results.
*
* @param string|string[] $input
* A single string or an array of importer names to process.
*
* @throws \InvalidArgumentException
* When the input is neither a string nor an array of strings.
*/
function _hs_migrate_remove_importers(string|array $input): void {
// Convert single string to array for consistent processing
$importers = is_array($input) ? $input : [$input];

// Validate all elements are strings
foreach ($importers as $importer) {
if (!is_string($importer)) {
throw new \InvalidArgumentException(
'All elements in the input array must be strings.'
);
}
}

foreach ($importers as $importer) {
// Verify migration entity exists.
$migration = \Drupal::entityTypeManager()
->getStorage('migration')
->load($importer);

if (!$migration) {
continue;
}

// Initialize logger and schema for the first importer found.
if (!isset($logger)) {
$logger = \Drupal::logger('hs_migrate');
$schema = \Drupal::database()->schema();
}

// Remove migration importer configuration.
$migration->delete();
$message = t('Deleted @config', [
'@config' => 'migrate_plus.migration.' . $importer,
]);
$logger->notice($message);

// Drop migration database tables.
$migrate_map_table = 'migrate_map_' . $importer;
if ($schema->tableExists($migrate_map_table)) {
$schema->dropTable($migrate_map_table);
$message = t('Dropped table @table', [
'@table' => $migrate_map_table,
]);
$logger->notice($message);
}
$migrate_message_table = 'migrate_message_' . $importer;
if ($schema->tableExists($migrate_message_table)) {
$schema->dropTable($migrate_message_table);
$message = t('Dropped table @table', [
'@table' => $migrate_message_table,
]);
$logger->notice($message);
}
}
}

0 comments on commit 65f47ab

Please sign in to comment.