瀏覽代碼

#993 Converations: records from table "bx_convos_conversations" and "bx_convos_conv2folder" are not removed

Alex Trofimov 8 年之前
父節點
當前提交
767a3da01a

+ 3 - 0
modules/boonex/convos/classes/BxCnvAlertsResponse.php

@@ -22,6 +22,9 @@ class BxCnvAlertsResponse extends BxBaseModTextAlertsResponse
         if ($this->MODULE == $oAlert->sUnit && 'commentPost' == $oAlert->sAction)
             BxDolService::call($this->MODULE, 'trigger_comment_post', array($oAlert->iObject, $oAlert->aExtras['comment_author_id'], $oAlert->aExtras['comment_id'], 0, $oAlert->aExtras['comment_text']));
 
+        if ('profile' == $oAlert->sUnit && 'delete' == $oAlert->sAction && (!isset($oAlert->aExtras['delete_with_content']) || !$oAlert->aExtras['delete_with_content']))
+            BxDolService::call($this->MODULE, 'remove_collaborator_from_all_conversations', array($oAlert->iObject));
+        
         parent::response($oAlert);
     }
 }

+ 22 - 2
modules/boonex/convos/classes/BxCnvDb.php

@@ -43,6 +43,24 @@ class BxCnvDb extends BxBaseModTextDb
         return $this->query($sQuery);
     }
 
+    /**
+     * Remove collaborator from all conversations (when profile is deleted)
+     * @param $iProfileId profile id to remove
+     * @return number of deletions
+     */
+    public function removeCollaboratorFromAllConversations($iProfileId)
+    {
+        $aConvos = $this->getColumn("SELECT `conv_id` FROM `" . $this->getPrefix() . "conv2folder` WHERE `collaborator` = ?", array($iProfileId));
+        if (!($iRet = $this->query("DELETE FROM `" . $this->getPrefix() . "conv2folder` WHERE `collaborator` = ?", array($iProfileId))))
+            return 0;
+
+        foreach ($aConvos as $iConversationId) {
+            if (!$this->getCollaborators($iConversationId))
+                $this->deleteConvo($iConversationId);
+        }
+        return $iRet;
+    }
+    
     public function getCollaborators($iConversationId)
     {
         $sQuery = $this->prepare("SELECT `collaborator`, `read_comments` FROM `" . $this->getPrefix() . "conv2folder` WHERE `conv_id` = ?", $iConversationId);
@@ -91,10 +109,12 @@ class BxCnvDb extends BxBaseModTextDb
         }
 
         $sQuery = "DELETE FROM `" . $this->getPrefix() . "conv2folder` WHERE `conv_id` = :conv_id" . $sWhere;
-        if (!$this->query($sQuery, $aBindings))
-            return false;
+        $this->query($sQuery, $aBindings);
 
         // delete whole conversation if there is no refencences to the conversation in conv2folder table
+        if ($this->getCollaborators($iConversationId))
+            return false;
+            
         $sQuery = $this->prepare("SELECT `id` FROM `" . $this->getPrefix() . "conv2folder` WHERE `conv_id` = ?", $iConversationId);
         if (!$this->getOne($sQuery)) {
             $CNF = &$this->_oConfig->CNF;

+ 38 - 0
modules/boonex/convos/classes/BxCnvModule.php

@@ -325,6 +325,44 @@ class BxCnvModule extends BxBaseModTextModule
         return '';
     }
 
+    /**
+     * Delete content entry
+     * @param $iContentId content id 
+     * @return error message or empty string on success
+     */
+    public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
+    {
+        return $this->_oDb->deleteConvo($iContentId);
+    }
+    
+    /**
+     * Delete profile from all conversation (when profile is delete without content)
+     * @param $iProfileId profile id 
+     * @return number of deleted items
+     */    
+    public function serviceRemoveCollaboratorFromAllConversations ($iProfileId)
+    {
+        return $this->_oDb->removeCollaboratorFromAllConversations((int)$iProfileId);
+    }
+    
+    /**
+     * Delete all content by profile (when profile is delete with content)
+     * @param $iProfileId profile id 
+     * @return number of deleted items
+     */
+    public function serviceDeleteEntitiesByAuthor ($iProfileId)
+    {
+        $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
+        if (!$a)
+            return 0;
+
+        $iCount = 0;
+        foreach ($a as $aContentInfo)
+            $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
+
+        return $iCount;
+    }
+    
     /**
      * No moderators for personal convos
      */