diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index a2a31b1e6f..21a36cee3b 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -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 diff --git a/docroot/modules/custom/va_gov_live_field_migration/drush.services.yml b/docroot/modules/custom/va_gov_live_field_migration/drush.services.yml new file mode 100644 index 0000000000..e3f89e571a --- /dev/null +++ b/docroot/modules/custom/va_gov_live_field_migration/drush.services.yml @@ -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 } diff --git a/docroot/modules/custom/va_gov_live_field_migration/src/Commands/Commands.php b/docroot/modules/custom/va_gov_live_field_migration/src/Commands/Commands.php new file mode 100644 index 0000000000..8692f1ae75 --- /dev/null +++ b/docroot/modules/custom/va_gov_live_field_migration/src/Commands/Commands.php @@ -0,0 +1,130 @@ +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. + }); + } + +} diff --git a/docroot/modules/custom/va_gov_live_field_migration/va_gov_live_field_migration.info.yml b/docroot/modules/custom/va_gov_live_field_migration/va_gov_live_field_migration.info.yml new file mode 100644 index 0000000000..c29590b780 --- /dev/null +++ b/docroot/modules/custom/va_gov_live_field_migration/va_gov_live_field_migration.info.yml @@ -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: [] diff --git a/docroot/modules/custom/va_gov_live_field_migration/va_gov_live_field_migration.module b/docroot/modules/custom/va_gov_live_field_migration/va_gov_live_field_migration.module new file mode 100644 index 0000000000..31cddced81 --- /dev/null +++ b/docroot/modules/custom/va_gov_live_field_migration/va_gov_live_field_migration.module @@ -0,0 +1,6 @@ +