Alex Trofimov 12 лет назад
Родитель
Сommit
54bfa96257

+ 41 - 7
inc/classes/BxDolCmts.php

@@ -493,8 +493,11 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
     public function onObjectDelete ($iObjectId = 0)
     {
         // delete comments
-        $aFiles = array();
-        $this->_oQuery->deleteObjectComments ($iObjectId ? $iObjectId : $this->getId(), $aFiles);
+        $aFiles = $aCmtIds = array();
+        $this->_oQuery->deleteObjectComments ($iObjectId ? $iObjectId : $this->getId(), $aFiles, $aCmtIds);
+
+        // delete meta info
+        $this->deleteMetaInfo($aCmtIds);
 
         // delete files
         if ($aFiles) {
@@ -514,9 +517,12 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
             $oQuery = $o->getQueryObject();
 
             // delete comments
-            $aFiles = array ();
-            $oQuery->deleteAuthorComments($iAuthorId, $aFiles);
+            $aFiles = $aCmtIds = array ();
+            $oQuery->deleteAuthorComments($iAuthorId, $aFiles, $aCmtIds);
 
+            // delete meta info
+            $this->deleteMetaInfo($aCmtIds);
+    
             // delete files
             $oStorage = BxDolStorage::getObjectInstance($o->getStorageObjectName());
             if ($oStorage)
@@ -537,8 +543,11 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
             $oQuery = $o->getQueryObject();
 
             // delete comments
-            $aFiles = array ();
-            $oQuery->deleteAll($aSystem['system_id'], $aFiles);
+            $aFiles = $aCmtIds = array ();
+            $oQuery->deleteAll($aSystem['system_id'], $aFiles, $aCmtIds);
+
+            // delete meta info
+            $this->deleteMetaInfo($aCmtIds);
 
             // delete files
             $oStorage = BxDolStorage::getObjectInstance($o->getStorageObjectName());
@@ -552,6 +561,23 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
         return true;
     }
 
+    function deleteMetaInfo ($mixedCmtId)
+    {
+        if (!$this->_sMetatagsObj)
+            return;
+
+        if (!is_array($mixedCmtId))
+            $mixedCmtId = array($mixedCmtId);
+
+        bx_import('BxDolMetatags');
+        $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
+
+        foreach ($mixedCmtId as $iCmtId) {
+            $oMetatags->onDeleteContent($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId));
+            $this->_oQuery->deleteCmtIds($this->_aSystem['system_id'], $iCmtId);
+        }
+    }
+
     /**
      * Permissions functions
      */
@@ -754,6 +780,8 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
 
             $this->isRemoveAllowed(true);
 
+            $this->deleteMetaInfo ($aCmt['cmt_id']);
+
             bx_import('BxDolAlerts');
             $oZ = new BxDolAlerts($this->_sSystem, 'commentRemoved', $this->getId(), $iCmtAuthorId, array('comment_id' => $aCmt['cmt_id'], 'comment_author_id' => $aCmt['cmt_author_id']));
             $oZ->alert();
@@ -842,7 +870,7 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
         return bx_process_input($s, $iDataAction);
     }
 
-    protected function _prepareTextForOutput ($s)
+    protected function _prepareTextForOutput ($s, $iCmtId = 0)
     {
     	bx_import('BxDolTemplate');
     	$oTemplate = BxDolTemplate::getInstance();
@@ -866,6 +894,12 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
         	));
         }, $s);
 
+        if ($this->_sMetatagsObj && $iCmtId) {
+            bx_import('BxDolMetatags');
+            $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
+            $s = $oMetatags->keywordsParse($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $s);
+        }
+
         return $s;
     }
 

+ 23 - 6
inc/classes/BxDolCmtsQuery.php

@@ -265,7 +265,7 @@ class BxDolCmtsQuery extends BxDolDb
         return $this->query($sQuery);
     }
 
-    function deleteAuthorComments ($iAuthorId, &$aFiles = null)
+    function deleteAuthorComments ($iAuthorId, &$aFiles = null, &$aCmtIds = null)
     {
         $aSystem = $this->_oMain->getSystemInfo();
 
@@ -284,6 +284,9 @@ class BxDolCmtsQuery extends BxDolDb
             if ($aFilesMore && null !== $aFiles)
                 $aFiles = array_merge($aFiles, $aFilesMore);
 
+            if (null !== $aCmtIds)
+                $aCmtIds[] = $r['cmt_id'];
+
             $isDelOccured = 1;
         }
         $sQuery = $this->prepare("UPDATE {$this->_sTable} SET `cmt_author_id` = 0 WHERE `cmt_author_id` = ? AND `cmt_replies` != 0", $iAuthorId);
@@ -292,7 +295,7 @@ class BxDolCmtsQuery extends BxDolDb
             $this->query ("OPTIMIZE TABLE {$this->_sTable}");
     }
 
-    function deleteObjectComments ($iObjectId, &$aFilesReturn = null)
+    function deleteObjectComments ($iObjectId, &$aFilesReturn = null, &$aCmtIds = null)
     {
         $aSystem = $this->_oMain->getSystemInfo();
         $aFiles = $this->convertImagesArray($this->getImages($aSystem['system_id'], false, $iObjectId));
@@ -303,6 +306,11 @@ class BxDolCmtsQuery extends BxDolDb
             $this->query ($sQuery);
         }
 
+        if (null !== $aCmtIds) {
+            $sQuery = $this->prepare("SELECT `cmt_id` FROM {$this->_sTable} WHERE `cmt_object_id` = ?", $iObjectId);
+            $aCmtIds = $this->getColumn ($sQuery);
+        }
+
         $sQuery = $this->prepare("DELETE FROM {$this->_sTable} WHERE `cmt_object_id` = ?", $iObjectId);
         $this->query ($sQuery);
         $this->query ("OPTIMIZE TABLE {$this->_sTable}");
@@ -311,7 +319,7 @@ class BxDolCmtsQuery extends BxDolDb
             $aFilesReturn = $aFiles;
     }
 
-    function deleteAll ($iSystemId, &$aFiles = null)
+    function deleteAll ($iSystemId, &$aFiles = null, &$aCmtIds = null)
     {
         // get files
         if (null !== $aFiles)
@@ -320,11 +328,20 @@ class BxDolCmtsQuery extends BxDolDb
         // delete files
         $this->deleteImages($iSystemId, false);
 
+        if (null !== $aCmtIds)
+            $aCmtIds = $this->getColumn ("SELECT `cmt_id` FROM {$this->_sTable}");
+
         // delete comments
         $sQuery = $this->prepare("TRUNCATE TABLE {$this->_sTable}");
         $this->query ($sQuery);
     }
 
+    function deleteCmtIds ($iSystemId, $iCmtId)
+    {
+        $sQuery = $this->prepare("DELETE FROM {$this->_sTableIds} WHERE `system_id` = ? AND `cmt_id` = ?", $iSystemId, $iCmtId);
+        return $this->query ($sQuery);
+    }
+
     function getObjectTitle($iId)
     {
         $sQuery = $this->prepare("SELECT `{$this->_sTriggerFieldTitle}` FROM `{$this->_sTriggerTable}` WHERE `{$this->_sTriggerFieldId}` = ? LIMIT 1", $iId);
@@ -337,13 +354,13 @@ class BxDolCmtsQuery extends BxDolDb
         return $this->query($sQuery);
     }
 
-    function getUniqId($iSystemId, $iObjId)
+    function getUniqId($iSystemId, $iCmtId)
     {
-        $sQuery = $this->prepare("SELECT `id` FROM `{$this->_sTableIds}` WHERE `system_id` = ? AND `obj_id` = ?", $iSystemId, $iObjId);
+        $sQuery = $this->prepare("SELECT `id` FROM `{$this->_sTableIds}` WHERE `system_id` = ? AND `cmt_id` = ?", $iSystemId, $iCmtId);
         if ($iUniqId = $this->getOne($sQuery))
             return $iUniqId;
             
-        $sQuery = $this->prepare("INSERT INTO `{$this->_sTableIds}` SET `system_id` = ?, `obj_id` = ?", $iSystemId, $iObjId);
+        $sQuery = $this->prepare("INSERT INTO `{$this->_sTableIds}` SET `system_id` = ?, `cmt_id` = ?", $iSystemId, $iCmtId);
         if (!$this->query($sQuery))
             return false;
 

+ 6 - 1
inc/classes/BxDolMetatags.php

@@ -421,7 +421,12 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
      */
     public function onDeleteContent($iId) 
     {
-        // TODO: 
+        $i = 0;
+        foreach ($this->_aMetas as $sMeta) {
+            $sFunc = $sMeta . 'Delete';
+            $i += $this->_oQuery->$sFunc($iId);
+        }
+        return $i;
     }
 
 }

+ 2 - 2
install/sql/system.sql

@@ -852,9 +852,9 @@ CREATE TABLE IF NOT EXISTS `sys_cmts_images2entries` (
 CREATE TABLE IF NOT EXISTS `sys_cmts_ids` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `system_id` int(11) NOT NULL DEFAULT '0',
-  `obj_id` int(11) NOT NULL DEFAULT '0',
+  `cmt_id` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`),
-  UNIQUE KEY `system_obj_id` (`system_id`,`obj_id`)
+  UNIQUE KEY `system_cmt_id` (`system_id`,`cmt_id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 CREATE TABLE IF NOT EXISTS `sys_cmts_meta_keywords` (

+ 4 - 0
modules/base/text/classes/BxBaseModTextFormEntry.php

@@ -131,6 +131,10 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
         if ($o) $o->onObjectDelete();
 
+        bx_import('BxDolMetatags');
+        $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
+        $oMetatags->onDeleteContent($iContentId);
+
         // delete db record
 
         return parent::delete($iContentId);

+ 5 - 5
template/scripts/BxBaseCmts.php

@@ -205,8 +205,8 @@ class BxBaseCmts extends BxDolCmts
             $sText = trim(substr($sText, 0, $iLength));
         }
 
-        $sText = $this->_prepareTextForOutput($sText);
-        $sTextMore = $this->_prepareTextForOutput($sTextMore);
+        $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
+        $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
 
         $aTmplReplyTo = array();
         if((int)$aCmt['cmt_parent_id'] != 0) {
@@ -609,7 +609,7 @@ class BxBaseCmts extends BxDolCmts
                 if ($this->_sMetatagsObj) {
                     bx_import('BxDolMetatags');
                     $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
-                    $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $this->getId()), $sCmtText);
+                    $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
                 }
 
                 bx_import('BxDolAlerts');
@@ -651,14 +651,14 @@ class BxBaseCmts extends BxDolCmts
                 if ($this->_sMetatagsObj) {
                     bx_import('BxDolMetatags');
                     $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
-                    $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $this->getId()), $sCmtText);
+                    $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
                 }
 
                 bx_import('BxDolAlerts');
                 $oZ = new BxDolAlerts($this->_sSystem, 'commentUpdated', $this->getId(), $iCmtAuthorId, array('comment_id' => $aCmt['cmt_id'], 'comment_author_id' => $aCmt['cmt_author_id']));
                 $oZ->alert();
 
-                return array('id' => $iCmtId, 'text' => $sCmtText);
+                return array('id' => $iCmtId, 'text' => $this->_prepareTextForOutput($sCmtText, $iCmtId));
             }
 
             return array('msg' => _t('_cmt_err_cannot_perform_action'));