Hi,

is there a possibility to delete all (read) messages?

Or, as a feature request, i think it would be a great option to be able to automaticly delete read messages after x days.

Thanks for this great module,

Nilsja

Comments

berdir’s picture

We decided against doing something like this.

Instead, #69856: Message limits, allows you do limit how many messages a user can have, which gives them control over which they want to delete.

You can delete messages/threads with http://blog.worldempire.ch/de/api/function/privatemsg_thread_change_dele... and http://blog.worldempire.ch/de/api/function/privatemsg_message_change_del.... But to get these, you need a custom query, our query builder currently does not support that (for all users, it does for a single user).

nilsja’s picture

thank you for the infos. in my case it is not a quota, but a security/privacy concern. i want to be able to delete all messages with one click.

so perhaps is a delete script directly via mysql the better way? is their any danger by deleting the complete pm_index pm_messages and pm_attachments? or would unsinstalling the module also do this?

TRUNCATE TABLE `pm_index`
TRUNCATE TABLE `pm_messages`
TRUNCATE TABLE `pm_attachments`

berdir’s picture

Status: Active » Fixed

Yes, uninstall/re-install would do the same thing. Depending on the number of modules you've installed, there might also be other tables (like tags)
That will obviously delete everything.

nilsja’s picture

here is my solution: i activated the php filter module. don't forget to allow this in your /admin/settings/filters, and only for the admin user.
then i created a block called "red button" which is only visible to user role webteam and inserted the following php code:

<?php
$passw = $_POST["del"];

  if($passw == "yourpassword") // enter the password to delete all messages here
  {
    $sql = 'TRUNCATE TABLE `pm_attachments`';  //if you dont use privatemsg attachments you can delete this and the following 3 lines.
    $result = db_query(db_rewrite_sql($sql));
    $files = glob("/.../sites/default/files/.../*"); //absolute php path you configured in /admin/settings/messages
    foreach($files as $datei) unlink($datei);

    $sql = 'TRUNCATE TABLE `pm_index`'; 
    $result = db_query(db_rewrite_sql($sql));

    $sql = 'TRUNCATE TABLE `pm_message`'; 
    $result = db_query(db_rewrite_sql($sql));
    echo "<b>done.</b><br>";

    drupal_set_message(t("deleting attachments in DB ...<br>deleting attachments from filesystem ...<br>deleting messages from db...<br><b>All messages successfully deleted</b>.")); 

  }

  else
  {
     print "To delete all messages enter the password here:";
  print "<form action=\"\" method=\"post\"><input type=\"password\" size=\"10\" name=\"del\" autocomplete=\"off\">  <input type=\"submit\" value=\"baaam\">  </form><br><br>";
  }
?>

the success messages are kind of useless because there is no error handling.

i think this is really ugly code. sorry, i'm not a programmer. but it works for me. so if anybody wants to improve it: missing wrong password message and error handling...

naheemsays’s picture

I would not recommend the use of the php filter module as using php in blocks/nodes could be a recipe for disaster.

You could do as Berdir mentioned in comment 3 - disable and then uninstall the module. That will delete all settings and tables linked to privatemsg. When you re-enable, everything would be recreated.

nilsja’s picture

i have to limit it to a role, so the uninstall variant doesnt work for me. the webteam role should not be able to administer all modules...

berdir’s picture

Yes, but still, placing PHP code in blocks is a very bad idea you should instead create a simple module (or place it in a existing one) and provide a block/link through that.

nilsja’s picture

ok, you insisted :)

here is the lousy beginning of my first module (do not install it!):

privatemsgdel.info:

; $Id$
name = Delete all private messages
description = This quick&dirty module provides a block for deleting all messages of the privatemsg module. Only certain roles should be allowed to do this.
core = 6.x
dependencies[] = privatemsg
package = Mail

privatemsgdel.module:

<?php
// $Id$

/**
* Display help and module information
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg() function
* @return help text for the path
*/
function privatemsgdel_help($path, $arg) {
  $output = '';  //declare your output variable
  switch ($path) {
    case "admin/help#privatemsgdel":
      $output = '<p>'.  t("Deletes all Privatemsg messages of all users.") .'</p>';
      break;
  }
  return $output;
} // function privatemsgdel_help



/**
* Valid permissions for this module
* @return array An array of valid permissions for the onthisdate module
*/
function privatemsgdel_perm() {
  return array('Delete all Privatemsg messages of all users.');
} // function privatemsgdel_perm()



function privatemsgdel_block($op = 'list', $delta = '', $edit = array()) {
  // The $op parameter determines what piece of information is being requested.
  switch ($op) {
    case 'list':
      // If $op is "list", we just need to return a list of block descriptions.
      // This is used to provide a list of possible blocks to the administrator;
      // end users will not see these descriptions.
      $blocks['configurable-text'] = array(
        'info'       => t('Delete all privatemsgs'), //Blockname in admin/build/blocks
      );
      // A block can provide default settings. In this case we'll enable the
      // block and make it visible only on the 'node/*' pages.
      $blocks['empty'] = array(
        'info'       => t('Example: empty block'),
        'status'     => TRUE,
        'weight'     => 0,
        'visibility' => 1,
        'pages'      => '',
      );
      return $blocks;
    case 'configure':
      // If $op is "configure", we need to provide the administrator with a
      // configuration form. The $delta parameter tells us which block is being
      // configured. In this example, we'll allow the administrator to customize
      // the text of the first block.
      $form = array();
      if ($delta == 'configurable-text') {
        // All we need to provide is a text field, Drupal will take care of
        // the other block configuration options and the save button.
        $form['block_example_string'] = array(
          '#type' => 'textfield',
          '#title' => t('Delete all Privatemsgs'),
          '#size' => 60,
          '#description' => t('<b>test</b>'),
          '#default_value' => variable_get('block_example_string',  t('Some example content.')),
        );
      }
      return $form;
    case 'save':
      // If $op is "save", we need to save settings from the configuration form.
      // Since the first block is the only one that allows configuration, we
      // need to check $delta to make sure we only save it.
      if ($delta == 'configurable-text') {
        // Have Drupal save the string to the database.
        variable_set('block_example_string', $edit['block_example_string']);
      }
      return;
    case 'view':
      // If $op is "view", then we need to generate the block for display
      // purposes. The $delta parameter tells us which block is being requested.
      switch ($delta) {
        case 'configurable-text':
          // The subject is displayed at the top of the block. Note that it
          // should be passed through t() for translation.
          $block['subject'] = t('Title of configurable-text block');
          // The content of the block is typically generated by calling a custom
          // function.
          $block['content'] = "inhalte...configurable-text"; 
          break;

      }
      return $block;
  }
}

function privatemsgdel_doit() {
    $sql = 'TRUNCATE TABLE `pm_attachments`';  //if you dont use privatemsg attachments you can delete this and the following 3 lines.
    $result = db_query(db_rewrite_sql($sql));
    $files = glob("/.../sites/default/files/.../*"); //absolute php path you configured in /admin/settings/messages
    foreach($files as $datei) unlink($datei);
    $sql = 'TRUNCATE TABLE `pm_index`';
    $result = db_query(db_rewrite_sql($sql));
    $sql = 'TRUNCATE TABLE `pm_message`';
    $result = db_query(db_rewrite_sql($sql));

  }
}


function privatemsgdel_done() {
drupal_set_message(t("deleting attachments in DB ...<br>deleting attachments from filesystem ...<br>deleting messages from db...<br><b>All messages successfully deleted</b>."));
}

// from here on i'm totally lost...

$passw = $_POST["del"]; 

if($passw == "testa") //should be configureable in the block settings...
  {
// call function doit()
// call funtion done() if doit() returns ...
}

else
  {
     print "To delete all messages enter the password here:";
  print "<form action=\"\" method=\"post\"><input type=\"password\" size=\"10\" name=\"del\" autocomplete=\"off\">  <input type=\"submit\" value=\"baaam\">  </form><br><br>";
  } 

perhaps somebody wants to finish it, or teach me how to do it...

nilsja

Status: Fixed » Closed (fixed)

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

mardok’s picture

rikimaru0007’s picture

Hello, in Site Configuration > Privatemsg > Private Messages (tab)
How about the checkbox, Flush (deleted messages)

By default, deleted messages are only hidden from the user but still stored in the database. These settings control if and when messages should be removed

I would like to know the manual flush in database
by using this code below in SQL tab phpMyAdmin

db_query("TRUNCATE {what?!}");

These are the available replacement for the what?! above.
pm_block_user
pm_email_notify
pm_index
pm_message
pm_tags
pm_tag_index

I'm looking for... Something like pm_deleted but it hasn't.