Periodic cleanup of emails does not exist in 2.0

Created on 12 January 2024, over 1 year ago

Problem/Motivation

The feature described here -- https://www.drupal.org/project/mail_safety/issues/2894814 β†’ -- and added to Drupal 7 release does not exist in more recent versions.

"After enabling saving to the dashboard, mails will stack up and are never cleaned up. This can cause an the database to be overloaded with old mails. Feature request to add a periodic cron clean up, based on the settings the user can provide."

Proposed resolution

Add same functionality to most recent release

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada endless_wander

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

Merge Requests

Comments & Activities

  • Issue created by @endless_wander
  • πŸ‡ΊπŸ‡ΈUnited States laboratory.mike

    Currently I have this in a cron job:

    $now = new DrupalDateTime('-90 days');
    $delete = \Drupal::database()->delete('mail_safety_dashboard');
    $delete->condition('sent', $now->getTimestamp(), '<');
    $delete->execute();
    

    We could set this up in a container with dependency injection, and add a config to set the retention time.

  • πŸ‡§πŸ‡ͺBelgium flyke

    Thank you laboratory.mike, your solution is a perfect stop gap until we get an actual settings page and this functionality incorporated into the module itself.

    /**
     * Implements hook_mail().
     */
    function mymodule_helper_cron() {
      // Delete old mail logs.
      $now = new DrupalDateTime('-90 days');
      $delete = \Drupal::database()->delete('mail_safety_dashboard');
      $delete->condition('sent', $now->getTimestamp(), '<');
      $delete->execute();
    }
  • πŸ‡ΊπŸ‡ΈUnited States drupgirl

    +1 for this essential function being incorporated.

  • πŸ‡΅πŸ‡ΉPortugal nsalves

    Here's a patch that adds the functionality. It adds a cron job that reads an offset value configured in the settings page of the module. If no value is configured the cron does nothing and everything remains as it is

  • πŸ‡΅πŸ‡ΉPortugal nsalves
  • πŸ‡³πŸ‡±Netherlands sjerdo Haarlem

    @nsalves Thanks for providing a patch. Could you create a MR for this change?

    There are some code style issues with this patch (in file `mail_safety.module`) which needs attention before we can merge this into the main branch: indent and function doc-block refers to the incorrect hook.

  • First commit to issue fork.
  • Merge request !11[#3414182] adds cron to delete old entries β†’ (Merged) created by nsalves
  • πŸ‡΅πŸ‡ΉPortugal nsalves

    Hello sjerdo, thanks for the feedback and apologies for the oversight. Merge request opened.
    Thanks

  • Pipeline finished with Success
    6 days ago
    Total: 151s
    #593820
  • πŸ‡΅πŸ‡ΉPortugal nsalves
  • Pipeline finished with Success
    5 days ago
    Total: 144s
    #594902
Production build 0.71.5 2024