mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-04 23:44:25 +03:00
Реализовано удаление связанных данных
This commit is contained in:
parent
48c3d4d688
commit
dfd7d21907
|
@ -403,11 +403,17 @@ 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;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Удаляет коммент из прямого эфира
|
* Удаляет коммент из прямого эфира
|
||||||
|
@ -626,5 +638,74 @@ class LsComment extends Module {
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -327,5 +327,20 @@ class LsFavourite extends Module {
|
||||||
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -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;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Обновляет топик
|
* Обновляет топик
|
||||||
|
@ -913,6 +938,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');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Получает список тегов по первым буквам тега
|
* Получает список тегов по первым буквам тега
|
||||||
*
|
*
|
||||||
|
@ -957,6 +991,16 @@ class LsTopic extends Module {
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Получить список просмотром/чтения топиков по списку айдишников
|
* Получить список просмотром/чтения топиков по списку айдишников
|
||||||
*
|
*
|
||||||
|
|
|
@ -490,7 +490,23 @@ 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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue