src/Batch/NT8PropertyBatch.php
public static function propertyBatchLoad(int $batch_size = 8, int $modify_replace = 0) {
    $batchSizeList = [
      1 => 1,
      2 => 2,
      3 => 4,
      4 => 8,
      5 => 16,
      6 => 32,
      7 => 64,
      8 => 128,
      9 => 256,
    ];

    // Get list of properties to reload.
    $per_page = $batchSizeList[$batch_size] ?? 128;

    // Get page count.
    $first_page = \Drupal::service('nt8tabsio.tabs_service')->get(
      "property",
      [
        "page" => 1,
        "pageSize" => $per_page
      ]
    );

    $first_page = json_decode($first_page);

    $search_instance_id = $first_page->searchId;
    $total_results = $first_page->totalResults;

    $batch = [
      'title' => t('Loading all properties from API.'),
      'operations' => [],
      'progress_message' => t('Processed @current out of @total.'),
      'finished' => '\Drupal\nt8property\Batch\NT8PropertyBatch::propertyBatchLoadFinishedCallback',
    ];

    $pages = ceil($total_results / $per_page);
    $last_page = $total_results - ($per_page * ($pages - 1));

    for ($page_counter = 0; $page_counter < $pages; $page_counter++) {
      $batch["operations"][] = [
        '\Drupal\nt8property\Batch\NT8PropertyBatch::propertyBatchLoadCallback',
        [
          $page_counter,
          [
            'per_page' => $per_page,
            'last_page' => $last_page,
            'pages' => $pages,
          ],
          $search_instance_id,
          $modify_replace,
        ],
      ];
    }

    batch_set($batch);
  }
public static function propertyBatchLoad(int $batch_size = 8, int $modify_replace = 0) {
    $batchSizeList = [
      1 => 1,
      2 => 2,
      3 => 4,
      4 => 8,
      5 => 16,
      6 => 32,
      7 => 64,
      8 => 128,
      9 => 256,
    ];

    // Get list of properties to reload.
    $per_page = $batchSizeList[$batch_size] ?? 128;

    // Get page count.
    $first_page = \Drupal::service('nt8tabsio.tabs_service')->get(
      "property",
      [
        "page" => 1,
        "pageSize" => $per_page
      ]
    );

    $first_page = json_decode($first_page);

    $search_instance_id = $first_page->searchId;
    $total_results = $first_page->totalResults;

    $batch = [
      'title' => t('Loading all properties from API.'),
      'operations' => [],
      'progress_message' => t('Processed @current out of @total.'),
      'finished' => '\Drupal\nt8property\Batch\NT8PropertyBatch::propertyBatchLoadFinishedCallback',
    ];

    $pages = ceil($total_results / $per_page);
    $last_page = $total_results - ($per_page * ($pages - 1));

    for ($page_counter = 0; $page_counter < $pages; $page_counter++) {
      $batch["operations"][] = [
        '\Drupal\nt8property\Batch\NT8PropertyBatch::propertyBatchLoadCallback',
        [
          $page_counter,
          [
            'per_page' => $per_page,
            'last_page' => $last_page,
            'pages' => $pages,
          ],
          $search_instance_id,
          $modify_replace,
        ],
      ];
    }

    batch_set($batch);
  }
public static function propertyBatchLoad ( int $ batch_size = 8 , int $ modify_replace = 0 ) { $ batchSizeList = [ 1 => 1 , 2 => 2 , 3 => 4 , 4 => 8 , 5 => 16 , 6 => 32 , 7 => 64 , 8 => 128 , 9 => 256 , ] ; // Get list of properties to reload. $ per_page = $ batchSizeList [ $ batch_size ] ?? 128 ; // Get page count. $ first_page = \ Drupal :: service ( 'nt8tabsio.tabs_service' ) -> get ( "property" , [ "page" => 1 , "pageSize" => $ per_page ] ) ; $ first_page = json_decode ( $ first_page ) ; $ search_instance_id = $ first_page -> searchId ; $ total_results = $ first_page -> totalResults ; $ batch = [ 'title' => t ( 'Loading all properties from API.' ) , 'operations' => [ ] , 'progress_message' => t ( 'Processed @current out of @total.' ) , 'finished' => '\Drupal\nt8property\Batch\NT8PropertyBatch::propertyBatchLoadFinishedCallback' , ] ; $ pages = ceil ( $ total_results / $ per_page ) ; $ last_page = $ total_results - ( $ per_page * ( $ pages - 1 ) ) ; for ( $ page_counter = 0 ; $ page_counter < $ pages ; $ page_counter ++ ) { $ batch [ "operations" ] [ ] = [ '\Drupal\nt8property\Batch\NT8PropertyBatch::propertyBatchLoadCallback' , [ $ page_counter , [ 'per_page' => $ per_page , 'last_page' => $ last_page , 'pages' => $ pages , ] , $ search_instance_id , $ modify_replace , ] , ] ; } batch_set ( $ batch ) ; }
Instantiates and handles a Drupal batch property load.

@param int $batch_size
The number of properties to request & process per search.
The batch size goes up in a 2 ^ n scale.
@param int $modify_replace
Modify the existing nodes or create new ones (deleting the current).
0 => Modify, 1 => Replace.
Instantiates and handles a Drupal batch property load .