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.

I Just Noticed a Strange Bug

SkismaSkisma New
edited March 2015 in Vanilla 2.0 - 2.8

Hi,

I'm not 100% certain this is a bug in this plugin or somewhere else, but let me explain. I have my discussion ID 13 entered in the settings of this plugin so that anytime someone posts in this topic, it won't count towards their post count. Prior to posting a test post in this discussion I had 23 total posts. I then posted the word "test" in the discussion and immediately went to my profile, it said my total post count was 21. I then went back and posted another test, then went straight back to my profile and it said my post count was 25. Because of this, I ranked up to Rank 6 using YAGA because the requirement for that rank is 25 posts. I then went back to my forum home (categories) and received a notification that said I ranked up to Rank 5. I thought this was odd so I went back to my profile and it now said my post count was 21 again. At this point, I went back to the discussion and posted a 3rd test. I went to my profile and it said it my post count was now 26! I ranked up again to Rank 6, went to my forum home and de-ranked to Rank 5. I went back to my profile and it said 21 again.

I hope that all made sense, I just thought I'd type out everything I did so hopefully it wasn't confusing. Is there any additional info needed to look into this?

My site is: http://forgehaven.com/forums and the discussion is: http://forgehaven.com/forums/discussion/13/post-party-countdown

«134

Comments

  • BleistivtBleistivt Moderator

    This plugin recalculates the profile counts. The problem is that counts are incremented when you post a comment, so they are set back only whenever the profile is visited and may be higher in the mean time.

    If you need bullet proof counts (e.g. for a badge rule) I'd recommend creating a plugin that manages a separate field to keep track of the counts.

  • Ahh I see that you mean. Well damn, I don't have the slightest clue how to make a plugin.

  • @Bleistivt Are there any other possible solutions? Maybe I could modify the way YAGA ranks up users....possibly set a delay or something?

  • Couldn't I just modify the current plugin vs creating a new one? If so, would anyone here be willing to help me?

    What I'm needing is for comments in a certain discussion to not be counted to begin with vs. having them increment, then be discounted.

  • I think I have a simple solution that requires minimal changes.

    1. Fire an event on the DiscountDiscussionModel
    2. Extend the CommentCount rule to fire on the new event hook
    3. Wrap all this in a plugin that executes the badge hooks on the new event hook

    This would require the latest version of Yaga, but minimally invasive.

    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.

  • @hgtonight Awesome! I'm trying to understand this the best I can.

    1. So I need to add something to class.discountdiscussionmodel.php?
    2. I then need to add something to the CommentCount rule to execute this new code I added to class.discountdiscussionmodel.php? Where is this Comment rule located?
    3. I don't have a clue here.

    I do already have the latest version of YAGA. It's worth mentioning that I have my ranking system setup already and everything is good there, but because the current post counts are going up then back down is where the issues are occurring.

  • @Skisma said:
    It's worth mentioning that I have my ranking system setup already and everything is good there, but because the current post counts are going up then back down is where the issues are occurring.

    You are right, this wouldn't affect the rank system. I will have to think about that.

    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.

  • BleistivtBleistivt Moderator

    I believe @hgtonight means the one on github which allows for plugin-provided rules.

    I then posted the word "test" in the discussion and immediately went to my profile, it said my total post count was 21. I then went back and posted another test, then went straight back to my profile and it said my post count was 25.

    This shouldn't happen. If you can reproduce this, I'd be interested to test it myself if you can give me a test account on your site.

  • I PM'd you your login info :)

  • BleistivtBleistivt Moderator

    Thanks!
    Resetting the comment count after every post may work for your use case.

    public function CommentModel_BeforeNotification_Handler($Sender, $Args) {
        Gdn::UserModel()->SetField($Args['Comment']->InsertUserID, 'CountComments', null);
    }
    
  • @Bleistivt Awesome! I'll give this a shot.

    What file to I need to add this to?

  • BleistivtBleistivt Moderator

    You can create a new plugin out of this or just add it to the class.discountdiscussions.plugin.php (inside the class body)

  • SkismaSkisma New
    edited March 2015

    @Bleistivt I've tried adding it in different places within the class body and each time when I upload it, it breaks my entire forums. I get a 500 Internal Server Error. I've first tried adding this code in between:

    public function SettingsController_DiscountDiscussions_Create($Sender) {
    $Sender->Permission('Garden.Settings.Manage');
    $Sender->AddSideMenu('/settings/discountdiscussions');
    $Sender->SetData('Title', 'DiscountDiscussions'.' '.T('Settings'));

        $Conf = new ConfigurationModule($Sender);
        $Conf->Initialize(array(
            'DiscountDiscussions.IDs' => array(
                'Control' => 'textbox',
                'LabelCode' => 'DiscussionIDs where no comments are counted, comma separated.',
            ))
        );
        $Conf->RenderAll();
    }
    

    and

    public function CommentModel_BeforeNotification_Handler($Sender) {
    DiscountDiscussionModel::UserCount($Sender->EventArguments['Comment']['InsertUserID']);
    }

    Then I tried adding it above:

    public function SettingsController_DiscountDiscussions_Create($Sender) {
    $Sender->Permission('Garden.Settings.Manage');
    $Sender->AddSideMenu('/settings/discountdiscussions');
    $Sender->SetData('Title', 'DiscountDiscussions'.' '.T('Settings'));

    so that it would be the first piece of code in the class and it's still doing the same thing.

    Any ideas?

  • BleistivtBleistivt Moderator
    edited March 2015

    Looks like the plugin already handles that event.

    In that case just change the CommentModel_BeforeNotification_Handler to

    public function CommentModel_BeforeNotification_Handler($Sender, $Args) {
        Gdn::UserModel()->SetField($Args['Comment']->InsertUserID, 'CountComments', null);
        DiscountDiscussionModel::UserCount($Sender->EventArguments['Comment']['InsertUserID']);
    }
    
  • You know what? I noticed that! ...but I wasn't too sure so I didn't try it. Next time I definitely will. I guess this is a good sign of slight improvement in my knowledge. Not much though. lol

  • @Bleistivt I inputted this code and gave it a test. Unfortunately the same thing is happening, is this supposed to refresh the user's comment count after every post?

  • BleistivtBleistivt Moderator

    Sorry, I can not reproduce this locally where it already worked.

    Generally I'd also recommend against having the comment counts show wrong data.
    If you really need to have "spam" topics, comment counts can't be used as a gamification metric.

  • Damn. Yea I know this is kinda out of the ordinary :/

    There's only this one topic that I'm needing to not be counted towards post count. Is there any way possible I can stop them from counting all together rather than be discounted? Maybe if I modify the class.discountdiscussionmodel.php?

  • BleistivtBleistivt Moderator

    Is there any way possible I can stop them from counting all together rather than be discounted?

    Yes, by adding a new count field to the user table and having a custom plugin manage that.

    Basically your plugin would have to:

    • Add a new field to the user table.
    • Handle a hook after comment submission (possibly the CommentModel_BeforeNotification_Handler) and increment the field for that user if the discussion is not in the list of excluded discussions.

    Then a new Yaga rule could easily created from the already existing rule.

    A few hints:

    • In the CommentModel_BeforeNotification_Handler...

      $Sender->EventArguments['Comment']->InsertUserID // this is the user id
      $Sender->EventArguments['Comment']->DiscussionID // this is the discussion id
      
    • The settings screen and the check if the discussion is in the list can be directly copied from the discountdiscussions plugin.

    • This is how you add a new column to the user table:

      public function Setup() {
          $this->Structure();
      }
      
      public function Structure() {
          GDN::Structure()->Table('User')
              ->Column('CustomCount', 'int(11)', 0)
              ->Set();
      }
      
  • SkismaSkisma New
    edited March 2015

    @Bleistivt After reading over your post a few times I decided to give this a go! I think I've got everything other than the CommentModel_BeforeNotification_Handler hook, let's hope so. Here's what I've got so far:

    <?php if (!defined('APPLICATION')) exit();
    
    $PluginInfo['DiscountDiscussions'] = array(
        'Name' => 'DisablePostCount',
        'Description' => 'Disables post count in specified discussions.',
        'Version' => '1.0',
        'Author' => "Bleistivt, Skisma",
        'MobileFriendly' => TRUE,
        'SettingsUrl' => '/settings/disablepostcount',
        'SettingsPermission' => 'Garden.Settings.Manage'
    );
    
    class DisablePostCountPlugin extends Gdn_Plugin {
    
        public function SettingsController_DisablePostCount_Create($Sender) {
            $Sender->Permission('Garden.Settings.Manage');
            $Sender->AddSideMenu('/settings/disablepostcount');
            $Sender->SetData('Title', 'DisablePostCount'.' '.T('Settings'));
    
            $Conf = new ConfigurationModule($Sender);
            $Conf->Initialize(array(
                'DisablePostCount.IDs' => array(
                    'Control' => 'textbox',
                    'LabelCode' => 'List the DiscussionID's you wish to disable post count in, comma separated.',
                ))
            );
            $Conf->RenderAll();
        }
    
        public function Setup() {
            $this->Structure();
        }
    
        public function Structure() {
            GDN::Structure()->Table('User')
            ->Column('CustomCount', 'int(11)', 0)
            ->Set();
        }
    
    }
    
    if (!function_exists('CountString')) {
        function CountString($Number, $Url = '', $Options = array()) {
            $Url = str_replace('/profile/count/comments', '/plugin/disablepostcount/comment', $Url);
            if (is_string($Options))
                $Options = array('cssclass' => $Options);
            $Options = array_change_key_case($Options);
            $CssClass = GetValue('cssclass', $Options, '');
            if ($Number === NULL && $Url) {
                $CssClass = ConcatSep(' ', $CssClass, 'Popin TinyProgress');
                $Url = htmlspecialchars($Url);
                $Result = "<span class=\"$CssClass\" rel=\"$Url\"></span>";
            } elseif ($Number) {
                $Result = " <span class=\"Count\">$Number</span>";
            } else {
                $Result = '';
            }
            return $Result;
        }
    
    }
    
Sign In or Register to comment.