From 52d41e2e99637d21d81feece0630d68f9d2f1ae6 Mon Sep 17 00:00:00 2001 From: orakili Date: Fri, 20 Sep 2024 06:30:18 +0000 Subject: [PATCH 1/2] chore: hide interactive content format Refs: RW-1077 --- .../reliefweb_entities/src/Services/ReportFormAlter.php | 8 ++++++++ .../custom/reliefweb_rivers/src/Services/ReportRiver.php | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php b/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php index be44f632c..ee73f401e 100644 --- a/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php +++ b/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php @@ -6,6 +6,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\reliefweb_entities\Entity\Report; use Drupal\reliefweb_entities\EntityFormAlterServiceBase; use Drupal\reliefweb_form\Helpers\FormHelper; use Drupal\reliefweb_utility\Helpers\UrlHelper; @@ -74,6 +75,13 @@ protected function addBundleFormAlterations(array &$form, FormStateInterface $fo // Remove data (9420) option for content format field (Collab #3679). FormHelper::removeOptions($form, 'field_content_format', [9420]); + // Remove interactive (38974) format if the report is not tagged with it. + // @see https://humanitarian.atlassian.net/browse/RW-1077 + $report = $form_state?->getFormObject()?->getEntity(); + if ($report instanceof Report && $report?->field_content_format?->target_id != 38974) { + FormHelper::removeOptions($form, 'field_content_format', [38974]); + } + // Remove Key document (2) option for feature field. FormHelper::removeOptions($form, 'field_feature', [2]); diff --git a/html/modules/custom/reliefweb_rivers/src/Services/ReportRiver.php b/html/modules/custom/reliefweb_rivers/src/Services/ReportRiver.php index 526e843bd..0ec9b80da 100644 --- a/html/modules/custom/reliefweb_rivers/src/Services/ReportRiver.php +++ b/html/modules/custom/reliefweb_rivers/src/Services/ReportRiver.php @@ -173,6 +173,10 @@ public function getFilters() { 'name' => $this->t('Content format'), 'type' => 'reference', 'vocabulary' => 'content_format', + 'exclude' => [ + // Interactive (RW-1077). + 38974, + ], 'field' => 'format.id', 'widget' => [ 'type' => 'options', From 62ec71ed2d9b6efb3ee62620137005629973e195 Mon Sep 17 00:00:00 2001 From: orakili Date: Fri, 20 Sep 2024 06:30:48 +0000 Subject: [PATCH 2/2] chore: add script to archive interactive content Refs: RW-1077 --- scripts/retagging/RW-1077.php | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scripts/retagging/RW-1077.php diff --git a/scripts/retagging/RW-1077.php b/scripts/retagging/RW-1077.php new file mode 100644 index 000000000..faf6ce6a2 --- /dev/null +++ b/scripts/retagging/RW-1077.php @@ -0,0 +1,52 @@ +query(" + SELECT DISTINCT n.nid + FROM {node_field_data} AS n + INNER JOIN {node__field_content_format} AS fcf + ON fcf.entity_id = n.nid + WHERE n.type = :bundle + AND fcf.field_content_format_target_id = :content_format + ORDER BY nid ASC +", [ + ":bundle" => "report", + ":content_format" => $content_format, +])->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; + + foreach (array_chunk($nids, $chunk_size) as $chunk) { + foreach ($storage->loadMultiple($chunk) as $node) { + $node->setModerationStatus('archive'); + $node->notifications_content_disable = TRUE; + $node->setRevisionLogMessage("Automatic archiving of interactive content (Ref: RW-1077)."); + $node->setRevisionUserId(2); + $node->setRevisionCreationTime($now); + $node->setNewRevision(TRUE); + if ($save) { + $node->save(); + } + + echo "Progress: $progress / $total..." . PHP_EOL; + $progress++; + } + } +}