public UpdateManager::fetchDataBatch(&$context)
Processes a step in batch for fetching available update data.
Parameters
array $context: Reference to an array used for Batch API storage.
Overrides UpdateManagerInterface::fetchDataBatch
File
- core/modules/update/src/UpdateManager.php, line 185
Class
- UpdateManager
- Default implementation of UpdateManagerInterface.
Namespace
Drupal\update
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | public function fetchDataBatch(& $context ) { if ( empty ( $context [ 'sandbox' ][ 'max' ])) { $context [ 'finished' ] = 0; $context [ 'sandbox' ][ 'max' ] = $this ->updateProcessor->numberOfQueueItems(); $context [ 'sandbox' ][ 'progress' ] = 0; $context [ 'message' ] = $this ->t( 'Checking available update data ...' ); $context [ 'results' ][ 'updated' ] = 0; $context [ 'results' ][ 'failures' ] = 0; $context [ 'results' ][ 'processed' ] = 0; } // Grab another item from the fetch queue. for ( $i = 0; $i < 5; $i ++) { if ( $item = $this ->updateProcessor->claimQueueItem()) { if ( $this ->updateProcessor->processFetchTask( $item ->data)) { $context [ 'results' ][ 'updated' ]++; $context [ 'message' ] = $this ->t( 'Checked available update data for %title.' , array ( '%title' => $item ->data[ 'info' ][ 'name' ])); } else { $context [ 'message' ] = $this ->t( 'Failed to check available update data for %title.' , array ( '%title' => $item ->data[ 'info' ][ 'name' ])); $context [ 'results' ][ 'failures' ]++; } $context [ 'sandbox' ][ 'progress' ]++; $context [ 'results' ][ 'processed' ]++; $context [ 'finished' ] = $context [ 'sandbox' ][ 'progress' ] / $context [ 'sandbox' ][ 'max' ]; $this ->updateProcessor->deleteQueueItem( $item ); } else { // If the queue is currently empty, we're done. It's possible that // another thread might have added new fetch tasks while we were // processing this batch. In that case, the usual 'finished' math could // get confused, since we'd end up processing more tasks that we thought // we had when we started and initialized 'max' with numberOfItems(). By // forcing 'finished' to be exactly 1 here, we ensure that batch // processing is terminated. $context [ 'finished' ] = 1; return ; } } } |
Please login to continue.