Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-29-2008, 05:10 PM
PaulSonny PaulSonny is offline
 
Join Date: Dec 2006
Location: Middlesbrough, UK
Posts: 433
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Checking The Time in DB Field.

Hello Everyone,

I have a database field which has a timestamp in it, named datalastupdate.

I have an admin option, named helpcenter_auto_close which sets the period of time that has to pass.

I have the following php code:

PHP Code:
<?php
if ($vbulletin->options['helpcenter_auto_close']>0){
    
$ticketreply $vbulletin->db->query_first("SELECT * FROM " TABLE_PREFIX ."helpcenter_ticket");
    while (
$ticket $vbulletin->db->fetch_array($ticketreply))
    {    
        
$ticketid $ticket['ticketid'];
        
$hc_time1 $vbulletin->options['helpcenter_auto_close'];
        
$hc_time1 TIMENOW;
        
$hc_timediff intval($hc_time1-$hc_time2);
        if (
$ticket['datelastupdate'] <= $hc_timediff){
        
$vbulletin->db->query_write("UPDATE " TABLE_PREFIX ."helpcenter_ticket SET ticketstatus=0 WHERE ticketid=$ticketid");
        }
    }
}
?>
I'm trying to get it so that if the ticket has not been replied to for the set period in the admin options then it will close the ticket, but it wont work. Im doing this will a scheduled task.

I cant see what i'm doing wrong, can anybody help me?

Thanks, Paul.
Reply With Quote
  #2  
Old 04-29-2008, 07:52 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is your column in your database store UNIX time or date and time like in this format, year-month-day hour:minute:second?

Also you are overwriting the value of $hc_time1 here and $hc_time2 doesn't look to be set.
PHP Code:
$hc_time1 $vbulletin->options['helpcenter_auto_close'];
        
$hc_time1 TIMENOW
Reply With Quote
  #3  
Old 04-29-2008, 09:11 PM
PaulSonny PaulSonny is offline
 
Join Date: Dec 2006
Location: Middlesbrough, UK
Posts: 433
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

To be honest i'm not sure what is used. When adding the timestamp to the database i've just used TIMENOW the same as I have used it above.

Just realised the error with the $hc_time and have sorted it thanks, but still not working.

Thanks, Paul.

Updated Code:

PHP Code:
<?php
if ($vbulletin->options['helpcenter_auto_close']>0){
    
$ticketreply $vbulletin->db->query_first("SELECT * FROM " TABLE_PREFIX ."helpcenter_ticket");
    while (
$ticket $vbulletin->db->fetch_array($ticketreply))
    {    
        
$ticketid $ticket['ticketid'];
        
$hc_time1 TIMENOW;
        
$hc_time2 $vbulletin->options['helpcenter_auto_close'];
        
$hc_timediff intval($hc_time1-$hc_time2);
        if (
$ticket['datelastupdate']<=$hc_timediff){
        
$vbulletin->db->query_write("UPDATE " TABLE_PREFIX ."helpcenter_ticket SET ticketstatus=0 WHERE ticketid=$ticketid");
        }
    }
}
?>
Reply With Quote
  #4  
Old 04-29-2008, 10:04 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried running the cron in your browser to see if any errors occur? Also if the time you are supplying isn't in UNIX time it wouldn't work.

Also does $vbulletin->options['helpcenter_auto_close'] contain a number above 0?
Reply With Quote
  #5  
Old 04-30-2008, 06:38 AM
PaulSonny PaulSonny is offline
 
Join Date: Dec 2006
Location: Middlesbrough, UK
Posts: 433
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does using TIMENOW when adding to the DB not store it in UNIX?

I have tried running it in the browser but I just get a blank white page, when I get home later today i'll put some print statements in to test how far it is getting

It does hold a value above 0, ive set it to 120 to test it.

Thanks, Paul.
Reply With Quote
  #6  
Old 04-30-2008, 07:00 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

TIMENOW is the UNIX-style timestamp. You really don't need to assign it to a variable.
Reply With Quote
  #7  
Old 04-30-2008, 02:19 PM
PaulSonny PaulSonny is offline
 
Join Date: Dec 2006
Location: Middlesbrough, UK
Posts: 433
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah right just when I was looking at other examples it has been assigned to a variable.

So could I use instead:

$hc_timediff = intval(TIMENOW-$hc_time2);

Thanks, Paul.
Reply With Quote
  #8  
Old 04-30-2008, 02:39 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Throw in some var_dump()'s and echo()'s to check which is being executed it maybe that it isn't fetching stuff from the database. Blank pages are useless for debugging!
Reply With Quote
  #9  
Old 04-30-2008, 04:19 PM
PaulSonny PaulSonny is offline
 
Join Date: Dec 2006
Location: Middlesbrough, UK
Posts: 433
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What i dont understand is ive put a print statement at the very top and when I run the file it doesnt even print that line like it should.

Thanks, Paul.
Reply With Quote
  #10  
Old 04-30-2008, 04:38 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good code layout is essential I can easily say that more organised code will gaurantee that you can troubshoot problems faster. Please, please, please layout code properly!

Here is how I would have done it (I've commented in lines I would try, to solve problems e.t.c.):
PHP Code:
<?php
// echo 'Starting file';
if ($vbulletin->options['helpcenter_auto_close'] > 0)
{
    
// echo 'First condition passed';
    
$ticketreply $vbulletin->db->query_first("SELECT * FROM " TABLE_PREFIX ."helpcenter_ticket");
    
    
// echo 'query good';
    
while ($ticket $vbulletin->db->fetch_array($ticketreply))
    {    
         echo 
'while good';
        
        
$ticketid =& $ticket['ticketid'];
        
$hc_time2 $vbulletin->options['helpcenter_auto_close'];
        
$hc_timediff intval(TIMENOW $hc_time2);
        
        
// var_dump($ticketid, $hc_time1, $hc_time2, $hc_timediff, $ticket )
        
if ($ticket['datelastupdate'] <= $hc_timediff)
        {
            
$vbulletin->db->query_write("UPDATE " TABLE_PREFIX ."helpcenter_ticket SET ticketstatus = 0 WHERE ticketid = $ticketid");
        }
    }
}
?>
But whilst I was reorganising your code I found you were using [minicode]query_first()[/minicode] but you should be using [minicode]query_read()[/minicode] I suspect?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:34 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07218 seconds
  • Memory Usage 2,285KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete