From dfd7d219079dd764ea89cc1f3864406546dfda1f Mon Sep 17 00:00:00 2001 From: Alexey Kachayev Date: Sun, 25 Oct 2009 20:01:05 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/modules/comment/Comment.class.php | 103 ++++++++++++++++-- .../comment/mapper/Comment.mapper.class.php | 30 ++++- classes/modules/favourite/Favourite.class.php | 17 ++- .../mapper/Favourite.mapper.class.php | 13 +++ classes/modules/topic/Topic.class.php | 50 ++++++++- .../topic/mapper/Topic.mapper.class.php | 20 +++- classes/modules/vote/Vote.class.php | 18 +++ .../modules/vote/mapper/Vote.mapper.class.php | 14 +++ 8 files changed, 247 insertions(+), 18 deletions(-) diff --git a/classes/modules/comment/Comment.class.php b/classes/modules/comment/Comment.class.php index ccb81891..9839dab6 100644 --- a/classes/modules/comment/Comment.class.php +++ b/classes/modules/comment/Comment.class.php @@ -340,12 +340,12 @@ class LsComment extends Module { $aCommentsRec=$this->BuildCommentsRecursive($aCommentsRow); } $this->Cache_Set($aCommentsRec, "comment_target_{$sId}_{$sTargetType}", array("comment_new_{$sTargetType}_{$sId}"), 60*60*24*2); - } + } if (!isset($aCommentsRec['comments'])) { return array('comments'=>array(),'iMaxIdComment'=>0); } $aComments=$aCommentsRec; - $aComments['comments']=$this->GetCommentsAdditionalData(array_keys($aCommentsRec['comments'])); + $aComments['comments']=$this->GetCommentsAdditionalData(array_keys($aCommentsRec['comments'])); foreach ($aComments['comments'] as $oComment) { $oComment->setLevel($aCommentsRec['comments'][$oComment->getId()]); } @@ -402,12 +402,18 @@ class LsComment extends Module { /** * Обновляет статус у коммента - delete или publish * - * @param CommentEntity_Comment $oComment - * @return unknown + * @param CommentEntity_Comment $oComment + * @return bool */ public function UpdateCommentStatus(CommentEntity_Comment $oComment) { - if ($this->oMapper->UpdateComment($oComment)) { - //чистим зависимые кеши + if ($this->oMapper->UpdateComment($oComment)) { + /** + * Если комментарий удаляется, удаляем его из прямого эфира + */ + if($oComment->getDelete()) $this->DeleteCommentOnlineByArrayId($oComment->getId(),$oComment->getTargetType()); + /** + * Чистим зависимые кеши + */ $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update")); // временно, т.к. нужно использовать только при solid кеше $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_{$oComment->getId()}","comment_update_status_{$oComment->getTargetType()}")); $this->Cache_Delete("comment_{$oComment->getId()}"); @@ -428,10 +434,16 @@ class LsComment extends Module { return false; } $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_status_{$sTargetType}")); - // Если статус публикации успешно изменен, то меняем статус в отметке "избранное" - return ($this->oMapper->SetCommentsPublish($sTargetId,$sTargetType,$iPublish)) - ? $this->Favourite_SetFavouriteTargetPublish($oComment->getId(),'comment',$iPublish) - : false; + /** + * Если статус публикации успешно изменен, то меняем статус в отметке "избранное". + * Если комментарии снимаются с публикации, удаляем их из прямого эфира. + */ + if($this->oMapper->SetCommentsPublish($sTargetId,$sTargetType,$iPublish)){ + $this->Favourite_SetFavouriteTargetPublish($oComment->getId(),'comment',$iPublish); + if($iPublish!=1) $this->DeleteCommentOnlineByTargetId($sTargetId,$sTargetType); + return true; + } + return false; } /** * Удаляет коммент из прямого эфира @@ -625,6 +637,75 @@ class LsComment extends Module { return $this->Favourite_DeleteFavourite($oFavourite); } return false; - } + } + /** + * Удаляет комментарии из избранного по списку + * + * @param array $aCommentId + * @return bool + */ + public function DeleteFavouriteCommentsByArrayId($aCommentId) { + return $this->Favourite_DeleteFavouriteByTargetId($aCommentId, 'comment'); + } + /** + * Удаляет комментарии из базы данных + * + * @param array|int $aTargetId + * @param string $sTargetType + * @return bool + */ + public function DeleteCommentByTargetId($aTargetId,$sTargetType) { + if(!is_array($aTargetId)) $aTargetId = array($aTargetId); + /** + * Получаем список идентификаторов удаляемых комментариев + */ + $aCommentsId = array(); + foreach ($aTargetId as $sTargetId) { + $aComments=$this->GetCommentsByTargetId($sTargetId,$sTargetType); + $aCommentsId = array_merge($aCommentsId, array_keys($aComments['comments'])); + } + /** + * Если ни одного комментария не найдено, выходим + */ + if(!count($aCommentsId)) return true; + /** + * Чистим зависимые кеши + */ + $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update")); // временно, т.к. нужно использовать только при solid кеше + //$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_{$oComment->getId()}","comment_update_status_{$oComment->getTargetType()}")); + //$this->Cache_Delete("comment_{$oComment->getId()}"); + if($this->oMapper->DeleteCommentByTargetId($aTargetId,$sTargetType)){ + /** + * Удаляем комментарии из избранного + */ + $this->DeleteFavouriteCommentsByArrayId($aCommentsId); + /** + * Удаляем комментарии к топику из прямого эфира + */ + $this->DeleteCommentOnlineByArrayId($aCommentsId,$sTargetType); + /** + * Удаляем голосование за комментарии + */ + $this->Vote_DeleteVoteByTarget($aCommentsId,'comment'); + return true; + } + return false; + } + + /** + * Удаляет коммент из прямого эфира по массиву переданных идентификаторов + * + * @param (array|int) $aCommentId + * @param string $sTargetType + * @return bool + */ + public function DeleteCommentOnlineByArrayId($aCommentId,$sTargetType) { + if(!is_array($aCommentId)) $aCommentId = array($aCommentId); + /** + * Чистим кеш + */ + $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$sTargetType}")); + return $this->oMapper->DeleteCommentOnlineByArrayId($aCommentId,$sTargetType); + } } ?> \ No newline at end of file diff --git a/classes/modules/comment/mapper/Comment.mapper.class.php b/classes/modules/comment/mapper/Comment.mapper.class.php index 56e5f31e..e141a77f 100644 --- a/classes/modules/comment/mapper/Comment.mapper.class.php +++ b/classes/modules/comment/mapper/Comment.mapper.class.php @@ -126,7 +126,7 @@ class Mapper_Comment extends Mapper { ".Config::Get('db.table.comment_online')." WHERE target_type = ? - { AND target_id NOT IN(?a) } + { AND target_id NOT IN(?a) } ORDER by comment_online_id desc limit 0, ?d ; "; $aComments=array(); @@ -317,5 +317,33 @@ class Mapper_Comment extends Mapper { } return false; } + + public function DeleteCommentByTargetId($aTargetId,$sTargetType) { + $sql = " + DELETE FROM ".Config::Get('db.table.comment')." + WHERE + target_type = ? + AND + target_id IN (?a) + "; + if ($this->oDb->query($sql,$sTargetType,$aTargetId)) { + return true; + } + return false; + } + + public function DeleteCommentOnlineByArrayId($aCommentId,$sTargetType) { + $sql = " + DELETE FROM ".Config::Get('db.table.comment_online')." + WHERE + comment_id IN (?a) + AND + target_type = ? + "; + if ($this->oDb->query($sql,$aCommentId,$sTargetType)) { + return true; + } + return false; + } } ?> \ No newline at end of file diff --git a/classes/modules/favourite/Favourite.class.php b/classes/modules/favourite/Favourite.class.php index 13262c9a..6e24c921 100644 --- a/classes/modules/favourite/Favourite.class.php +++ b/classes/modules/favourite/Favourite.class.php @@ -326,6 +326,21 @@ class LsFavourite extends Module { public function SetFavouriteTargetPublish($sTargetId,$sTargetType,$iPublish) { $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("favourite_{$sTargetType}_change")); return $this->oMapper->SetFavouriteTargetPublish($sTargetId,$sTargetType,$iPublish); - } + } + /** + * Удаляет избранное по списку идентификаторов таргетов + * + * @param array|int $aTargetId + * @param string $sTargetType + * @return bool + */ + public function DeleteFavouriteByTargetId($aTargetId, $sTargetType) { + if(!is_array($aTargetId)) $aTargetId = array($aTargetId); + /** + * Чистим зависимые кеши + */ + $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("favourite_{$sTargetType}_change")); + return $this->oMapper->DeleteFavouriteByTargetId($aTargetId,$sTargetType); + } } ?> \ No newline at end of file diff --git a/classes/modules/favourite/mapper/Favourite.mapper.class.php b/classes/modules/favourite/mapper/Favourite.mapper.class.php index 21c40063..5d7e03d0 100644 --- a/classes/modules/favourite/mapper/Favourite.mapper.class.php +++ b/classes/modules/favourite/mapper/Favourite.mapper.class.php @@ -267,5 +267,18 @@ class Mapper_Favourite extends Mapper { ? $aRow['count'] : false; } + + public function DeleteFavouriteByTargetId($aTargetId,$sTargetType) { + $sql = " + DELETE FROM ".Config::Get('db.table.favourite')." + WHERE + target_id IN(?a) + AND + target_type = ? "; + if ($this->oDb->query($sql,$aTargetId,$sTargetType)) { + return true; + } + return false; + } } ?> \ No newline at end of file diff --git a/classes/modules/topic/Topic.class.php b/classes/modules/topic/Topic.class.php index 5525028a..f55cf46d 100644 --- a/classes/modules/topic/Topic.class.php +++ b/classes/modules/topic/Topic.class.php @@ -167,10 +167,35 @@ class LsTopic extends Module { */ public function DeleteTopic($sTopicId) { $oTopic=$this->GetTopicById($sTopicId); - //чистим зависимые кеши + /** + * Чистим зависимые кеши + */ $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array('topic_update',"topic_update_user_{$oTopic->getUserId()}","topic_update_blog_{$oTopic->getBlogId()}")); $this->Cache_Delete("topic_{$sTopicId}"); - return $this->oMapperTopic->DeleteTopic($sTopicId); + /** + * Если топик успешно удален, удаляем связанные данные + */ + if($this->oMapperTopic->DeleteTopic($sTopicId)){ + /** + * Удаляем комментарии к топику. + * При удалении комментариев они удаляются из избранного,прямого эфира и голоса за них + */ + $this->Comment_DeleteCommentByTargetId($sTopicId,'topic'); + /** + * Удаляем топик из избранного + */ + $this->DeleteFavouriteTopicByArrayId($sTopicId); + /** + * Удаляем топик из прочитанного + */ + $this->DeleteTopicReadByArrayId($sTopicId); + /** + * Удаляем голосование к топику + */ + $this->Vote_DeleteVoteByTarget($sTopicId,'topic'); + return true; + } + return false; } /** * Обновляет топик @@ -912,6 +937,15 @@ class LsTopic extends Module { */ public function SetFavouriteTopicPublish($sTopicId,$iPublish) { return $this->Favourite_SetFavouriteTargetPublish($sTopicId,'topic',$iPublish); + } + /** + * Удаляет топики из избранного по списку + * + * @param array $aTopicId + * @return bool + */ + public function DeleteFavouriteTopicByArrayId($aTopicId) { + return $this->Favourite_DeleteFavouriteByTargetId($aTopicId, 'topic'); } /** * Получает список тегов по первым буквам тега @@ -956,7 +990,17 @@ class LsTopic extends Module { return $data[$sTopicId]; } return null; - } + } + /** + * Удаляет записи о чтении записей по списку идентификаторов + * + * @param array|int $aTopicId + * @return bool + */ + public function DeleteTopicReadByArrayId($aTopicId) { + if(!is_array($aTopicId)) $aTopicId = array($aTopicId); + return $this->oMapperTopic->DeleteTopicReadByArrayId($aTopicId); + } /** * Получить список просмотром/чтения топиков по списку айдишников * diff --git a/classes/modules/topic/mapper/Topic.mapper.class.php b/classes/modules/topic/mapper/Topic.mapper.class.php index e8dead20..9af12b1d 100644 --- a/classes/modules/topic/mapper/Topic.mapper.class.php +++ b/classes/modules/topic/mapper/Topic.mapper.class.php @@ -490,8 +490,24 @@ class Mapper_Topic extends Mapper { "; return $this->oDb->query($sql,$oTopicRead->getCommentCountLast(),$oTopicRead->getCommentIdLast(),$oTopicRead->getDateRead(),$oTopicRead->getTopicId(),$oTopicRead->getUserId()); } - - + /** + * Удаляет записи о чтении записей по списку идентификаторов + * + * @param array $aTopicId + * @return bool + */ + public function DeleteTopicReadByArrayId($aTopicId) { + $sql = " + DELETE FROM ".Config::Get('db.table.topic_read')." + WHERE + topic_id IN(?a) + "; + if ($this->oDb->query($sql,$aTopicId)) { + return true; + } + return false; + } + public function GetTopicsReadByArray($aArrayId,$sUserId) { if (!is_array($aArrayId) or count($aArrayId)==0) { return array(); diff --git a/classes/modules/vote/Vote.class.php b/classes/modules/vote/Vote.class.php index 601845d4..aa1fa81b 100644 --- a/classes/modules/vote/Vote.class.php +++ b/classes/modules/vote/Vote.class.php @@ -154,5 +154,23 @@ class LsVote extends Module { } return $data; } + + /** + * Удаляет голосование из базы по списку идентификаторов таргета + * + * @param array|int $aTargetId + * @param string $sTargetType + * @return bool + */ + public function DeleteVoteByTarget($aTargetId, $sTargetType) { + if (!is_array($aTargetId)) $aTargetId=array($aTargetId); + $aTargetId=array_unique($aTargetId); + + /** + * Чистим зависимые кеши + */ + $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("vote_update_{$sTargetType}")); + return $this->oMapper->DeleteVoteByTarget($aTargetId,$sTargetType); + } } ?> \ No newline at end of file diff --git a/classes/modules/vote/mapper/Vote.mapper.class.php b/classes/modules/vote/mapper/Vote.mapper.class.php index efed1546..3ce54a6f 100644 --- a/classes/modules/vote/mapper/Vote.mapper.class.php +++ b/classes/modules/vote/mapper/Vote.mapper.class.php @@ -59,5 +59,19 @@ class Mapper_Vote extends Mapper { } return $aVotes; } + + public function DeleteVoteByTarget($aTargetId,$sTargetType) { + $sql = " + DELETE FROM ".Config::Get('db.table.vote')." + WHERE + target_id IN(?a) + AND + target_type = ? + "; + if ($this->oDb->query($sql,$aTargetId,$sTargetType)) { + return true; + } + return false; + } } ?> \ No newline at end of file