You are here

public function UpdateReady::submitForm in Automatic Updates 8.2

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/UpdateReady.php, line 98

Class

UpdateReady
Defines a form to commit staged updates.

Namespace

Drupal\automatic_updates\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $session = $this
    ->getRequest()
    ->getSession();

  // Store maintenance_mode setting so we can restore it when done.
  $session
    ->set('maintenance_mode', $this->state
    ->get('system.maintenance_mode'));
  if ($form_state
    ->getValue('maintenance_mode') === TRUE) {
    $this->state
      ->set('system.maintenance_mode', TRUE);

    // @todo unset after updater. After db update?
  }
  $batch = (new BatchBuilder())
    ->setTitle($this
    ->t('Apply updates'))
    ->setInitMessage($this
    ->t('Preparing to apply updates'))
    ->addOperation([
    BatchProcessor::class,
    'commit',
  ])
    ->addOperation([
    BatchProcessor::class,
    'clean',
  ])
    ->setFinishCallback([
    BatchProcessor::class,
    'finishCommit',
  ])
    ->toArray();
  batch_set($batch);
}