I think it would be smart to have an option to remove messages completely from the tables after a month because who really needs them. I just fear if my community grows large enough that the space used for messages could be enormous. I see the function _privatemsg_prune() which archives messages after a month. Is there a way to make this simply delete them? Or maybe give admin an option in the settings page?

Thanks

Comments

mindless’s picture

the module doesn't do anything with privatemsg_archive table except add data... so, you can delete the contents of the table anytime you like. you can also comment out the one line in privatemsg.module that does INSERT INTO {privatemsg_archive} and now old messages are simply deleted instead of archived.

mstef’s picture

2 concerns..heres the code for that function first..

function _privatemsg_prune() {
// move deleted message older than 1 month to archive table, and optimize table
$result = db_query('SELECT * FROM {privatemsg} WHERE author_del = 1 AND recipient_del = 1 AND timestamp < %d', time() - 3600*24*30);
while ($message = db_fetch_object($result)) {
db_query("INSERT INTO {privatemsg_archive} (id, author, recipient, subject, message, timestamp, hostname, format, folder) VALUES (%d, %d, %d, '%s', '%s', %d, '%s', %d, %d)", $message->id, $message->author, $message->recipient, $message->subject, $message->message, $message->timestamp, $message->hostname, $message->format, $message->folder);
db_query('DELETE FROM {privatemsg} WHERE id = %d', $message->id);
}

// this is MySQL-specific
if (!strncmp($GLOBALS['db_type'], 'mysql', 5)) {
db_query('OPTIMIZE TABLE {privatemsg}');
}
}

-----

First the comment says '// move deleted message older than 1 month to archive table, and optimize table'

Most importantly, "move deleted message" .. Does that mean messages that are sitting in the inbox after a month are gone, messages that the user PRESSED delete on, read or unread, etc? If it is any message older than one month, then its perfect..

ALSO, just to make sure: I should remove the db_query("INSERT INTO {privatemsg_archive} function in the while loop to achieve this right?

THANKS

mindless’s picture

Yes, that's the right line with {privatemsg_archive}.

Which messages to delete is currently setup to not delete very many.. in the query at the start of "prune":
author_del = 1 AND recipient_del = 1
This portion of the query means only select messages that the recipient has deleted AND the sender has deleted (from their "Sent messages" folder). I don't think many users bother to go into Sent messages and delete stuff, so on most sites probably not many messages make it into the archive.
You can adjust that query as desired.. remove "author_del = 1 AND" to delete msgs older than a month that the receipient has deleted. Also remove "recipient_del = 1 AND" to remove all messages older than a month, deleted or not.

mstef’s picture

thank you very much

berdir’s picture

Status: Active » Closed (fixed)

I apologize for pinging the participants, I'm closing out old issues.
Privatemsg already implements some of these features. Please file a
feature request against the latest DRUPAL-6 version if still relevant.