You are here

public function WebformCliService::drush_webform_repair in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Commands/WebformCliService.php \Drupal\webform\Commands\WebformCliService::drush_webform_repair()

Overrides WebformCliServiceInterface::drush_webform_repair

See also

\Drupal\webform\Form\AdminConfig\WebformAdminConfigAdvancedForm::submitForm

File

src/Commands/WebformCliService.php, line 837

Class

WebformCliService
Drush version agnostic commands.

Namespace

Drupal\webform\Commands

Code

public function drush_webform_repair() {
  if (!$this
    ->drush_confirm($this
    ->dt("Are you sure you want repair the Webform module's admin settings and webforms?"))) {
    return $this
      ->drush_user_abort();
  }
  module_load_include('install', 'webform');
  $this
    ->drush_print($this
    ->dt('Repairing webform submission storage schema…'));
  _webform_update_webform_submission_storage_schema();
  $this
    ->drush_print($this
    ->dt('Repairing admin configuration…'));
  _webform_update_admin_settings(TRUE);
  $this
    ->drush_print($this
    ->dt('Repairing webform settings…'));
  _webform_update_webform_settings();
  $this
    ->drush_print($this
    ->dt('Repairing webform handlers…'));
  _webform_update_webform_handler_settings();
  $this
    ->drush_print($this
    ->dt('Repairing webform field storage definitions…'));
  _webform_update_field_storage_definitions();
  $this
    ->drush_print($this
    ->dt('Repairing webform submission storage schema…'));
  _webform_update_webform_submission_storage_schema();
  if (\Drupal::moduleHandler()
    ->moduleExists('webform_entity_print')) {
    $this
      ->drush_print($this
      ->dt('Repairing webform entity print settings…'));
    module_load_include('install', 'webform_entity_print');
    webform_entity_print_install();
  }
  $this
    ->drush_print($this
    ->dt('Removing (unneeded) webform submission translation settings…'));
  _webform_update_webform_submission_translation();

  // Validate all webform elements.
  $this
    ->drush_print($this
    ->dt('Validating webform elements…'));
  \Drupal::moduleHandler()
    ->loadAll();

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $render_context = new RenderContext();
  $renderer
    ->executeInRenderContext($render_context, function () {

    /** @var \Drupal\webform\WebformEntityElementsValidatorInterface $elements_validator */
    $elements_validator = \Drupal::service('webform.elements_validator');

    /** @var \Drupal\webform\WebformInterface[] $webforms */
    $webforms = Webform::loadMultiple();
    foreach ($webforms as $webform) {

      // Ignored test files.
      // @todo Determine why these webforms are throwing error via CLI.
      if (in_array($webform
        ->id(), [
        'test_element_managed_file_limit',
        'test_composite_custom_file',
        'test_element_comp_file_plugin',
      ])) {
        continue;
      }
      $messages = $elements_validator
        ->validate($webform);
      if ($messages) {
        $this
          ->drush_print('  ' . $this
          ->dt('@title (@id): Found element validation errors.', [
          '@title' => $webform
            ->label(),
          '@id' => $webform
            ->id(),
        ]));
        foreach ($messages as $message) {
          $this
            ->drush_print('  - ' . strip_tags($message));
        }
      }
    }
  });
  Cache::invalidateTags([
    'rendered',
  ]);

  // @todo Remove when that is fixed in https://www.drupal.org/node/2773591.
  \Drupal::service('cache.discovery')
    ->deleteAll();
}