删除文章,有问题。因为表的关联,要处理很多步骤。其中上下篇的处理没有完成!
不过,我觉得删除文章牵涉到很多张表,而且有可能在日后的功能增加中还会涉及更多。
我觉得删除文章,这步骤应该放在存储过程来完成(效率提高非常多,否则在hibenrate要操作很多),以下是我写的存储过程,已经成功实现了:
begin
set @next_id = null;
set @pre_id = null;
select @next_id:=next_id, @pre_id:=pre_id from arti_article where article_id=id;
/** 处理 上一篇、下一篇 ***/
update arti_article set next_id=@next_id where next_id=id;
update arti_article set pre_id=@pre_id where pre_id=id;
/** 为了避免next_id或pre_id指向自己id,多以下步骤 **/
update arti_article set pre_id=null, next_id=null where pre_id=id or next_id=id;
/** 删除专题 ***/
delete from cms_article_topic where article_id=id;
/** 删除评论 ***/
delete from cms_comment where ref_doc_id=id;
/** 删除附件 ***/
delete arti_article_attachment ,core_attachment from arti_article_attachment ,core_attachment where arti_article_attachment.article_id=id and arti_article_attachment.attachment_id=core_attachment.attachment_id;
/** 删除本身 ***/
delete from arti_article where article_id=id;
end
其中需要传递一个参数,就是文章ID。另外执行存储过程后,再实际删除文章txt以及附近文件等,这在原有基础上稍微修改下就行了。
想问下JEECMS作者,觉得如何呢?交流下,谢谢 |
|