Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter
Support for Vanilla Forums Cloud product

In this Discussion

Follow Us


Tagged error when deleting post

edited December 2010 in Questions
When deleting a post with tags, the number of this tag is not refreshed. For example a post with the tag "board" is deleted, then the number behind the tag "board" is the same.
Tagged:

Comments

  • LincolnLincoln Community Instigator Vanilla Staff

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • For those who want the fix, just add this to your "class TaggingPlugin extends Gdn_Plugin" definition in class.tagging.plugin.php:



    /**
    * !!!! TEMPORARY FIX (by sprockett) !!!!!
    * Reduce counts, Remove tags, and Remove tag-discussion mapping upon deletion of Discussion
    */
    public function DiscussionModel_DeleteDiscussion_Handler($Sender) {
    //Ensure this gets fired only if Tagging is enabled.
    if (!C('Plugins.Tagging.Enabled'))
    return;

    //Get discussionID that is being deleted
    $DiscussionID =$Sender->EventArguments['DiscussionID'];

    //Get List of tags to reduce count for
    $TagDataSet = Gdn::SQL()->Select('TagID')
    ->From('tagdiscussion')
    ->Where('DiscussionID =',$DiscussionID)
    ->Get();
    while ($SingleTag = $TagDataSet->NextRow(DATASET_TYPE_ARRAY)) {
    $RemovedTagIDs[]=$SingleTag['TagID'];
    }

    //Check if there are even any tags to delete
    if (count($RemovedTagIDs) > 0) {
    // Step 1: Reduce count
    Gdn::SQL()->Update('Tag')->Set('CountDiscussions', 'CountDiscussions - 1', FALSE)->WhereIn('TagID', $RemovedTagIDs)->Put();
    // Step 2: Delete tag entries from table if they hit zero count.
    $Sender->SQL->Where('CountDiscussions <=', '0')->Delete('Tag');
    // Step 3: Delete mapping data between discussion and tag (tagdiscussion table)
    $Sender->SQL->Where('DiscussionID', $DiscussionID)->Delete('tagdiscussion');
    }
    }
  • I have uploaded an modifed version of the original Tagging plugin. This addresses the above problem, and adds another feature where you can see tags that belong in one category.

    http://vanillaforums.org/addon/tagging-plugin-1.0.0
  • Thanks for your help.
Sign In or Register to comment.