Skip to content

Commit

Permalink
Update hook to delete old award entities
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 21, 2024
1 parent 57cb210 commit 5bfc639
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ migration_group: sup_press
label: 'Stanford University Press Books Table Of Contents'
source:
plugin: url
orphan_action: delete
urls:
- 'https://memento.stanford.edu/fmi/data/v2/databases/Web/layouts/Web/records?_limit=1000'
- 'https://memento.stanford.edu/fmi/data/v2/databases/Web/layouts/Web/records?_limit=1000&_offset=1001'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ migration_group: sup_press
label: 'Import Stanford University Press Social Links'
source:
plugin: url
orphan_action: delete
data_fetcher_plugin: file
urls:
- 'public://social-links.json'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,37 @@ function supress_helper_update_9008() {
/**
* Fixed book e-retailers urls with trailing spaces.
*/
function supress_helper_update_9009(){
\Drupal::database()->query('UPDATE node__sup_book_e_retailers SET sup_book_e_retailers_uri = RTRIM(sup_book_e_retailers_uri)')->execute();
\Drupal::database()->query('UPDATE node_revision__sup_book_e_retailers SET sup_book_e_retailers_uri = RTRIM(sup_book_e_retailers_uri)')->execute();
function supress_helper_update_9009() {
\Drupal::database()
->query('UPDATE node__sup_book_e_retailers SET sup_book_e_retailers_uri = RTRIM(sup_book_e_retailers_uri)')
->execute();
\Drupal::database()
->query('UPDATE node_revision__sup_book_e_retailers SET sup_book_e_retailers_uri = RTRIM(sup_book_e_retailers_uri)')
->execute();
}

/**
* Rollback award migration.
*/
function supress_helper_update_9010(&$sandbox) {
$award_storage = \Drupal::entityTypeManager()->getStorage('sup_award');
if (empty($sandbox['ids'])) {
$sandbox['ids'] = $award_storage->getQuery()
->accessCheck(FALSE)
->execute();
$sandbox['total'] = count($sandbox['ids']);
}

$award_ids = array_splice($sandbox['ids'], 0, 50);
foreach ($award_storage->loadMultiple($award_ids) as $award) {
$award->delete();
}
$sandbox['#finished'] = count($sandbox['ids']) ? 1 - count($sandbox['ids']) / $sandbox['total'] : 1;
}

/**
* Truncate award migration table.
*/
function supress_helper_update_9011() {
\Drupal::database()->truncate('migrate_map_sup_awards')->execute();
}

0 comments on commit 5bfc639

Please sign in to comment.