When syncing content on prod/dev environment in large sites, very often developers need to sync only last XX items of some entity type. Because all content items are too much and export/import process will be very slow.

Can we add options for limit count of exported content items per entity/bundle type, and sort order?

Eg, export only top 100 entities with type 'node' & bundle 'article', ordered by updated DESC field.

Comments

Murz created an issue. See original summary.

aleada’s picture

Hi,
This would be a nice feature for this module...

I tried to solve this problem by adding a condition in the query of the submitForm function (src/Form/ContentExportForm.php)

 public function submitForm(array &$form, FormStateInterface $form_state) {
    // Delete the content tar file in case an older version exist.
    file_unmanaged_delete($this->getTempFile());

    //Set batch operations by entity type/bundle
    $entities_list = [];
    $entity_type_definitions = $this->entityTypeManager->getDefinitions();
    foreach ($entity_type_definitions as $entity_type => $definition) {
      $reflection = new \ReflectionClass($definition->getClass());
      if ($reflection->implementsInterface(ContentEntityInterface::class)) {
		if( $entity_type != 'node' && $entity_type != 'file' ){
			continue;  
//SKIP ENTITY TYPES FROM EXPORT (blocks,taxonomy_term etc)
		}
		$entities = $this->entityTypeManager->getStorage($entity_type)
                                            ->getQuery()
					->condition('created', 1568494800, '>')  		
//ADDED DATE CREATED CONDITION									
					->execute();
        foreach ($entities as $entity_id) {
          $entities_list[] = [
            'entity_type' => $entity_type,
            'entity_id' => $entity_id,
          ];
        }
      }
    }
    if (!empty($entities_list)) {
      $batch = $this->generateBatch($entities_list);
      batch_set($batch);
    }
  }

Hope this helps.

blanca.esqueda’s picture

Version: 8.x-2.x-dev » 4.0.x-dev
Component: Code » Export/Import