View Full Version : Update A Users Birthday - Nightly as Task
gpc10347
07-23-2008, 05:05 PM
I know I'll probably be quickly told that I must gnarfle the garthok for even asking such a silly question, but (there's always a but), I'd like to create a Scheduled Task to run specifically to update a users date of birth to the day coming (Each day would then be the users' birthday)...
I gather from reading the manual, I'd need to set the task to run before the Birthday Message task and all that for the following day. I also need to create a PHP file to update the user record by the userID -
The questions I have are regarding where one would put the PHP file in order to prevent a bot or user from being able to run in (inadvertantly) and, if anyone has a snippet that would do this safely...
(Call it Groudhog Day...)
Thanks for any assistance with this rather oddball inquiry
calorie
07-23-2008, 05:46 PM
The untested snippet below should update the birth date for userids 1, 2, and 3. Edit the code as desired and then use the ACP to set up a new cron job that runs once a day:
<?php
// ########################## SET PHP ENVIRONMENT ###############################
error_reporting(E_ALL & ~E_NOTICE);
// ###################### PREVENT UNAUTHORIZED ACCESS ###########################
if (!is_object($vbulletin->db))
{
exit();
}
// ############################ SET NEEDED DATES ################################
$birthday = date('m-d-Y', TIMENOW);
$birthday_search = date('Y-m-d', TIMENOW);
// ################# UPDATE BIRTHDAY FOR USERID 1, 2 AND 3 ######################
$birthdays = $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user
SET birthday = '" . $vbulletin->db->escape_string($birthday) . "',
birthday_search = '" . $vbulletin->db->escape_string($birthday_search) . "'
WHERE userid IN (1,2,3)
");
// ############################ LOG CRON ACTION #################################
log_cron_action('', $nextitem, 1);
?>
gpc10347
07-23-2008, 07:07 PM
This oughtta be a great addition to what is already an silly place..
I'll report back with the results!
Thanks loads!!
--------------- Added 1216844527 at 1216844527 ---------------
Awesome. the system now says it's their birthday...
What's the format to make them say perpetually 29 years old though instead of zero? (I"m concerned they won't be able to see the threads!)
; )
Got it! I likely didn't put the conversion in as nicely as some but I managed to make the user's birthday today less 29 years... Perfect! Thanks again!
gpc10347
07-26-2008, 01:37 PM
This is what I attempted to use and, it's likely wrong and watching it work doesn't error but my confidence isn't good...
What's the best way to keep a user 29 for the rest of her life?
$birthday1 = mktime(0, 1, 0, date("m"), date("d"), date("Y")-29);
$birthday = date('m-d-Y', $birthday1);
$birthday_search = date('Y-m-d', TIMENOW);
gpc10347
07-29-2008, 03:44 PM
I have to go to the Usergroup Manager for the usergroup this user is in and re-save the page where "Birthdays Viewable " is located to have it appear within the Today's Borthdays module in CMPS... (I know: Not A vBulletin issue but you have to admit, it's an interesting oddity: I named the task Groundhog Day)
<?php
// ########################## SET PHP ENVIRONMENT ###############################
error_reporting(E_ALL & ~E_NOTICE);
// ###################### PREVENT UNAUTHORIZED ACCESS ###########################
if (!is_object($vbulletin->db))
{
exit();
}
// ############################ SET NEEDED DATES ################################
$birthday = date('m-d-Y', strtotime("-29 years"));
$birthday_search = date('Y-m-d', strtotime("-29 years"));
// ################# UPDATE BIRTHDAY FOR USERID 1, 2 AND 3 ######################
$birthdays = $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user
SET birthday = '" . $vbulletin->db->escape_string($birthday) . "',
birthday_search = '" . $vbulletin->db->escape_string($birthday_search) . "'
WHERE userid IN (7,46)
");
// ############################ LOG CRON ACTION #################################
log_cron_action('', $nextitem, 1);
?>
Anything telltale about that?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.