diff --git a/html/modules/custom/ghi_content/ghi_content.services.yml b/html/modules/custom/ghi_content/ghi_content.services.yml index 3333c1665..4328ee9db 100644 --- a/html/modules/custom/ghi_content/ghi_content.services.yml +++ b/html/modules/custom/ghi_content/ghi_content.services.yml @@ -15,6 +15,11 @@ services: class: Drupal\ghi_content\EventSubscriber\RouteSubscriber tags: - { name: event_subscriber } + ghi_content.post_row_save_subscriber: + class: '\Drupal\ghi_content\EventSubscriber\PostRowSaveEventSubscriber' + arguments: ['@entity_type.manager', '@ghi_content.manager.factory'] + tags: + - { name: 'event_subscriber' } ghi_content.manager.factory: class: Drupal\ghi_content\ContentManager\ManagerFactory arguments: ['@ghi_content.manager.article', '@ghi_content.manager.document'] diff --git a/html/modules/custom/ghi_content/src/EventSubscriber/PostRowSaveEventSubscriber.php b/html/modules/custom/ghi_content/src/EventSubscriber/PostRowSaveEventSubscriber.php new file mode 100644 index 000000000..caed02a9f --- /dev/null +++ b/html/modules/custom/ghi_content/src/EventSubscriber/PostRowSaveEventSubscriber.php @@ -0,0 +1,93 @@ +entityTypeManager = $entity_type_manager; + $this->managerFactory = $manager_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity_type.manager'), + $container->get('ghi_content.manager.factory'), + ); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $events[MigrateEvents::POST_ROW_SAVE][] = ['onMigratePostRowSave']; + return $events; + } + + /** + * React to an entity having been saved during a migration run. + * + * Check update imported or updated article or document nodes with their + * version from the remote source system. + * + * @param \Drupal\migrate\Event\MigratePostRowSaveEvent $event + * The event object. + */ + public function onMigratePostRowSave(MigratePostRowSaveEvent $event) { + $migration_ids = [ + 'articles_hpc_content_module', + 'documents_hpc_content_module', + ]; + if (!in_array($event->getMigration()->id(), $migration_ids)) { + return; + } + $ids = $event->getDestinationIdValues(); + $entities = $this->entityTypeManager->getStorage('node')->loadMultiple($ids); + foreach ($entities as $entity) { + $content_manager = $this->managerFactory->getContentManager($entity); + if (!$content_manager) { + continue; + } + $content_manager->updateNodeFromRemote($entity); + $content_manager->saveContentNode($entity); + } + } + +} diff --git a/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceBaseHpcContentModule.php b/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceBaseHpcContentModule.php index 8f5314f58..ab206db5b 100644 --- a/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceBaseHpcContentModule.php +++ b/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceBaseHpcContentModule.php @@ -225,6 +225,7 @@ public function query($payload) { 'body' => $body, 'headers' => $headers, 'cookies' => $jar, + 'timeout' => 60000, ]; // See if we have a cached version already for this request.