Skip to content

Commit

Permalink
adding a shell to fix the comment counts
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Jan 18, 2013
1 parent b737501 commit 5869452
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Core/Comments/Console/Command/CommentShell.php
@@ -0,0 +1,31 @@
<?php
class CommentShell extends AppShell {

public $uses = array(
'Comments.InfinitasComment'
);

public function main() {
$this->InfinitasComment->virtualFields['count'] = 'COUNT(InfinitasComment.id)';
$comments = $this->InfinitasComment->find('all', array(
'fields' => array(
'count',
$this->InfinitasComment->alias . '.class',
$this->InfinitasComment->alias . '.foreign_id',
),
'conditions' => array(
$this->InfinitasComment->alias . '.active' => 1
),
'group' => array(
$this->InfinitasComment->alias . '.class',
$this->InfinitasComment->alias . '.foreign_id',
)
));

foreach ($comments as $comment) {
$Model = ClassRegistry::init(ucfirst($comment['InfinitasComment']['class']));
$Model->id = $comment['InfinitasComment']['foreign_id'];
$Model->saveField('comment_count', $comment['InfinitasComment']['count']);
}
}
}

0 comments on commit 5869452

Please sign in to comment.