1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-02 22:45:02 +03:00

Реализовано удаление связанных данных

This commit is contained in:
Alexey Kachayev 2009-10-25 20:01:05 +00:00
parent 48c3d4d688
commit dfd7d21907
8 changed files with 247 additions and 18 deletions

View file

@ -340,12 +340,12 @@ class LsComment extends Module {
$aCommentsRec=$this->BuildCommentsRecursive($aCommentsRow); $aCommentsRec=$this->BuildCommentsRecursive($aCommentsRow);
} }
$this->Cache_Set($aCommentsRec, "comment_target_{$sId}_{$sTargetType}", array("comment_new_{$sTargetType}_{$sId}"), 60*60*24*2); $this->Cache_Set($aCommentsRec, "comment_target_{$sId}_{$sTargetType}", array("comment_new_{$sTargetType}_{$sId}"), 60*60*24*2);
} }
if (!isset($aCommentsRec['comments'])) { if (!isset($aCommentsRec['comments'])) {
return array('comments'=>array(),'iMaxIdComment'=>0); return array('comments'=>array(),'iMaxIdComment'=>0);
} }
$aComments=$aCommentsRec; $aComments=$aCommentsRec;
$aComments['comments']=$this->GetCommentsAdditionalData(array_keys($aCommentsRec['comments'])); $aComments['comments']=$this->GetCommentsAdditionalData(array_keys($aCommentsRec['comments']));
foreach ($aComments['comments'] as $oComment) { foreach ($aComments['comments'] as $oComment) {
$oComment->setLevel($aCommentsRec['comments'][$oComment->getId()]); $oComment->setLevel($aCommentsRec['comments'][$oComment->getId()]);
} }
@ -402,12 +402,18 @@ class LsComment extends Module {
/** /**
* Обновляет статус у коммента - delete или publish * Обновляет статус у коммента - delete или publish
* *
* @param CommentEntity_Comment $oComment * @param CommentEntity_Comment $oComment
* @return unknown * @return bool
*/ */
public function UpdateCommentStatus(CommentEntity_Comment $oComment) { 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")); // временно, т.к. нужно использовать только при solid кеше
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_{$oComment->getId()}","comment_update_status_{$oComment->getTargetType()}")); $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()}"); $this->Cache_Delete("comment_{$oComment->getId()}");
@ -428,10 +434,16 @@ class LsComment extends Module {
return false; return false;
} }
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_status_{$sTargetType}")); $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 $this->Favourite_DeleteFavourite($oFavourite);
} }
return false; 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);
}
} }
?> ?>

View file

@ -126,7 +126,7 @@ class Mapper_Comment extends Mapper {
".Config::Get('db.table.comment_online')." ".Config::Get('db.table.comment_online')."
WHERE WHERE
target_type = ? target_type = ?
{ AND target_id NOT IN(?a) } { AND target_id NOT IN(?a) }
ORDER by comment_online_id desc limit 0, ?d ; "; ORDER by comment_online_id desc limit 0, ?d ; ";
$aComments=array(); $aComments=array();
@ -317,5 +317,33 @@ class Mapper_Comment extends Mapper {
} }
return false; 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;
}
} }
?> ?>

View file

@ -326,6 +326,21 @@ class LsFavourite extends Module {
public function SetFavouriteTargetPublish($sTargetId,$sTargetType,$iPublish) { public function SetFavouriteTargetPublish($sTargetId,$sTargetType,$iPublish) {
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("favourite_{$sTargetType}_change")); $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("favourite_{$sTargetType}_change"));
return $this->oMapper->SetFavouriteTargetPublish($sTargetId,$sTargetType,$iPublish); 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);
}
} }
?> ?>

View file

@ -267,5 +267,18 @@ class Mapper_Favourite extends Mapper {
? $aRow['count'] ? $aRow['count']
: false; : 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;
}
} }
?> ?>

View file

@ -167,10 +167,35 @@ class LsTopic extends Module {
*/ */
public function DeleteTopic($sTopicId) { public function DeleteTopic($sTopicId) {
$oTopic=$this->GetTopicById($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_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}"); $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) { public function SetFavouriteTopicPublish($sTopicId,$iPublish) {
return $this->Favourite_SetFavouriteTargetPublish($sTopicId,'topic',$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 $data[$sTopicId];
} }
return null; return null;
} }
/**
* Удаляет записи о чтении записей по списку идентификаторов
*
* @param array|int $aTopicId
* @return bool
*/
public function DeleteTopicReadByArrayId($aTopicId) {
if(!is_array($aTopicId)) $aTopicId = array($aTopicId);
return $this->oMapperTopic->DeleteTopicReadByArrayId($aTopicId);
}
/** /**
* Получить список просмотром/чтения топиков по списку айдишников * Получить список просмотром/чтения топиков по списку айдишников
* *

View file

@ -490,8 +490,24 @@ class Mapper_Topic extends Mapper {
"; ";
return $this->oDb->query($sql,$oTopicRead->getCommentCountLast(),$oTopicRead->getCommentIdLast(),$oTopicRead->getDateRead(),$oTopicRead->getTopicId(),$oTopicRead->getUserId()); 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) { public function GetTopicsReadByArray($aArrayId,$sUserId) {
if (!is_array($aArrayId) or count($aArrayId)==0) { if (!is_array($aArrayId) or count($aArrayId)==0) {
return array(); return array();

View file

@ -154,5 +154,23 @@ class LsVote extends Module {
} }
return $data; 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);
}
} }
?> ?>

View file

@ -59,5 +59,19 @@ class Mapper_Vote extends Mapper {
} }
return $aVotes; 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;
}
} }
?> ?>