From 1a4028644a9b5d69d92425b85b406dd266c1eefb Mon Sep 17 00:00:00 2001 From: orakili Date: Mon, 17 Feb 2025 02:57:22 +0000 Subject: [PATCH 1/2] chore: set Other as default OCHA product Refs: RW-1175 --- config/field.field.node.report.field_ocha_product.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/config/field.field.node.report.field_ocha_product.yml b/config/field.field.node.report.field_ocha_product.yml index 5fbb5118c..ec73639ea 100644 --- a/config/field.field.node.report.field_ocha_product.yml +++ b/config/field.field.node.report.field_ocha_product.yml @@ -6,6 +6,8 @@ dependencies: - field.storage.node.field_ocha_product - node.type.report - taxonomy.vocabulary.ocha_product + content: + - 'taxonomy_term:ocha_product:a3ba79f0-7af9-40d0-bb1a-bf1e4d80613f' id: node.report.field_ocha_product field_name: field_ocha_product entity_type: node @@ -14,7 +16,9 @@ label: 'OCHA product' description: '' required: false translatable: false -default_value: { } +default_value: + - + target_uuid: a3ba79f0-7af9-40d0-bb1a-bf1e4d80613f default_value_callback: '' settings: handler: any_term @@ -23,7 +27,7 @@ settings: ocha_product: ocha_product sort: field: name - direction: asc - auto_create: false + direction: ASC + auto_create: 0 auto_create_bundle: '' field_type: entity_reference From 7c1c6e25fcfe35f1cdb74b940fe9ea6589cefa03 Mon Sep 17 00:00:00 2001 From: orakili Date: Mon, 17 Feb 2025 03:29:11 +0000 Subject: [PATCH 2/2] chore: add script used to retag OCHA product Refs: RW-1175 --- scripts/retagging/RW-1175.php | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 scripts/retagging/RW-1175.php diff --git a/scripts/retagging/RW-1175.php b/scripts/retagging/RW-1175.php new file mode 100644 index 000000000..b6d402605 --- /dev/null +++ b/scripts/retagging/RW-1175.php @@ -0,0 +1,64 @@ + "Press Release", + 12352 => "Statement/Speech", + 12353 => "Other", +]; + +$nids = \Drupal::database()->query(" + SELECT DISTINCT n.nid + FROM {node_field_data} AS n + INNER JOIN {node__field_ocha_product} AS fs + ON fs.entity_id = n.nid + WHERE fs.field_ocha_product_target_id IS NOT NULL + AND fs.field_ocha_product_target_id NOT IN (:terms[]) + ORDER BY nid ASC +", [ + ":terms[]" => array_keys($terms), +])->fetchCol(); + +$total = count($nids); + +echo "Found " . $total . " nodes to update" . PHP_EOL; + +if (!empty($proceed)) { + $storage = \Drupal::entityTypeManager()->getStorage("node"); + $chunk_size = 100; + $now = time(); + $progress = 1; + + $results = []; + foreach (array_chunk($nids, $chunk_size) as $chunk) { + foreach ($storage->loadMultiple($chunk) as $node) { + foreach ($node->field_ocha_product as $item) { + if (!isset($terms[$item->target_id])) { + $results[$node->bundle()][$item->target_id] = ($results[$node->bundle()][$item->target_id] ?? 0) + 1; + $item->target_id = 12353; + } + } + + $node->notifications_content_disable = TRUE; + $node->setRevisionLogMessage("Automatic retagging of OCHA product (Ref: RW-1175)."); + $node->setRevisionUserId(2); + $node->setRevisionCreationTime($now); + $node->setNewRevision(TRUE); + if ($save) { + $node->save(); + } + + echo "Progress: $progress / $total..." . PHP_EOL; + $progress++; + } + } + + print_r($results); +}