-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VACMS-14997: module shell for live migration module (#15140)
* VACMS-14997: Module shell for live migration module. * Refactor to improve reliability and information.
- Loading branch information
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
docroot/modules/custom/va_gov_live_field_migration/drush.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
130 changes: 130 additions & 0 deletions
130
docroot/modules/custom/va_gov_live_field_migration/src/Commands/Commands.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
}); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
docroot/modules/custom/va_gov_live_field_migration/va_gov_live_field_migration.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] |
6 changes: 6 additions & 0 deletions
6
docroot/modules/custom/va_gov_live_field_migration/va_gov_live_field_migration.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains va_gov_live_field_migration.module. | ||
*/ |