How to disable Webform's notice message per submission

Created on 22 January 2021, almost 4 years ago
Updated 17 May 2024, 6 months ago

Problem/Motivation

Migrating a site via Migrate Upgrade & Migrate Tools causes it to output a notice for every submission. On a site with 30,000 submissions it outputs 30,000 messages. This is really annoying.

Proposed resolution

Provide an option, or documentation, to disable the submission logging.

Remaining tasks

Work out how to do this.
Document how to turn off the logging or provide an option to do it.

User interface changes

TBD

API changes

TBD

Data model changes

TBD

✨ Feature request
Status

Needs review

Version

1.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Here is a way to do it in a custom module:

    filter_dblog/filter_dblog.services.yml

    services:
      # Overrides the core logger.dblog service.
      logger.dblog:
        class: Drupal\filter_dblog\Logger\DbLog
        arguments: ['@database', '@logger.log_message_parser']
        tags:
          - { name: logger }
          - { name: backend_overridable }
    

    filter_dblog/src/Logger/DbLog.php

    <?php
    
    namespace Drupal\filter_dblog\Logger;
    
    use Drupal\dblog\Logger\DbLog as BaseDbLog;
    
    /**
     * Modifies the logger.dblog service.
     *
     * @see https://drupal.stackexchange.com/a/222123
     * @see https://www.drupal.org/docs/drupal-apis/services-and-dependency-injection/altering-existing-services-providing-dynamic-services
     */
    class DbLog extends BaseDbLog {
    
      /**
       * Prevent logging messages by exact message text.
       */
      const MESSAGE_BLACKLIST = [
        // Cron runs every minute. That's a lot of log messages.
        'Cron run completed.',
      ];
    
      /**
       * Prevent logging messages if they match a regular expression pattern.
       */
      const MESSAGE_BLACKLIST_PATTERNS = [
        '/ webform sent .* email\.$/',
      ];
    
      /**
       * Messages that use content title.
       */
      const TITLE_MESSAGES = [
        '@title completed.',
        '@title created.',
        '@title updated.',
        'Deleted @title.',
        '@title draft created.',
        '@title draft updated.',
      ];
    
      /**
       * Pattern to match a webform submission title.
       */
      const WEBFORM_SUBMISSION_TITLE_PATTERN = '/: Submission #\d+$/';
    
      /**
       * {@inheritdoc}
       */
      public function log($level, $message, array $context = []) {
        // Skip logging blacklisted messages.
        if (in_array($message, self::MESSAGE_BLACKLIST)) {
          return;
        }
    
        // Skip logging messages for content with a matching title pattern.
        if (isset($context['@title']) && preg_match(self::WEBFORM_SUBMISSION_TITLE_PATTERN, $context['@title'])) {
          if (in_array($message, self::TITLE_MESSAGES)) {
            return;
          }
        }
    
        // Skip logging messages matching a blacklisted pattern.
        foreach (self::MESSAGE_BLACKLIST_PATTERNS as $pattern) {
          if (preg_match($pattern, $message)) {
            return;
          }
        }
    
        // Log the message.
        parent::log($level, $message, $context);
      }
    
    }
    
  • Note that since this only overrides the DB logger, messages will still show up in the CLI. I'm not sure how to override all of the loggers at once but you could override SysLog was well.

    I noticed there's a WebformSubmissionLogLogger which may be of use to override.

    Also, I did this by message in order to be reusable, but there's also a message "channel" and other context parameters that can be checked for in order to skip logging.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I was able to disable the message using this line in my settings.php file:

    $settings['locale_custom_strings_en'][''] = [
      // Disable the message logged when Webform submissions are migrated. Remove
      // this line after the site migration is finished.
      '@title updated.' => '',
    ];
    
  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Now as a patch file to add details to the README.md about it.

  • Status changed to RTBC 8 months ago
  • Status changed to Needs work 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    So, that didn't work correctly - when I was doing limited testing on a site where I was manually rolling back a few records and importing them again it wasn't displaying the message, but when I ran the full from-scratch migration the message was still displayed :-\

  • πŸ‡ΊπŸ‡ΈUnited States firewaller

    Yeah, #4 doesn't work for me on a fresh migration.

    FYI that message is getting logged here: https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/WebformSubmi...

    Based on that logic above, the only way to silence these messages in CLI was to disable the "results_disabled" setting in each form temporarily. However, now I'm seeing the error from here: https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Plugin/Webfo...

    That's caused by this logic: https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Plugin/Webfo...

    So I don't think that's a viable approach either.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Temporary workaround to disable the message in Webform; a hack, if you will.

  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Never mind #9, this one works.

Production build 0.71.5 2024