Skip to content

Commit

Permalink
VACMS-14997: module shell for live migration module (#15140)
Browse files Browse the repository at this point in the history
* VACMS-14997: Module shell for live migration module.

* Refactor to improve reliability and information.
  • Loading branch information
ndouglas authored Sep 7, 2023
1 parent 3d02935 commit 326fff3
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ module:
va_gov_graphql: 0
va_gov_help_center: 0
va_gov_links: 0
va_gov_live_field_migration: 0
va_gov_login: 0
va_gov_lovell: 0
va_gov_magichead: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
va_gov_live_field_migration.commands:
class: \Drupal\va_gov_live_field_migration\Commands\Commands
arguments: []
tags:
- { name: drush.command }
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace Drupal\va_gov_live_field_migration\Commands;

use Drush\Commands\DrushCommands;

/**
* Drush commands for live field migrations.
*/
class Commands extends DrushCommands {

/**
* Perform an operation, such as migrating, rolling back, or verifying.
*
* @param callable $operation
* The operation to perform.
*/
public function performOperation(callable $operation) {
$startTime = microtime(TRUE);
try {
$operation();
}
catch (\Exception $exception) {
$this->output()->writeln('Error: ' . $exception->getMessage());
}
finally {
$elapsedTime = microtime(TRUE) - $startTime;
$peakMemoryUsage = memory_get_peak_usage();
$this->output()->writeln('Elapsed time: ' . number_format($elapsedTime, 2) . ' seconds');
$this->output()->writeln('Peak memory usage: ' . number_format($peakMemoryUsage / 1024 / 1024, 2) . ' MB');
}
}

/**
* Migrate a specific field on a specific content type.
*
* @param string $entityType
* The entity type.
* @param string $bundle
* The entity bundle or content type.
* @param string $fieldName
* The field name.
*
* @command va-gov-live-field-migration:migrate-field
* @aliases va-gov-live-field-migration-migrate-field
*/
public function migrateField(
string $entityType,
string $bundle,
string $fieldName
) {
$this->performOperation(function () use ($entityType, $bundle, $fieldName) {
$this->output()->writeln('Migrating field ' . $fieldName . ' on ' . $entityType . ' ' . $bundle);
// Logic for the migration.
$this->output()->writeln('Migration successful.');
});
}

/**
* Rollback a specific field on a specific content type.
*
* @param string $entityType
* The entity type.
* @param string $bundle
* The entity bundle or content type.
* @param string $fieldName
* The field name.
*
* @command va-gov-live-field-migration:rollback-field
* @aliases va-gov-live-field-migration-rollback-field
*/
public function rollbackField(
string $entityType,
string $bundle,
string $fieldName
) {
$this->performOperation(function () use ($entityType, $bundle, $fieldName) {
$this->output()->writeln('Rolling back field ' . $fieldName . ' on ' . $entityType . ' ' . $bundle);
// Logic for the rollback.
$this->output()->writeln('Rollback successful.');
});
}

/**
* Verify a migration completed successfully.
*
* @param string $entityType
* The entity type.
* @param string $bundle
* The entity bundle or content type.
* @param string $fieldName
* The field name.
*
* @command va-gov-live-field-migration:verify
* @aliases va-gov-live-field-migration-verify
*/
public function verify(
string $entityType,
string $bundle,
string $fieldName
) {
$this->performOperation(function () use ($entityType, $bundle, $fieldName) {
$this->output()->writeln('Verifying field ' . $fieldName . ' on ' . $entityType . ' ' . $bundle);
// Logic for the verification.
$this->output()->writeln('Verification successful.');
});
}

/**
* Find fields that haven't been migrated yet.
*
* @param string $entityType
* The entity type.
* @param string $bundle
* The entity bundle or content type.
*
* @command va-gov-live-field-migration:find
* @aliases va-gov-live-field-migration-find
*/
public function find(
string $entityType,
string $bundle
) {
$this->performOperation(function () use ($entityType, $bundle) {
$this->output()->writeln('Finding fields on ' . $entityType . ' ' . $bundle);
// Logic for finding fields.
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'VA.gov Live Field Migration'
type: module
description: 'Helper functionality for live field migrations.'
core_version_requirement: ^9 || ^10
package: 'Custom'
dependencies: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

/**
* @file
* Contains va_gov_live_field_migration.module.
*/

0 comments on commit 326fff3

Please sign in to comment.