Adding cron to taxonomy
bettyatolive - July 25, 2008 - 06:41
Hi,
I am using taxonomy and tagadelic module. I want to write a fucntion that will run as a cron. How will i be able to
write that?
I actually inserted 2 more columns(count, date ) in term_data tables (based on my requirements ) , now on the first day of every month, I want the count of it to be reset to 1. I tried writing this as a cron functionality but didnot work.
Below is the function that I wrote:
function taxonomy_cron() {
$tdy_arr=explode('-',$tdy);
$tdy_date=$tdy_arr[2];
if($tdy_date == "1") {
db_query(db_rewrite_sql("UPDATE {term_data} SET tcount = 1, date = '%s'"), $tdy);
}
}
Can somebody help me out in this.
Thanks,
Betty

You could try something like
You could try something like this:
<?php/**
* Implementation of hook_cron().
*/
function taxonomy_cron() {
//only run the update on the first of every month
if(date('j') == 1){
//get current datetime in MySQL format: yyyy-mm-dd hh:mm:ss
$mysql_date = date("Y-m-d H:i:s");
//reset the tcount column to 1 and the date column to today for all rows
db_query(db_rewrite_sql("UPDATE {term_data} SET tcount = 1, date = '%s'"), $mysql_date);
}
}
?>
That's assuming the date column you added is a MySQL datetime column.
Now you just need to make sure that cron actually runs at least every first day of the month.
Let us know how that works out.
HTH
Thanks for the
Thanks for the reply.
Actually the code that I wrote also worked, but i forgot to declare the $tdy value :(
Just now found that out. :)
Anyways, I am using the datetime type, this seems more apt for me.
Thanks for the idea.