PDA

View Full Version : Automatically closing threads


hurrican
08-12-2004, 02:26 AM
I Currently am working with this PHP Script to close threads older than a year, but I can't seem to get it to work, on my command line, I can type
php closethreads.php and it goes on w/o error, but the threads don't lock.. I constructed this with a little bit of other codes i've found on here.. Any help is greatly appreciated!


$DB_site->query("UPDATE thread
SET open = 0
WHERE dateline < ".(TIMENOW - (60 * 60 * 24 * 364))."
AND forumid IN (3,4,5)
");
?>

Modin
08-12-2004, 03:08 AM
hmm...

I assume you've included global.php etc?

can you post the entire script, maybe it's something earlier in it because that query looks great to me.

If your admin set error reporting to none by default then it wouldn't show any errors. My admin did that once...worst developing environment ever.

hurrican
08-12-2004, 03:13 AM
OOpsie, Thanks for the reply! I thought I had copied the whole script, but guess not, lol.. I run my own server, so I can luckily configure everything needed for debugging. I should mention this is for vB2.3.5 - Here's what my entire script looks like.. :classic:


<?php
require("./global.php");
$DB_site->query("UPDATE thread
SET open = 0
WHERE dateline < ".(TIMENOW - (60 * 60 * 24 * 364))."
AND forumid IN (3,4,5)
");
?>

Modin
08-12-2004, 03:20 AM
hmm... maybe global.php won't let you use it outside of a browser... try this instead.



<?php

$db = mysql_connect($db_server, $db_user, $db_pass) or
die("Could not connect to database with error (".mysql_error().")");

$db_sel = mysql_select_db($db_name, $db) or
die("Could not select database $db_name with error (".mysql_error().")");

mysql_query("UPDATE thread SET open = 0 WHERE dateline < ".(TIMENOW - (60 * 60 * 24 * 364))." AND forumid IN (3,4,5)", $db);
?>


(replacing the necessary variables with your database info of course ;))

hurrican
08-12-2004, 03:48 AM
Hmm.. Still no go :( That code is definately a lot better looking though. It's definitely got me baffled, lol.. I really appreciate your help!! :) :) I'm learning the way around MySQL pretty good, but not quite well enough, lol :)



<?php

$db = mysql_connect('localhost', 'un', 'pw') or
die("Could not connect to database with error (".mysql_error().")");

$db_sel = mysql_select_db('dbname', $db) or
die("Could not select database $db_name with error (".mysql_error().")");

mysql_query("UPDATE thread SET open = 0 WHERE dateline < ".(TIMENOW - (60 * 60 * 24 * 364))." AND forumid IN (3,4,5)", $db);
?>

There is still no output below.. hmm

[root@ball vb]# php closethreads.php

[root@ball vb]#

Natch
08-12-2004, 03:51 AM
There will be no output unless you echo something out ...

Modin
08-12-2004, 04:32 AM
yeah, there shouldn't be output with that script, though it should update your database.

at the end of it if you want confirmation then add the line. Or whatever you want it to say:)

echo "Script Completed";

hurrican
08-12-2004, 04:46 AM
I did do that just to confirm, but for some weird reason, the threads still don't get closed. I'm baffled, lol. If I go look in phpMySQLadmin the real old threads still all show 1 (open) so I did a search for 0, and they were threads that were already closed.. Any possible suggestions as to why nothing will update??

thanks again, i'll check back in the morning! :)

Modin
08-12-2004, 04:55 AM
whooops...

here try this instead :)


<?php

$db = mysql_connect('localhost', 'un', 'pw') or
die("Could not connect to database with error (".mysql_error().")");

$db_sel = mysql_select_db('dbname', $db) or
die("Could not select database $db_name with error (".mysql_error().")");

mysql_query("UPDATE thread SET open = 0 WHERE dateline < ".(time() - (60 * 60 * 24 * 364))." AND forumid IN (3,4,5)", $db);
?>

Dean C
08-12-2004, 08:06 AM
If you're using vB3 take a look at one of the files in the includes/cron directory. Put your script you have at the top in a new file in that directory. And add it as a scheduled task :)

hurrican
08-12-2004, 11:09 AM
Dude, you're the bomb :) Worked like a charm that time. Funny how TIMENOW and time can cause a problem, lol. I guess the original script that I copied somewhere else on the forum was wrong, but it works great this time! Now to go set it up as a cron job :) Could I Paypal ya $15 bucks for your help?? I highly appreciate your help, and this board :) I'm suprised that I couldn't find the answer asked already, with a solution. Again, thanks a lot!! :nervous: :nervous:

Thanks Dean, but I am running 2.3.5 :) I'm kinda holding off for now on vB 3 until it gets to around 3.1 for bug purposes, then again, my users hate change, lol. I run a football website so can't do any upgrades until around January now anyway! doh :ermm:

Dean C
08-12-2004, 11:20 AM
Best of luck with upgrading in January then ;)

Modin
08-12-2004, 03:38 PM
Glad it's working :)
I don't require anything, but I won't object to donations ;)

Sent you a pm with my paypal account in it.

Cheers :)

Milktruck
08-18-2004, 03:55 AM
I want to close all threads older than a week, weekly.

I have vB 3.0.1

This script would work?

Dean C
08-18-2004, 06:52 AM
This is the query you want:


UPDATE thread SET open = 0 WHERE dateline < ".(time() - (60 * 60 * 24 * 7))."


Modify the script above to suit :)