Skip to content

Commit

Permalink
VACMS-15559 Move deploy function to script.
Browse files Browse the repository at this point in the history
  • Loading branch information
swirtSJW committed Feb 1, 2024
1 parent 9920416 commit cd482f5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 27 deletions.
19 changes: 0 additions & 19 deletions docroot/modules/custom/va_gov_vamc/va_gov_vamc.deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Post deploy file VA Gov VAMC.
*/

use Drupal\va_gov_vamc\ServiceLocationMigration;

require_once __DIR__ . '/../../../../scripts/content/script-library.php';

/**
Expand All @@ -19,20 +17,3 @@ function va_gov_vamc_deploy_build_va_police_9001(&$sandbox) {
_va_gov_vamc_create_system_content_pages($sandbox, $build_bundle, 'draft');
return script_library_sandbox_complete($sandbox, "Created @total {$build_bundle} nodes.");
}

/**
* Migrate some facility service data to service location paragraphs.
*/
function va_gov_vamc_deploy_migrate_service_data_to_service_location_9003(&$sandbox) {

$source_bundle = 'health_care_local_health_service';
script_library_sandbox_init($sandbox, 'get_nids_of_type', [$source_bundle, FALSE]);
script_library_toggle_post_api_queueing(TRUE);
new ServiceLocationMigration($sandbox);
$new_service_locations = $sandbox['service_locations_created_count'] ?? 0;
$updated_service_locations = $sandbox['service_locations_updated_count'] ?? 0;
$forward_revisions = $sandbox['forward_revisions_count'] ?? 0;
script_library_toggle_post_api_queueing(FALSE);

return script_library_sandbox_complete($sandbox, "migrated @total {$source_bundle} nodes into {$new_service_locations} new service_location paragraphs, and {$updated_service_locations} updated. Also updated {$forward_revisions} forward revisions.");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* @file
* Migrate data from VAMC Facility Service nodes to Service Location paragraphs.
*
* @see https://github.com/department-of-veterans-affairs/va.gov-cms/issues/15559
*
* This updates ~15,800 Facility services. It takes roughly 2 hours to run.
* It should only be run 1 time or it will duplicate phone data.
*
* If for some reason the run crashes before it is complete:
* - Go to /admin/config/va-gov-post-api/config
* - Uncheck the box for 'Bypass data comparison'
* - Click the 'Save' button.
*/

use Drupal\va_gov_vamc\ServiceLocationMigration;

require_once __DIR__ . '/script-library.php';

run();

/**
* Executes the intended functionality. Runs by default when the script is run.
*/
function run(): void {
script_library_toggle_post_api_data_check(TRUE);
$sandbox = ['#finished' => 0];
do {
print(va_gov_vamc_deploy_migrate_service_data_to_service_location($sandbox));
} while ($sandbox['#finished'] < 1);
// Migration is done.
script_library_toggle_post_api_data_check(FALSE);
return "Script run complete.";
}

/**
* Migrate some facility service data to service location paragraphs.
*/
function va_gov_vamc_deploy_migrate_service_data_to_service_location(&$sandbox) {
$source_bundle = 'health_care_local_health_service';
script_library_sandbox_init($sandbox, 'get_nids_of_type', [$source_bundle, FALSE]);
new ServiceLocationMigration($sandbox);
$new_service_locations = $sandbox['service_locations_created_count'] ?? 0;
$updated_service_locations = $sandbox['service_locations_updated_count'] ?? 0;
$forward_revisions = $sandbox['forward_revisions_count'] ?? 0;
return script_library_sandbox_complete($sandbox, "migrated @total {$source_bundle} nodes into {$new_service_locations} new service_location paragraphs, and {$updated_service_locations} updated. Also updated {$forward_revisions} forward revisions.");
}
26 changes: 18 additions & 8 deletions scripts/content/script-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,32 @@ function script_libary_map_to_value(string|null $lookup, array $map, bool $stric
}

/**
* Turns on or off settings related to the post_api.
* Turns on or off queueing of items to the post_api.
*
* CAUTION: The only time we would want to fully disable queueing is during a
* deploy when editors can not save anything.
*
* @param bool $state
* TRUE to toggle the settings on, FALSE to toggle them off.
*/
function script_library_toggle_post_api_queueing(bool $state): void {
$state = ($state) ? 1 : 0;
$on = ($state) ? 1 : 0;
$config_post_api = \Drupal::configFactory()->getEditable('post_api.settings');

$config_post_api->set('pause_cron_processing', $state)
// CONSIDER: The only time we would want to fully disable queueing is during
// a deploy when editors can not save anything.
// ->set('disable_queueing', $state) .
$config_post_api->set('disable_queueing', $on)
->save(FALSE);
script_library_toggle_post_api_data_check($state);
}

/**
* Turns on or off data checks and deduping for adding items to post_api queue.
*
* @param bool $state
* TRUE to toggle the settings on, FALSE to toggle them off.
*/
function script_library_toggle_post_api_data_check(bool $state): void {
$on = ($state) ? 1 : 0;
$config_va_gov_post_api = \Drupal::configFactory()->getEditable('va_gov_post_api.settings');
$config_va_gov_post_api->set('bypass_data_check', $state)
$config_va_gov_post_api->set('bypass_data_check', $on)
->save(FALSE);
}

Expand Down

0 comments on commit cd482f5

Please sign in to comment.