batch_process example

/** * Fires a batch process without a form submission. * * @return \Symfony\Component\HttpFoundation\RedirectResponse|null * A redirect response if the batch is progressive. No return value otherwise. */
  public function testLargePercentage() {
    batch_test_stack(NULL, TRUE);

    batch_set(_batch_test_batch_5());
    return batch_process('batch-test/redirect');
  }

  /** * Submits a form within a batch programmatically. * * @param int $value * Some value passed to a custom batch callback. * * @return \Symfony\Component\HttpFoundation\RedirectResponse|null * A redirect response if the batch is progressive. No return value otherwise. */
  
    $this->executeSubmitHandlers($form$form_state);

    // If batches were set in the submit handlers, we process them now,     // possibly ending execution. We make sure we do not react to the batch     // that is already being processed (if a batch operation performs a     // \Drupal\Core\Form\FormBuilderInterface::submitForm).     if ($batch = &$this->batchGet() && !isset($batch['current_set'])) {
      // Store $form_state information in the batch definition.       $batch['form_state'] = $form_state;

      $batch['progressive'] = !$form_state->isProgrammed();
      $response = batch_process();
      // If the batch has been completed and _batch_finished() called then       // $batch will be NULL.       if ($batch && $batch['progressive']) {
        return $response;
      }

      // Execution continues only for programmatic forms.       // For 'regular' forms, we get redirected to the batch processing       // page. Form redirection will be handled in _batch_finished(),       // after the batch is processed.     }

    
$cancel_method = \Drupal::service('config.factory')->get('user.settings')->get('cancel_method');

      // Allow other modules to act.
      user_cancel([]$entity->id()$cancel_method);
      // Since user_cancel() is not invoked via Form API, batch processing       // needs to be invoked manually.       $batch =& batch_get();
      // Mark this batch as non-progressive to bypass the progress bar and       // redirect.       $batch['progressive'] = FALSE;
      batch_process();
    }
    else {
      $entity->delete();
    }

    return new ResourceResponse(NULL, 204);
  }

  /** * Gets the collection of entities. * * @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type * The JSON:API resource type for the request to be served. * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return \Drupal\jsonapi\ResourceResponse * The response. * * @throws \Drupal\Core\Http\Exception\CacheableBadRequestHttpException * Thrown when filtering on a config entity which does not support it. */
    $account_data = $this->userData->get('user', $user->id());
    if (isset($account_data['cancel_method']) && !empty($timestamp) && !empty($hashed_pass)) {
      // Validate expiration and hashed password/login.       if ($user->id() && $this->validatePathParameters($user$timestamp$hashed_pass$timeout)) {
        $edit = [
          'user_cancel_notify' => $account_data['cancel_notify'] ?? $this->config('user.settings')->get('notify.status_canceled'),
        ];
        user_cancel($edit$user->id()$account_data['cancel_method']);
        // Since user_cancel() is not invoked via Form API, batch processing         // needs to be invoked manually and should redirect to the front page         // after completion.         return batch_process('<front>');
      }
      else {
        $this->messenger()->addError($this->t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'));
        return $this->redirect('entity.user.cancel_form', ['user' => $user->id()]['absolute' => TRUE]);
      }
    }
    throw new AccessDeniedHttpException();
  }

}
$this->moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');

    // Check translation status of all translatable project in all languages.     // First we clear the cached list of projects. Although not strictly     // necessary, this is helpful in case the project list is out of sync.     locale_translation_flush_projects();
    locale_translation_check_projects();

    // Execute a batch if required. A batch is only used when remote files     // are checked.     if (batch_get()) {
      return batch_process('admin/reports/translations');
    }

    return $this->redirect('locale.translate_status');
  }

  /** * Shows the string search screen. * * @return array * The render array for the string search screen. */
  

  public function updateStatusManually() {
    $this->updateManager->refreshUpdateData();
    $batch_builder = (new BatchBuilder())
      ->setTitle(t('Checking available update data'))
      ->addOperation([$this->updateManager, 'fetchDataBatch'][])
      ->setProgressMessage(t('Trying to check available update data ...'))
      ->setErrorMessage(t('Error checking available update data.'))
      ->setFinishCallback('update_fetch_data_finished');
    batch_set($batch_builder->toArray());
    return batch_process('admin/reports/updates');
  }

}
// Now we rebuild all caches and after that execute the hook_post_update()       // functions.       $batch_builder->addOperation('drupal_flush_all_caches', []);
      foreach ($post_updates as $function) {
        $batch_builder->addOperation('update_invoke_post_update', [$function]);
      }
    }

    batch_set($batch_builder->toArray());

    // @todo Revisit once https://www.drupal.org/node/2548095 is in.     return batch_process(Url::fromUri('base://results'), Url::fromUri('base://start'));
  }

  /** * Finishes the update process and stores the results for eventual display. * * After the updates run, all caches are flushed. The update results are * stored into the session (for example, to be displayed on the update results * page in update.php). Additionally, if the site was off-line, now that the * update process is completed, the site is set back online. * * @param $success * Indicate that the batch API tasks were all completed successfully. * @param array $results * An array of all the results that were updated in update_do_one(). * @param array $operations * A list of all the operations that had not been completed by the batch API. */
Home | Imprint | This part of the site doesn't use cookies.