![]() |
Here is a simple script that I just hacked up that will delete all private messages older than 60 days old. Just copy the code to a new file, put in your forum root directory, and run it.
PHP Code:
|
What do you mean put in "a" file? a php file? Another question, are you saying I would have to run this file everytime I wanted it to delete the messages or do I just have to run it once? If so is there a way to get it to automatically do this instead of needing to be manually ran?
Thanks for any info you can provide. :tu: |
It would need to be executed...every time it would delete ALL PMs (for all users) older than 60 days. If you wanted it run regularly without your intervention, you'd need to ask your webhost about setting up a crontab.
|
What version is this for?
|
It's simple enough that I think it'll work for any version that supports the PM system.
|
TY!! TWT :)
|
Can we get something like this that does it automatically?
|
Lubi, just create a cron job for the script.
Amy |
Which numbers would I change if I wanted a figure other than 60 days? Say 6 months? (180 days)
|
anyone have any idea on which number to change? The last 60?
|
Quote:
So, 60*60*24 means a day... :) Any further problem ? :bunny: P.S.: the multiplier operator has the commutative property... :p |
can anyone confirm if this hack does what its suppose to do? Meaning does the above code guarantee to delete PMs longer than 60 days?
|
works fine for me
|
If you don't think it will work (or just want to get a number) you can comment out the delete line and use these to see the total rows that will be deleted:
PHP Code:
|
Works pretty good. Thanks
|
This would be cool is you can add this into the Admin cp ...
|
Does this work on version 2.3.0?
Does it empty out all the folders? How can I make it delete the PMs older than one month? Thank you! |
Amy,
I took your script and made an option in the Admin CP to run it. It seemed to work, but when I ran it all I got was a blank screen. I was wondering if there is a way to add something to the end of the script so that when it is finished running it would return you to say the PM stats query? I am not that versed in php, to do the coding myself . Thanks |
Quote:
PHP Code:
|
I'd like to adapt this to work with version 3.60.
The existing version shows: Code:
<?php
Can I just duplicate the a$ query above to prune each of those variables? Or is that unnecessary or redundant? |
Duplicating the above won't work. You can look at the usertools.php file in the admincp to see how vbulletin deletes sent pms or all pms, which may help you get started.
It looks like a similar query will work, but all three are linked together. Code:
pm |
Got some help on another forum which got me this far:
Code:
<?php However, this doesn't work. I get Quote:
Code:
$a = $DB_site->query("SELECT COUNT(*) AS oldpms FROM vbpm WHERE pmtextid IN(SELECT pmtextid FROM vbpmtext WHERE dateline < $time)"); |
I believe the error is caused by the
Code:
$DB_site->query Try this: Code:
$a = $db->query_read("SELECT COUNT(*) AS oldpms FROM vbpm WHERE pmtextid IN(SELECT pmtextid FROM vbpmtext WHERE dateline < $time)"); |
Better.
Code:
<?php Quote:
|
That is odd. I tried running the first query manually setting a time so it was 1 pm that is in my inbox and outbox. The count on the internal query was 1 and the full select was 2. That is correct. I tried running that query in a .php file and $a was blank. I'm not sure what is missing, or why you would be getting Resource id #16.
I wonder if php versions make a difference here? |
No idea.
This is what's running on my server: Server Type Linux Web Server Apache v1.3.37 PHP 4.4.4 MySQL Version 4.1.21-standard |
How did you run the first query exactly? I get an SQL error...
|
I put in a value for $time to get it to run with no errors. I got that value by adding a line to print $time.
Code:
SELECT pmtextid FROM vbpmtext WHERE dateline < 1170202068 Code:
print $a[oldpms]; Code:
print $a; |
Here's the exact code I'm running right now. I changed the days to 25.
Quote:
|
if I use
Code:
print $a[oldpms]; If I use Code:
print $a; Addendum: OK - I just saw your post above. So we get the same thing. |
I cannot see what is wrong. There must be some code syntax we are not aware of as the query works fine manually. I did see that perhaps quotes were missing around the array element, but that doesn't seem to make a difference. Here's what I've got that shows some of what I've tried to make this work.
Code:
<?php |
A hint on another forum got me closer.
Using this: Code:
<?php Quote:
|
It is normal that those two counts are different. The database is normalized, so the text of the PM only gets sent once, while the PM will have a count of 2, one for the inbox of receiver and one for the sentbox of the sender. The PMs would be exactly double if no one had deleted any, but with that many you'll have some where either the sender or receiver deleted, but not the other.
So the initial welcome PM on my system has this: PMID = 1, PMTextID=1,UserID=1,folderid=-1 PMID=2,PMTextID=1,UserID=1,folderid=0 The PM went from me to me, so the UserID is the same. One PM is in my sent items, and one is in my inbox, which must be what the folderid is referring to. They both have identical text, so they point to the same PMTextID. So that code looks fine. Now you need a query that will select and delete all the rows in vbpmreceipts where PMID = one of the PMIDs you are deleting. |
Thanks, Jacqueline.
I've been soliciting some help over at TAZ as well and member Sarah there has suggested this: Quote:
|
At first I tried these and they didn't work. Then I realized there were no read receipts on this forum yet, so I sent a message with one. The select count selected one. The delete I changed to a select and it selected the correct record, so it looks like she did a great job with the code for you.
|
Here's the latest:
Code:
<?php Quote:
This is the result using "query_first". If I just use "query", no data is printed (just the text). What exactly is the difference? |
Answering my own question, from https://vborg.vbsupport.ru/showthread.php?t=75207:
Quote:
Quote:
|
So:
If I understand this now, the following tells me how many PMs, PM Texts, and PM Receipts need to be deleted: Code:
<?php Code:
<?php And do I need "DELETE *" or just "DELETE"? |
I will take a look at this later tonight, but I just spotted that you've got the 25 days I was using instead of the 60 days you wanted in your time variable.
|
I took a quick look at the delete statements and it doesn't look right. The delete * is right, but I do not see any where you are deleting from vbpmreceipt. The order matters too. Probably vbpmreceipts need to be deleted first, then vbpm, then vbpmtext. Once you delete vbpmtext, you lose your date and cannot use it to delete the others.
|
All times are GMT. The time now is 04:46 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|