You are here

public function LoggerClearForm::submitForm in MongoDB 8

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/LoggerClearForm.php, line 66
Contains \Drupal\mongodb\Logger\LoggerClearForm.php

Class

LoggerClearForm
Provides the form that clears out the log.

Namespace

Drupal\mongodb\Form

Code

public function submitForm(array &$form, array &$form_state) {
  $logger = $this->logger;
  try {

    // Drop the watchdog collection.
    $this->logger
      ->templatesCollection()
      ->drop();

    // Recreate the indexes.
    $this->logger
      ->ensureIndexes();

    // Drop the event collections.
    foreach ($logger
      ->templatesCollection()->db
      ->listCollections() as $event_collection) {
      if (preg_match($logger::EVENT_COLLECTIONS_PATTERN, $event_collection
        ->getName())) {
        $event_collection
          ->drop();
      }
    }
    drupal_set_message(t('MongoDB log cleared.'));
  } catch (Exception $e) {
    drupal_set_message(t('An error occured while clearing the MongoDB log.'), 'error');
  }
}