vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Checking The Time in DB Field. (https://vborg.vbsupport.ru/showthread.php?t=177519)

PaulSonny 04-29-2008 05:10 PM

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.

MoT3rror 04-29-2008 07:52 PM

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


PaulSonny 04-29-2008 09:11 PM

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");
        }
    }
}
?>


MoT3rror 04-29-2008 10:04 PM

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?

PaulSonny 04-30-2008 06:38 AM

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.

Dismounted 04-30-2008 07:00 AM

TIMENOW is the UNIX-style timestamp. You really don't need to assign it to a variable.

PaulSonny 04-30-2008 02:19 PM

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.

Opserty 04-30-2008 02:39 PM

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! ;)

PaulSonny 04-30-2008 04:19 PM

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.

Opserty 04-30-2008 04:38 PM

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?


All times are GMT. The time now is 08:26 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01271 seconds
  • Memory Usage 1,762KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete