[Jaws-commits] r13374 - trunk/jaws/html/gadgets/Blog

afz at jaws-project.com afz at jaws-project.com
Fri Aug 10 21:14:31 UTC 2012


Author: afz
Date: 2012-08-10 21:14:30 +0000 (Fri, 10 Aug 2012)
New Revision: 13374

Modified:
   trunk/jaws/html/gadgets/Blog/AdminModel.php
   trunk/jaws/html/gadgets/Blog/Model.php
Log:
[Blog]: using query count for update comments count

Modified: trunk/jaws/html/gadgets/Blog/AdminModel.php
===================================================================
--- trunk/jaws/html/gadgets/Blog/AdminModel.php	2012-08-10 19:43:04 UTC (rev 13373)
+++ trunk/jaws/html/gadgets/Blog/AdminModel.php	2012-08-10 21:14:30 UTC (rev 13374)
@@ -827,12 +827,19 @@
         }
 
         if ($comment['status'] == COMMENT_STATUS_APPROVED) {
-            $sql = 'UPDATE [[blog]] SET [comments] = [comments] - 1 WHERE [id] = {id}';
-            $result = $GLOBALS['db']->query($sql, array('id' => $comment['gadget_reference']));
-
-            if (Jaws_Error::IsError($result)) {
-                $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_COMMENT_NOT_DELETED'), RESPONSE_ERROR);
-                return new Jaws_Error(_t('BLOG_ERROR_COMMENT_NOT_DELETED'), _t('BLOG_NAME'));
+            $params = array();
+            $params['id'] = $comment['gadget_reference'];
+            $howmany = $api->HowManyFilteredComments('gadget_reference',
+                                                     $comment['gadget_reference'],
+                                                     'approved');
+            if (!Jaws_Error::IsError($howmany)) {
+                $params['comments'] = $howmany;
+                $sql = 'UPDATE [[blog]] SET [comments] = {comments} WHERE [id] = {id}';
+                $result = $GLOBALS['db']->query($sql, $params);
+                if (Jaws_Error::IsError($result)) {
+                    $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_COMMENT_NOT_DELETED'), RESPONSE_ERROR);
+                    return new Jaws_Error(_t('BLOG_ERROR_COMMENT_NOT_DELETED'), _t('BLOG_NAME'));
+                }
             }
         }
 
@@ -868,28 +875,27 @@
 
         require_once JAWS_PATH.'include/Jaws/Comment.php';
         $api = new Jaws_Comment($this->_Name);
+        $api->MarkAs($ids, $status);
 
         // Fix blog comment counter...
         foreach ($ids as $id) {
             $comment = $api->GetComment($id);
-            if (($comment['status'] != COMMENT_STATUS_APPROVED) && ($status == COMMENT_STATUS_APPROVED)){
-                $sql = 'UPDATE [[blog]] SET [comments] = [comments] + 1 WHERE [id] = {id}';
-                $result = $GLOBALS['db']->query($sql, array('id' => $comment['gadget_reference']));
+            $params = array();
+            $params['id'] = $comment['gadget_reference'];
+            $howmany = $api->HowManyFilteredComments('gadget_reference',
+                                                     $comment['gadget_reference'],
+                                                     'approved');
+            if (!Jaws_Error::IsError($howmany)) {
+                $params['comments'] = $howmany;
+                $sql = 'UPDATE [[blog]] SET [comments] = {comments} WHERE [id] = {id}';
+                $result = $GLOBALS['db']->query($sql, $params);
                 if (Jaws_Error::IsError($result)) {
                     $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_COMMENT_NOT_UPDATED'), RESPONSE_ERROR);
                     return new Jaws_Error(_t('BLOG_ERROR_COMMENT_NOT_UPDATED'), _t('BLOG_NAME'));
                 }
-            } elseif (($comment['status'] == COMMENT_STATUS_APPROVED) && ($status != COMMENT_STATUS_APPROVED)) {
-                $sql = 'UPDATE [[blog]] SET [comments] = [comments] - 1 WHERE [id] = {id}';
-                $result = $GLOBALS['db']->query($sql, array('id' => $comment['gadget_reference']));
-                if (Jaws_Error::IsError($result)) {
-                    $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_COMMENT_NOT_UPDATED'), RESPONSE_ERROR);
-                    return new Jaws_Error(_t('BLOG_ERROR_COMMENT_NOT_UPDATED'), _t('BLOG_NAME'));
-                }
             }
         }
 
-        $api->MarkAs($ids, $status);
         $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_COMMENT_MARKED'), RESPONSE_NOTICE);
         return true;
     }

Modified: trunk/jaws/html/gadgets/Blog/Model.php
===================================================================
--- trunk/jaws/html/gadgets/Blog/Model.php	2012-08-10 19:43:04 UTC (rev 13373)
+++ trunk/jaws/html/gadgets/Blog/Model.php	2012-08-10 21:14:30 UTC (rev 13374)
@@ -850,18 +850,23 @@
                                     $name, $email, $url, $title, $comments,
                                     $ip, $permalink, $parent, $status);
 
-            //Update comments counter to +1
+            //Update comments counter
             if (!Jaws_Error::IsError($res)) {
                 //Send an email to blog entry author and website owner
                 $this->MailComment($parentId, $title, $email, $comments, $url);
                 if ($res == COMMENT_STATUS_APPROVED) {
-                    $sql = 'UPDATE [[blog]] SET [comments] = [comments] + 1 WHERE [id] = {id}';
-                    $params       = array();
+                    $params = array();
                     $params['id'] = $id;
-
-                    $result = $GLOBALS['db']->query($sql, $params);
-                    if (Jaws_Error::IsError($result)) {
-                        return new Jaws_Error(_t('BLOG_ERROR_COMMENT_NOT_ADDED'), _t('BLOG_NAME'));
+                    $howmany = $api->HowManyFilteredComments('gadget_reference',
+                                                             $id,
+                                                             'approved');
+                    if (!Jaws_Error::IsError($howmany)) {
+                        $params['comments'] = $howmany;
+                        $sql = 'UPDATE [[blog]] SET [comments] = {comments} WHERE [id] = {id}';
+                        $result = $GLOBALS['db']->query($sql, $params);
+                        if (Jaws_Error::IsError($result)) {
+                            return new Jaws_Error(_t('BLOG_ERROR_COMMENT_NOT_ADDED'), _t('BLOG_NAME'));
+                        }
                     }
                 }
 



More information about the Jaws-commits mailing list