Results 1 to 20 of 20

Thread: cron job for deleting entries after 30 days?

  1. #1
    Join Date
    Oct 2005
    Posts
    186

    Default cron job for deleting entries after 30 days?

    Brian, could you post what it should look like?

  2. #2
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    PHP Code:
    $kill = array();

    $getentries $db->query_read("
        SELECT entryid
        FROM " 
    TABLE_PREFIX "adv_dyna_entries
        WHERE dateline <= " 
    . (TIMENOW 2592000)
    );
    while (
    $entry $db->fetch_array($getentries))
    {
        
    $kill[] = $entry['entryid'];
    }

    require_once(
    './includes/vba_dyna_functions_moderate.php');


    delete_entries($kill); 
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

  3. #3
    Join Date
    Oct 2005
    Posts
    186

    Default

    I'll try that out. Thanks!

  4. #4
    Join Date
    Oct 2005
    Posts
    186

    Default

    Hey Brian, I'm getting an error on this line:

    $getentries = $db->query_read("

    The error is:
    Fatal error: Call to a member function query_read() on a non-object

    I've placed that code into a file, placed it in the cron folder and created a cron job.
    Last edited by ludachris; 12-01-2009 at 04:14 PM.

  5. #5
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    Try replacing the two places you see "$db->" in the code with "$vbulletin->db->" and see if you get better results.
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

  6. #6
    Join Date
    Oct 2005
    Posts
    186

    Default

    Quote Originally Posted by Brian View Post
    Try replacing the two places you see "$db->" in the code with "$vbulletin->db->" and see if you get better results.
    Was thinking that myself - when I tried that, I got the following error:

    Fatal error: Call to a member function query_write() on a non-object in /var/www/mysite.com/web/forums/includes/vba_dyna_functions_moderate.php on line 156

    Figured I was on the wrong path.

  7. #7
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    You could try adding this code to the top of your PHP file for the cron job.

    PHP Code:
    $db =& $vbulletin->db
    If that doesn't help then you may need to edit your includes/vba_dyna_functions_moderate.php file and add that line just below this code:
    PHP Code:
    function delete_entries($entryarray)
    {
        global 
    $db$vba_options
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

  8. #8
    Join Date
    Oct 2005
    Posts
    186

    Default

    So I've tried adding that line of code to the top of the cron job (while leaving the previous code modifications in, and then reverting them back to the original suggestion), and also adding the modification code to the vba_dyna_functions_moderate.php file... still getting an error:

    Call to a member function query_write() on a non-object in /var/www/mysite.com/web/forums/includes/vba_dyna_functions_moderate.php on line 158

  9. #9
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    Ahhh, you probably need to globalize the $vbulletin variable within the function as well.

    Code:
    function delete_entries($entryarray) 
    { 
        global $db, $vba_options, $vbulletin;
    
        $db =& $vbulletin->db;
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

  10. #10
    Join Date
    Oct 2005
    Posts
    186

    Default

    Making progres... now getting a db error:

    Invalid SQL:
    DELETE FROM ADV_DYNA_TABLE_PREFIXentries WHERE entryid IN


    I figure if maybe I add an underscore in the cron file query, I should be good?

    FROM " . TABLE_PREFIX . "_adv_dyna_entries

  11. #11
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    It would probably be better just to add this code near the top of the PHP file you're using for the cron job.
    PHP Code:
    define('ADV_DYNA_TABLE_PREFIX''adv_dyna'); 
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

  12. #12
    Join Date
    Oct 2005
    Posts
    186

    Default

    Got a new error:

    Fatal error: Call to undefined function dyna_fetch_upload_path() in /var/www/mysite.com/web/forums/includes/vba_dyna_functions_moderate.php on line 175

  13. #13
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    Well at least we're getting closer.

    Try adding this line to the top of your PHP file, just after the opening <?php tag.
    Code:
    require_once('./includes/vba_dyna_functions.php');
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

  14. #14
    Join Date
    Oct 2005
    Posts
    186

    Default

    That did it. It is now finally working. Thanks Brian.

  15. #15
    Join Date
    Oct 2005
    Posts
    186

    Default

    Hey Brian, is there an easy way to add on to this cron script to delete all attachments associated with the entries that are being deleted?

    Here's the code that is being used to delete the entries:
    Code:
    require_once('./includes/vba_dyna_functions.php');
    define('ADV_DYNA_TABLE_PREFIX', 'adv_dyna_');  
    
    $db =& $vbulletin->db; 
    
    $kill = array();
    
    $getentries = $db->query_read("
        SELECT entryid
        FROM " . TABLE_PREFIX . "adv_dyna_entries
        WHERE dateline <= " . (TIMENOW - 2592000)
    );
    while ($entry = $db->fetch_array($getentries))
    {
        $kill[] = $entry['entryid'];
    }
    
    require_once('./includes/vba_dyna_functions_moderate.php');
    
    
    delete_entries($kill); 
    
    ?>

  16. #16
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    Attachments should already be deleted when the delete_entries() function is run.
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

  17. #17
    Join Date
    Oct 2005
    Posts
    186

    Default

    Quote Originally Posted by Brian View Post
    Attachments should already be deleted when the delete_entries() function is run.
    Ahhh, that might be the case. I haven't verified whether it's the cron job or when people delete their own entries. But I know that I have attachments that are still stored that are not tied to any entries - as the entries were deleted, but not the attachments. I can't remember if the entries were deleted by the cron job or by me. It causes issues for usergroups that have a limit on their quota, as they have no ads posted but their attachments are still taking up space. Do attachments get deleted when entries are deleted manually by the user?

  18. #18
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    If your members are just soft deleting entries then that could be the issue since attachments are not removed when an entry is soft-deleted.
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

  19. #19
    Join Date
    Oct 2005
    Posts
    186

    Default

    Quote Originally Posted by Brian View Post
    If your members are just soft deleting entries then that could be the issue since attachments are not removed when an entry is soft-deleted.
    That must be it. Are soft deleted entries physically removed with the cron job? Maybe that's the issue. The entries get soft deleted and the attachments are not deleted. Then, when the cron runs, it doesn't delete the attachments.
    Last edited by ludachris; 05-20-2010 at 02:13 PM.

  20. #20
    Join Date
    Jan 2004
    Location
    Georgia, USA
    Posts
    34,466

    Default

    Even a soft-deleted entry should be removed by that code in your cron job, and it should pick up the attachments as well...
    Frequently Asked Questions
    CMPS Users Manual

    For vBadvanced software assistance, please use the support forums.
    Unsolicted PMs, IMs, and email will not be responded to.
    If you have a non-software related question or problem with your account, please submit a support ticket.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Deleting or renaming entries / categories
    By larina in forum Troubleshooting & Problems
    Replies: 10
    Last Post: 06-28-2008, 04:30 PM
  2. Cron SQL Error
    By dholt in forum Bugs From 2.0 Beta 2
    Replies: 5
    Last Post: 10-02-2006, 01:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •