private function importContentType(
        $contentTypeName,
        Bag $importData,
        MutableBag $relationQueue,
        MutableBag $responseBag,
        $overwrite
    ) {
        $count = 0;
        /** @var Repository $repo */
        $repo = $this->em->getRepository($contentTypeName);

        // Build a list of the relationship field names for this ContentType
        $relationFields = MutableBag::from([]);
        $taxonomyFields = MutableBag::from([]);
        foreach ($repo->getClassMetadata()->getFieldMappings() as $field) {
            if (is_a($field['fieldtype'], RelationType::class, true)) {
                $relationFields->add($field['fieldname']);
            }
            if (is_a($field['fieldtype'], TaxonomyType::class, true)) {
                $taxonomyFields->add($field['fieldname']);
            }
        }

        /** @var MutableBag $importDatum */
        foreach ($importData as $importDatum) {
            /** @var Content $entity */
            $entity = $repo->create(['contenttype' => $contentTypeName]);
            $values = $importDatum->toArrayRecursive();
            $entity->setValues($values);
            // Add relations now so they can still be applied if required on re-runs
            $this->addRelations($repo, $relationQueue, $importDatum, $relationFields);
            // Add taxonomy fields
            $this->addTaxonomy($entity, $taxonomyFields, $importDatum);

            $existing = $this->query->getContent($entity->getContenttype() . '/' . $entity->getSlug());
            if ($existing instanceof Content) {
                $entity->setId($existing->getId());
            }
            // If the entity already exists and we're not doing overwrite, exit early
            if ($entity->getId() !== null && $overwrite === false) {
                $responseBag->get('warning')->add(sprintf('ContentType "%s" with slug "%s" exists already! Skipping record.', $contentTypeName, $entity->getSlug()));
                continue;
            }

            $repo->save($entity);
            ++$count;
        }

        $responseBag->get('success')->add("- $count records for '$contentTypeName'");
    }
private function importContentType(
        $contentTypeName,
        Bag $importData,
        MutableBag $relationQueue,
        MutableBag $responseBag,
        $overwrite
    ) {
        $count = 0;
        /** @var Repository $repo */
        $repo = $this->em->getRepository($contentTypeName);

        // Build a list of the relationship field names for this ContentType
        $relationFields = MutableBag::from([]);
        $taxonomyFields = MutableBag::from([]);
        foreach ($repo->getClassMetadata()->getFieldMappings() as $field) {
            if (is_a($field['fieldtype'], RelationType::class, true)) {
                $relationFields->add($field['fieldname']);
            }
            if (is_a($field['fieldtype'], TaxonomyType::class, true)) {
                $taxonomyFields->add($field['fieldname']);
            }
        }

        /** @var MutableBag $importDatum */
        foreach ($importData as $importDatum) {
            /** @var Content $entity */
            $entity = $repo->create(['contenttype' => $contentTypeName]);
            $values = $importDatum->toArrayRecursive();
            $entity->setValues($values);
            // Add relations now so they can still be applied if required on re-runs
            $this->addRelations($repo, $relationQueue, $importDatum, $relationFields);
            // Add taxonomy fields
            $this->addTaxonomy($entity, $taxonomyFields, $importDatum);

            $existing = $this->query->getContent($entity->getContenttype() . '/' . $entity->getSlug());
            if ($existing instanceof Content) {
                $entity->setId($existing->getId());
            }
            // If the entity already exists and we're not doing overwrite, exit early
            if ($entity->getId() !== null && $overwrite === false) {
                $responseBag->get('warning')->add(sprintf('ContentType "%s" with slug "%s" exists already! Skipping record.', $contentTypeName, $entity->getSlug()));
                continue;
            }

            $repo->save($entity);
            ++$count;
        }

        $responseBag->get('success')->add("- $count records for '$contentTypeName'");
    }
private function importContentType ( $ contentTypeName , Bag $ importData , MutableBag $ relationQueue , MutableBag $ responseBag , $ overwrite ) { $ count = 0 ; /** @var Repository $repo */ $ repo = $ this -> em -> getRepository ( $ contentTypeName ) ; // Build a list of the relationship field names for this ContentType $ relationFields = MutableBag :: from ( [ ] ) ; $ taxonomyFields = MutableBag :: from ( [ ] ) ; foreach ( $ repo -> getClassMetadata ( ) -> getFieldMappings ( ) as $ field ) { if ( is_a ( $ field [ 'fieldtype' ] , RelationType :: class , true ) ) { $ relationFields -> add ( $ field [ 'fieldname' ] ) ; } if ( is_a ( $ field [ 'fieldtype' ] , TaxonomyType :: class , true ) ) { $ taxonomyFields -> add ( $ field [ 'fieldname' ] ) ; } } /** @var MutableBag $importDatum */ foreach ( $ importData as $ importDatum ) { /** @var Content $entity */ $ entity = $ repo -> create ( [ 'contenttype' => $ contentTypeName ] ) ; $ values = $ importDatum -> toArrayRecursive ( ) ; $ entity -> setValues ( $ values ) ; // Add relations now so they can still be applied if required on re-runs $ this -> addRelations ( $ repo , $ relationQueue , $ importDatum , $ relationFields ) ; // Add taxonomy fields $ this -> addTaxonomy ( $ entity , $ taxonomyFields , $ importDatum ) ; $ existing = $ this -> query -> getContent ( $ entity -> getContenttype ( ) . '/' . $ entity -> getSlug ( ) ) ; if ( $ existing instanceof Content ) { $ entity -> setId ( $ existing -> getId ( ) ) ; } // If the entity already exists and we're not doing overwrite, exit early if ( $ entity -> getId ( ) !== null && $ overwrite === false ) { $ responseBag -> get ( 'warning' ) -> add ( sprintf ( 'ContentType "%s" with slug "%s" exists already! Skipping record.' , $ contentTypeName , $ entity -> getSlug ( ) ) ) ; continue ; } $ repo -> save ( $ entity ) ; ++ $ count ; } $ responseBag -> get ( 'success' ) -> add ( "- $count records for '$contentTypeName'" ) ; }
Perform an import for records under a single ContentType key.

@param string     $contentTypeName
@param Bag        $importData
@param MutableBag $relationQueue
@param MutableBag $responseBag
@param bool       $overwrite

@throws \Bolt\Exception\InvalidRepositoryException
Perform an import for records under a single ContentType key .