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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 2.x Comparechanges, plain diff MR !11
  • 1 hidden branch
  • 3414182 Comparecompare

Comments

endless_wander created an issue. See original summary.

laboratory.mike’s picture

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.

flyke’s picture

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.

use Drupal\Core\Datetime\DrupalDateTime;

/**
 * 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();
}
drupgirl’s picture

+1 for this essential function being incorporated.

nsalves’s picture

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

nsalves’s picture

Status: Active » Needs review
sjerdo’s picture

Status: Needs review » Needs work

@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.

drunxfish made their first commit to this issue’s fork.

nsalves’s picture

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

nsalves’s picture

Status: Needs work » Needs review
sjerdo’s picture

Thanks for providing a patch @nsalves

To stay in line with Drupal Core (eg temporary files retention), I've asked @drunxfish to update the MR accordingly, including updating the code style issues.

This wille change the setting from a string to an integer (`-90 days` => `7776000`)

drunxfish’s picture

Version: 2.0.0 » 2.x-dev

sjerdo changed the visibility of the branch 3414182 to hidden.

sjerdo’s picture

Status: Needs review » Reviewed & tested by the community

  • sjerdo committed 20b1352c on 2.x authored by nsalves
    [#3414182] feat: Periodic cleanup of emails
    
    By: chrisla
    By: flyke
    By:...
sjerdo’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • sjerdo committed 5d530a2e on 2.x authored by nsalves
    [#3414182] feat: Periodic cleanup of emails
    
    By: chrisla
    By: flyke
    By:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

chrisla’s picture

Any chance of this being added to a release soon?

sjerdo’s picture

I have tagged a new release 2.2.0 containing this cleanup feature