Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Discussion Expiration (Testing only)

Read the documentation very carefully.

First before you do anything. Download, install and enable jQuery ext

Did u do what I wrote above. If not then do that right now

OK Now download the extension from HERE

extract and copy it in your extension Folder
Did u enable Jquery yet?
Now enable Discussion Expiration. refresh page
You will see a new Heading under "Extension Options" called Discussion Expiration
Click on it and select the Categories you want the Discussion to expire.
Picture 1
Just because u have the ability to choose all the categories. It makes no sense to do so. Think long and hard about which categories should have this capability. If you have a category about Events, then this will be perfect for it.

When you create a new Discussion and select the category, you will see a new field appear.
Picture 2

Use the included Date Picker to pick an expiration date.
Picture 3

All Bug reporting during the testing phase needs to be in this thread. You have to give me detail explanation of the problem. lame complaint won't get u any help.

Now that I think of it. this extension should have been called "Fresh Before".


  • Options
    This is great man! I have it on a testing site now. I take it expiration happens at midnight server time. My server is PST so I check back in 3 hours.

    The installation and use so far have been perfect.
  • Options
    edited May 2007
    it doesn't expire at a specific time. its reference time is the time u installed.
    When u installed the extension, the time of installation is stored, and from then on. it checks back after 24 hrs from installation. Plus the time is server time. If ur Server is outside US then it will be time of that country.

    Check ur database and see if the date is stored or not
  • Options
    Ah that's good to know. Where is that time stored? (so I can alter it to speed up testing)

    The date and info are stored perfectly

    In my case I will be expiring them to 'deleted' since I don't need them searchable. Is this the only line I would change or are there other points in your code.

    $query = "UPDATE LUM_DISCUSSION SET Active = 0 WHERE DateExpire > 0000-00-00 AND NOW() > DateExpire;";
  • Options
    u will change the time it checks
    if (time() > $Context->Configuration["DISCUSSIONEXPIRATION_LASTCHECK"] + 86400 )

    this checks if the current time is (24hr * 60min * 60sec) more than last check. If u remove the 86400 (=24hrs) then it should do it the moment u refresh ur discussion page. remember the check is done when the discussion page is refreshed.
  • Options
    Removing the 86400 generates an error

    Fatal error: Call to undefined method DiscussionGrid::GetDefinition() in /home/vanilla/extensions/DiscussionExpiration/default.php on line 101

    Same thing happens if you use 60 seconds.
  • Options
    edited May 2007
    Sorry my mistake
    fixing it. and will upload it
    It should be
    if (time() > $Context->Configuration["DISCUSSIONEXPIRATION_LASTCHECK"] + 86400 ) { function CloseExpiredDiscussions (&$DiscussionGrid) { $query = "UPDATE LUM_DISCUSSION SET Closed = 1 WHERE DateExpire > 0000-00-00 AND NOW() > DateExpire;"; $result = mysql_query($query); if (!$result) echo $DiscussionGrid->Context->GetDefinition('DiscussionExpiresError'); } $Context->Configuration["DISCUSSIONEXPIRATION_LASTCHECK"] = time(); $Context->AddToDelegate('DiscussionGrid', 'PostRender', 'CloseExpiredDiscussions'); }
  • Options
    edited May 2007
    I replaced that code and it looks like it is not working .

    with no number or with another number I get
    "Error Occured. Discussions were not closed"

    so it looks like its trying to perform the action, just not succeeding.

    UPDATE: Solution

    $query = "UPDATE LUM_DISCUSSION SET Closed = 1 WHERE DateExpire > 0000-00-00 AND NOW() > DateExpire;";
    $query = "UPDATE LUM_Discussion SET Closed = 1 WHERE DateExpire > 0000-00-00 AND NOW() > DateExpire;";

    Doing this it does work! pretty sweet man.

    I did see one other error. If you enter a old day you get your warning BUT at the very top of the page you also get :

    Notice: Trying to get property of non-object in /home/vanilla/extensions/DiscussionExpiration/library/Function.DiscussionExpiration.php on line 43
  • Options
    edited May 2007
    One more thing. In looking at the code it seems to check against the whole discussion table for expired posts. Would it not be more efficient to check only against open discussions (not closed / not deleted)?

    $query = "UPDATE LUM_Discussion SET Closed = 1 WHERE DateExpire > 0000-00-00 AND NOW() > DateExpire && Closed=0 && Deleted=0;";
  • Options
    edited May 2007
    good catch
    btw there is no column Deleted in Discussion table.
    I think i will make a check on the category. plus it shouldn't be a whisper either.
  • Options
    edited May 2007
    ooops...late night commenting. By deleted=0 I meant not deleted which is active=1. So... $query = "UPDATE LUM_Discussion SET Closed = 1 WHERE DateExpire > 0000-00-00 AND NOW() > DateExpire AND Closed=0 AND Active=1;"; So if you do a new post and type in "05/05/2007" you only get your warning? Not the : Notice: Trying to get property of non-object in /home/vanilla/extensions/DiscussionExpiration/library/Function.DiscussionExpiration.php on line 43 at the top of the page above the banner? Odd. I will try on another server after work as see if I can replicate it there. The line in question is: $sql->AddWhere('d', 'DiscussionID', '', $ResultDiscussion->DiscussionID, '='); That is causing an issue when an invalid date is entered. UPATE: Found one other thing. It doesn't handle wrong entries EG : tis thrsday (or DOG for that matter) will be accepted and give you: 12/31/1969 as a date. So I think $DateExpire = date("m/d/Y",strtotime($DateExpire)); will convert any word to a date and invalid words will be 12/31/1969. (just a guess.) If do, you could just check against that in function CheckDateFormat($strdate) if($strdate == "12/31/1969"){ $Context->WarningCollector->Add($Context->GetDefinition('WrongDateFormat')); return 0; } You also don't need the other two checks since they always ring true since strtotime($DateExpire) will create the correct format. You may also want to adjust "WrongDateFormat" You must enter the date in "mm/dd/yyyy" format, Use the provided Date Picker. to read: You must enter the date in the format of "mm/dd/yyyy" or use phases like or "next week" or "this thursday". Consider using the provided Date Picker. Use the provided Date picker or enter date like 05/16/2007 or "next week" or "this thursday" ---------------------------- But overall this works exactly as I had pictured. I will likely do a MOD once testing is done since it suits my board to have them delete: $query = "UPDATE LUM_Discussion SET Active = '0' WHERE DateExpire > 0000-00-00 AND NOW() > DateExpire AND Active=1;";
  • Options
    edited May 2007
    OK both bugs are fixed now.

    one question Does adding more "Where" clause slow down the query cause ur doing more checks per row, or does it speed up the query cause u will be changing less rows per query.
    For example I might not care if a deleted (non active) discussion is closed. But If i check for it. I'm wasting my time. cause i don't care about it. But if i don't check then I'm altering more rows. Which one is more troublesome?

    Should whispered discussions be closed or not.
    Should I check for categories or not. If the admin changes his mind about a particular category then, discussion from that category won't be closed even though it has date expiration. Should it be closed or no? I'm thinking if the admin changed his mind then he prolly doesn't want the discussions to expire even though it has expiration date. Decisions Decisions.

    regarding updating error messages. I'm making it o it tells u what u wrote and what u should have written. instead of just telling u what u should have written
  • Options
    edited May 2007
    1) Where Clause: Personally I don't know. I am still a noob when it comes to MySQL efficiency. I am sure someone around here will know what's best. 2) Whispers: I would think so since if you select expire you must want it to. 3) Close after change? I would say so since that is what the user posted it as. They would just not have the option in future posts. You could have an "clear expiry dates" button on the admin console that is only enabled when a category expiry option is disabled. (with an "are you sure" alert of course). I don't think its needed though. 4) Error message: Good call I will install you new version tonight and test some more but it was running pretty slick the last time. Nice work
  • Options
    edited May 2007
    1. where clause--I would assume that comparing an extra condition to every row would take much less time than reading an one row and then updating it. In other words, go crazy on the wheres.
    2. hmm... I agree with jeff.
    3. I would still close it. Say an administrator wants to expire only one discussion in a category--he would turn it on, go in to it, change it, then turn off the expriy for the category. You should probably post a notice that says something like The category x has discussions in it that are set to expire. Do you still want to expire them? ... then list them with yes/no buttons. Admin can then clear any expirations he wants and click done to go back to the forum.

    Another thought is to sink/unsticky discussions rather than close on their expiration.
  • Options
    edited May 2007
    How will i track what should happen when the expiration is passed. It can be set to do multiple things. UnStick and Close after expiration. or sink and unstick but not close. So every Discussion will now a expiration preference column.
    So I should allow multiple effects. There are essentially 3 options that we can use per discussion. Closed, Sink, Sticky. Checkboxes can be added. What i won't do is have different dates for different results. that will be hard to do.

    Should this be role specific as well. or everyone should be allowed to expire discussions.
    Admin Side calender of all Discussions set to expired can also be shown. click on the date to see a list of all Discussion set to close/unstick/sink on that date. there I can have a "clear the date" checkbox.
  • Options
    Personally, I don't think you need expire to sticky (Although, Expire to Unstick might come in handy for admins. eg: Unstick this post in 30 days). I think most admins will want either Close, Sink, or delete depending on the category. If you do enable a choice for users I think it would be nice have a choice of them NOT choosing, just expiring to the default. Since it only applies to an individuals post I don't think a role permission is needed but you could add it if you like. Actually, maybe a roll to expire any discussion (outside of the defaults). That could then be applied to admins or moderators and be used for system posts etc.
  • Options
    idunno. This is interesting... agree about different dates for different changes... it would be way too complicated to pack that in the discussions table.

    Its kind of pointless to have both close and sink at the same time--as sink is just a lesser form of close.

    Maybe serialize the array of changes into one field? Then convert them to an array and loop through each change...

    Or maybe this would be better left for a general "Vanilla Cron" extension that does more complex changes directly with SQL--like adding roles or categories or posts.
  • Options
    Ok I have been running several tests and it is working perfectly. No major errors. 1 small minor thing. You cannot select today as the day. You should since it does not expire until midnight when the date is > the todays date. In looking at the code you have < strtotime("now"). I think thats the problem since strtotime("now") gives you the date AND time of now.
  • Options
    try subtracting 86400 from StrtoTime("now"). So it will be wrong if its 24 more than todays day
  • Options
    edited May 2007
    I don't get it why can't i check for closed discussions
    this query works
    SELECT Name, DateExpire FROM LUM_Discussion WHERE Active=1 AND DateExpire>0000-00-00;

    but this fails
    SELECT Name, DateExpire FROM LUM_Discussion WHERE Active=1 AND DateExpire>0000-00-00 AND Closed =0;

    ok now in the settings page u should see a list of all open discussion that are set to expire.
  • Options
    Oh I ran into this too (since I am setting mine to Active=0). I had notice when I set =0 it was blank in the database. The fix is I had to so Active = '0' so this should work SELECT Name, DateExpire FROM LUM_Discussion WHERE Active='1' AND DateExpire>0000-00-00 AND Closed ='0'; This is (i believe) because its an ENUM set not just a value.
This discussion has been closed.