Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Need to sort discussions by Date Created, not Most Recent Comment

DoyceTDoyceT ✭✭✭
edited September 2014 in Vanilla 2.0 - 2.8

Hi all,

I'm on 2.1.1 stable, running a forum for an online campus.

The faculty/students in particularly active classes are complaining that their classroom areas (read: private Categories) are 'confusing', because "the order in which discussions are listed keeps changing" (obviously, because they're ordered by most-recently-updated)... and apparently they want to be able to memorize the location of each discussion on the screen and click on the G-D thing with their eyes closed, rather than actually reading.

Ahem.

Anyway, I'd "like" to change the display of discussions on the forum - specifically, to order the discussions by the date created.

(Yes, this dumb. Yes, I hate it. Read that as a given.)

I added the following two lines to config...

$Configuration['Vanilla']['Discussions']['SortField'] = 'd.DateInserted';
$Configuration['Vanilla']['Discussions']['SortDirection'] = 'desc';

... as suggested by @hgtonight in this post - http://vanillaforums.org/discussion/comment/180112/ - but it doesn't seem to have any effect. Has the code changed in the last year, to the point where these config settings no longer do anything? Config-defaults.php does not seem to contain any hints on this one.

«13

Comments

  • edited September 2014

    Look at the class.discussionmodel.php to see where it comes from

        $this->AddArchiveWhere($this->SQL);
    
          if ($Offset !== FALSE && $Limit !== FALSE)
             $this->SQL->Limit($Limit, $Offset);
    
          $this->EventArguments['SortField'] = C('Vanilla.Discussions.SortField', 'd.DateLastComment');
          $this->EventArguments['SortDirection'] = C('Vanilla.Discussions.SortDirection', 'desc');
            $this->EventArguments['Wheres'] = &$Wheres;
            $this->FireEvent('BeforeGet'); // @see 'BeforeGetCount' for consistency in results vs. counts
    
          $IncludeAnnouncements = FALSE;
          if (strtolower(GetValue('Announce', $Wheres)) == 'all') {
             $IncludeAnnouncements = TRUE;
             unset($Wheres['Announce']);
          }
    
          if (is_array($Wheres))
             $this->SQL->Where($Wheres);
    
            // Get sorting options from config
            $SortField = $this->EventArguments['SortField'];
            if (!in_array($SortField, array('d.DiscussionID', 'd.DateLastComment', 'd.DateInserted'))) {
                trigger_error("You are sorting discussions by a possibly sub-optimal column.", E_USER_NOTICE);
          }
    
            $SortDirection = $this->EventArguments['SortDirection'];
            if ($SortDirection != 'asc')
                $SortDirection = 'desc';
    
            $this->SQL->OrderBy($SortField, $SortDirection);
    
          // Set range and fetch
          $Data = $this->SQL->Get();
    

    by the way you should update to 2.1.3 for security and other reasons

  • I can't really do a version update until the semester is done.

    (I'm honestly trying not to mess with anything at all while classes are in session, so long as it's working as intended, or enough people complain about something dumb like this.)

    1. It should still work in 2.1.1
    2. You should always minor updates rarely break anything and contain security patches. Update.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • DoyceTDoyceT ✭✭✭
    edited September 2014

    @hgtonight said:
    2. You should always minor updates rarely break anything and contain security patches. Update.

    Okay. Updated to 2.1.3. See how I cave under pressure?

    Unfortunately, the fact that those two config lines should work doesn't seem to have any bearing on my forum, which continues to order by most recently updated.

    Update: Annnd it broke file uploading. Awesome.

    Update: And all posting. Double Awesome.

  • peregrineperegrine MVP
    edited September 2014

    you mean the config statements change or the update to 2.1.3....

    if it was the update clear the cache,

    not really needed but ....

    run utility/structure. utility/update.

    reinstall source files if you still have problems. 2.1.3 does work fine,

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Do you have any plugins that modify the sort field?

    Search for DiscussionModel_BeforeGet_ and report any plugins that use that hook.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Updated to 2.1.3.

    Cleared Cache.

    Ran structure and update.

    This is what I get whenever anyone tries to post.

  • peregrineperegrine MVP
    edited September 2014

    check your. .htaccess - did you overwrite it?

    and make sure rewritebase is correct.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Its still not clear are you just trying to get your forum functional, or are you working on the sorting stuff.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • DoyceTDoyceT ✭✭✭
    edited September 2014

    I am not trying to reorder the posts anymore. Updating to 2.1.3 has rendered the forum unusable, and I am now trying to address that issue.

  • peregrineperegrine MVP
    edited September 2014

    I would verify .htaccess and fix rewrite base

    check if no go.

    I would re-install source. make sure all files get copied, and then verify .htaccess

    and if you made changes to config-defaults.php which shouldn't be done (since it gets over-written as well)

    where as config.php doesn't get overwritten.

    and remove these lines from config.php

    $Configuration['Vanilla']['Discussions']['SortField'] = 'd.DateInserted';   
    $Configuration['Vanilla']['Discussions']['SortDirection'] = 'desc';   
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • DoyceTDoyceT ✭✭✭
    edited September 2014

    .htaccess reads:

    # Original
    # If you modify this file then change the above line to: # Modified
    <IfModule mod_rewrite.c>
       RewriteEngine On
       # Certain hosts may require the following line.
       # If vanilla is in a subfolder then you need to specify it after the /. 
       # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
       # RewriteBase /
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
    </IfModule>
    

    Config.php is back to where it was a couple hours before I did anything to it.

    Hitting "post" throws a 404 error for ... something. Can't tell what file it wants that it can't find.

    Hitting post again makes the page go completely blank.

    Also just sitting on the page with the 404 error will make it go blank after about 30 seconds idle.

  • peregrineperegrine MVP
    edited September 2014

    where is your forum folder.
    If vanilla is in a subfolder then you need to specify it after the /.

    uncomment this line and place your forum folder name

    # RewriteBase /

    e.g.

    RewriteBase /forum

    RewriteBase /vanilla

    RewriteBase /whatever

    I would verify .htaccess and fix rewrite base

    check if no go.

    I would re-install source. make sure all files get copied, and then verify .htaccess

    and make sure all folders are readable. and permisions correctly set.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • What is the URL that is giving you the 404?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • It's possible a plugin is overriding your Vanilla.Discussions.SortField.

    Regarding the 2.1.3 broken issue: Are you using a Bluehost 1-click installer, or manually uploading?

    If you are using an installer, verify their version is 2.1.3 and not 2.1.2.

    If you copy the files over yourself, do try copying them all again as peregrine suggested and checking your htaccess is as it should be.

    That 404 error suggests a non-Vanilla problem with your setup - that ain't Vanilla's 404.

  • Would you also humor me and tell me what browser you're using and whether you've tried in any other browsers?

  • @peregrine said:
    where is your forum folder.
    If vanilla is in a subfolder then you need to specify it after the /.

    uncomment this line and place your forum folder name

    # RewriteBase /

    .htaccess now reads:

    # Original
    # If you modify this file then change the above line to: # Modified
    <IfModule mod_rewrite.c>
       RewriteEngine On
       # Certain hosts may require the following line.
       # If vanilla is in a subfolder then you need to specify it after the /. 
       # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
       RewriteBase /orca
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
    </IfModule>
    

    Forum is at nila.edu/orca - so that tracks.

  • @hgtonight said:
    What is the URL that is giving you the 404?

    I can't exactly tell - it's not actually saying what the 404 file is - just that it can't find a file when I try to post.

  • @Linc said:
    Regarding the 2.1.3 broken issue: Are you using a Bluehost 1-click installer, or manually uploading?

    Nah, I uploaded the archive, unarchived, and copied everything over into the directory.

    If you copy the files over yourself, do try copying them all again as peregrine suggested and checking your htaccess is as it should be.

    I'll give it a shot, but I think I'm on about my fourth copy-over.

  • peregrineperegrine MVP
    edited September 2014

    a change in .htaccess isn't always immediate. that could be your issue now that you have changed .htaccess.

    on localhosts ubuntu one has to apache2ctl for immediate change.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.