Skip to content

Commit

Permalink
Add dba/counts handler
Browse files Browse the repository at this point in the history
Closes vanilla#1896.

When deleting spammers, I found my tag counts would be messed up if they
used any tags. This fixes that.
  • Loading branch information
hgtonight committed May 5, 2014
1 parent 2dab6d6 commit e6d0ff8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions plugins/Tagging/class.tagging.plugin.php
Expand Up @@ -609,6 +609,18 @@ public function Controller_Delete($Sender) {
$Sender->Render('delete', '', 'plugins/Tagging');
}

/**
* Add update routines to the DBA controller
*
* @param DbaController $Sender
*/
public function DbaController_CountJobs_Handler($Sender) {
$Name = 'Recalculate Tag.CountDiscussions';
$Url = "/dba/counts.json?" . http_build_query(array('table' => 'Tag', 'column' => 'CountDiscussions'));

$Sender->Data['Jobs'][$Name] = $Url;
}

/**
* Setup is called when the plugin is enabled.
*/
Expand Down
21 changes: 21 additions & 0 deletions plugins/Tagging/class.tagmodel.php
Expand Up @@ -70,6 +70,27 @@ public function Save($FormPostValues, $Settings = FALSE) {
}
}
}

public function Counts($Column, $UserID = NULL) {
$Px = $this->Database->DatabasePrefix;
// Delete all the orphaned tagdiscussion records
$Sql = 'delete td.* ' .
"from {$Px}TagDiscussion as td " .
"left join {$Px}Discussion as d ON td.DiscussionID = d.DiscussionID " .
'where d.DiscussionID is null';

$this->Database->Query($Sql);

$Result = array('Complete' => TRUE);
switch($Column) {
case 'CountDiscussions':
Gdn::Database()->Query(DBAModel::GetCountSQL('count', 'Tag', 'TagDiscussion', 'CountDiscussions', 'DiscussionID', 'TagID', 'TagID'));
break;
default:
throw new Gdn_UserException("Unknown column $Column");
}
return $Result;
}

public static function ValidateTag($Tag) {
// Tags can't contain commas.
Expand Down

0 comments on commit e6d0ff8

Please sign in to comment.