Fork me on GitHub
Please upgrade to 2.1.x here. The 2.0 branch is no longer being updated.
Important security fix: 2.1.10, released 4 May.

Tagged error when deleting post

edited December 2010 in Vanilla 2.0 Help
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

  • LincLinc Community Instigator Detroit Vanilla Staff

    Sr Developer at Vanilla Forums, humble servant of Lord Brackos, & pro smatcher. [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
Sign In or Register to comment.