Error on import nodes through the acquia_contenthub_subscriber_import queue

Created on 29 April 2022, about 2 years ago
Updated 8 December 2023, 7 months ago

Problem/Motivation

This problem occurs when importing a node, through the interface of the
Acquia ContentHub Subscriber, already exported previously through the Acquia ContentHub module's structure.

After running the import queue, the batch returns the following error:
Exception: The body field does not specify a metadata target. This is likely due to an unresolved dependency export process. Please check your relationships. in Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField\TextItemField->getEntity() (line 36 of /app/docroot/modules/contrib/acquia_contenthub/src/EventSubscriber/UnserializeContentField/FieldEntityDependencyTrait.php).

After retrying this process after the batch error, the queue runs its processing successfully. At the end of the process, the queue still keeps the items that could not be imported in the processing queue because of the error triggered in the first process.

Steps to reproduce

To perform this process, it is necessary to have 2 environments to perform this process. In the environment that will serve as the data source, enable the Acquia ContentHub Publisher module, and in the destination enable the Acquia ContentHub Subscriber module. After exporting a node in the source environment, perform the following steps:

  1. Access the import interface offered by the Acquia ContentHub Subscriber module here: /admin/config/services/acquia-contenthub/import-queue
  2. After checking the number of items available to import in the Number of items in the import queue field, click on the Import Items button
  3. Track the import queue processing, and after the error, see the error log (or Report Dblog issues here: /admin/reports/dblog)

Proposed resolution

Map the target field, using the imported entity as a reference, so that the import can occur successfully.

πŸ’¬ Support request
Status

Needs review

Version

2.0

Component

Documentation

Created by

πŸ‡§πŸ‡·Brazil erick.major Campinas, SΓ£o Paulo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡΅πŸ‡±Poland lamp5 Rzeszow

    The problem is that your text filter is missing in ACH, you have to process your data during unserialize process to attach your local text filter.

    <?php
    
    namespace Drupal\mymodule\EventSubscriber\UnserializeContentField;
    
    use Drupal\acquia_contenthub\AcquiaContentHubEvents;
    use Drupal\acquia_contenthub\Event\UnserializeCdfEntityFieldEvent;
    use Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField\FieldEntityReferenceBase;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    /**
     * Manual handling for text item fields filter references.
     */
    class TextItemFieldWithFilter extends FieldEntityReferenceBase implements EventSubscriberInterface {
    
      /**
       * Field types to unserialize.
       *
       * @var array
       */
      protected $fieldTypes = ['text_with_summary', 'text', 'text_long'];
    
      /**
       * {@inheritdoc}
       */
      public static function getSubscribedEvents() {
        $events[AcquiaContentHubEvents::UNSERIALIZE_CONTENT_ENTITY_FIELD] =
          ['onUnserializeContentField', 101];
        return $events;
      }
    
      /**
       * {@inheritdoc}
       */
      public function onUnserializeContentField(UnserializeCdfEntityFieldEvent $event) {
        if (!in_array($event->getFieldMetadata()['type'], $this->fieldTypes)) {
          return;
        }
    
        $field = $event->getField();
        $values = [];
    
        // Return early if no attr values are set.
        if (empty($field['value'])) {
          return;
        }
    
        foreach ($field['value'] as $langcode => $value) {
          foreach ($value as &$item) {
            if (!$item['format']) {
              continue;
            }
            $filter = $this->getFilter($item['format']);
            if (!$filter) {
              $this->log($item['format']);
              $item['format'] = filter_fallback_format();
            }
            $item['format'] = $filter->id();
          }
          $values[$langcode][$event->getFieldName()] = $value;
        }
        $event->setValue($values);
        $event->stopPropagation();
      }
    
      /**
       * Get filter.
       *
       * @param string $uuid
       *   Filter uuid.
       *
       * @return \Drupal\filter\Entity\FilterFormat|null
       *   Filter format.
       */
      protected function getFilter(string $uuid) {
        $storage = \Drupal::entityTypeManager()->getStorage('filter_format');
        $entities = $storage->loadByProperties(['uuid' => $uuid]);
        return !empty($entities) ? reset($entities) : NULL;
      }
    
    }
    
Production build 0.69.0 2024