Comments

rickmanelius’s picture

That would be awesome... I'd like to flush for development purposes.

miro_dietiker’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Category: support » feature

Might be a button on the admin settings page. Pushing into current feature branch.

Currently, just flush the table of maillog.

chrisjlee’s picture

@miro dietiker Is there a specific table or tables that one should flush?

miro_dietiker’s picture

Table name is {maillog}

pluess’s picture

Assigned: Unassigned » pluess
Status: Active » Needs review
StatusFileSize
new1.53 KB

This little patch addes a "Clear all maillog entries" button to the admin panel.

jkingsnorth’s picture

Issue summary: View changes
Status: Needs review » Needs work

Since this is a destructive action shouldn't there also be a confirmation step?

miro_dietiker’s picture

Assigned: pluess » Unassigned
waverate’s picture

It would be great to have this feature request implemented.

waverate’s picture

Patch #5 didn't clear the table me in D7.36 and maillog-7.x-1.x-dev.

From function db_truncate, it looks like you need to call execute on the object.

The following worked for me:

function maillog_clear_log() {
  $result = db_truncate('maillog')->execute();
  drupal_set_message(t("All maillog entries deleted."));
}
rhabbachi’s picture

Component: Documentation » Code
Status: Needs work » Needs review
StatusFileSize
new877 bytes

Re-rolled the patch with the suggestion from #9

dkinzer’s picture

Status: Needs review » Reviewed & tested by the community

Just tried the patch at #10 locally and it works. We'll be using it in or testing environment.

miro_dietiker’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs work

As stated, It's a delete everything functionality, so we want to have a confirmation form. We won't add this without confirmation.

Let's have it in 8.x first.

edurenye’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.08 KB
new4.06 KB
new28.91 KB

Done with confirmation and added tests.

The last submitted patch, 13: clear_maillog-1421886-13-test_only.patch, failed testing.

miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

Yeah thx, this looks nice to me!

rosk0’s picture

  1. +++ b/src/Form/MaillogClearConfirmForm.php
    @@ -0,0 +1,64 @@
    +    return t('All maillog database entries will be deleted. This action cannot be undone.');
    

    Should be $this->t(), no?

  2. +++ b/src/Form/MaillogClearConfirmForm.php
    @@ -0,0 +1,64 @@
    +    drupal_set_message(t("All maillog entries have been deleted."));
    

    Same as above.

  3. +++ b/src/Form/MaillogSettingsForm.php
    @@ -37,6 +37,17 @@ class MaillogSettingsForm extends ConfigFormBase {
    +      '#title' => t('Clear Maillog'),
    

    Same.

  4. +++ b/src/Form/MaillogSettingsForm.php
    @@ -37,6 +37,17 @@ class MaillogSettingsForm extends ConfigFormBase {
    +      '#value' => t('Clear all maillog entries'),
    

    Same.

edurenye’s picture

Done those changes.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thx!

The question mark was missing in the question sentence.

Status: Fixed » Closed (fixed)

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

jstamper’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
StatusFileSize
new2.24 KB

I've created a D7 patch for this using confirm_form. If you want me to open a new issue I can do that.

spanners’s picture

Tried applying patch from #21 and got...

patching file maillog.module
Hunk #1 succeeded at 70 (offset 11 lines).
Hunk #2 FAILED at 148.
Hunk #3 succeeded at 151 (offset -23 lines).
1 out of 3 hunks FAILED -- saving rejects to file maillog.module.rej

The .rej file contains...

***************
*** 138,143 ****
}

/**
* Display a maillog record.
*
* @param array $maillog
--- 148,173 ----
}

/**
+ * Confirm form that deletes all entries from the maillog table
+ */
+ function maillog_maillog_clear_log_form($form, &$form_state) {
+ $question = t('Are you sure you want to clear all the maillog entries');
+ $path = 'admin/config/development/maillog';
+ $description = t('All maillog database entries will be deleted. This action cannot be undone.');
+
+ return confirm_form($form, $question, $path, $description);
+ }
+
+ /**
+ * Confirm form that deletes all entries from the maillog table
+ */
+ function maillog_maillog_clear_log_form_submit($form, &$form_state) {
+ db_truncate('maillog')->execute();
+ drupal_set_message(t("All maillog entries have been deleted."));
+ drupal_goto('admin/config/development/maillog');
+ }
+
+ /**
* Display a maillog record.
*
* @param array $maillog

waverate’s picture

Patch #21 applies cleanly to 7.x-1.x-dev (21 May 2016).

However, there is a typo on line 128; missing $:

It should read

  $result = db_query("DELETE FROM {maillog} WHERE $idmaillog = :id", array(':id' => $idmaillog));
rick hood’s picture

StatusFileSize
new2.45 KB

I lost the clear all maillog button after updating to this release: https://www.drupal.org/project/maillog/releases/7.x-1.0-rc1
I was able to add it back using code from #21 1421886-clear-maillog.patch
I created a patch with those changes.
It applied OK for me to 7.x-1.0-rc1 using git apply clear_maillog-1421886-24.patch

robcarr’s picture

StatusFileSize
new2.11 KB

What a great patch. A site of mine kept crashing because the database was about 80Mb (should be just a few Mb) and MySQL kept running out of memory . The maillog table was most of that bulk and now works fine on 7.x-1.0-rc1

I rerolled the patch that Rick rolled at #24 to strip the file path down (it wouldn't apply as I don't put my Drupal site under /docroot)

robcarr’s picture

I've created a separate issue so that the 7.x patch can be reviewed and committed #3187649: Truncate Maillog Table

bardiuk’s picture

For whoever who will google this like me: https://www.drupal.org/project/maillog/issues/3341880

The list is a separate thing and the configuration is at the other page. In the configuration you can delete logs.

Configuration > Development > Maillog settings