级联删除资源

dev_repository_hjq
lizanle 11 years ago
parent a4f1b9c625
commit b95f479c17

@ -1,5 +1,6 @@
class Forum < ActiveRecord::Base class Forum < ActiveRecord::Base
include Redmine::SafeAttributes include Redmine::SafeAttributes
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy has_many_kindeditor_assets :assets, :dependent => :destroy
has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy
has_many :memos, :dependent => :destroy, conditions: "parent_id IS NULL" has_many :memos, :dependent => :destroy, conditions: "parent_id IS NULL"
@ -16,7 +17,7 @@ class Forum < ActiveRecord::Base
validates_length_of :name, maximum: 50 validates_length_of :name, maximum: 50
#validates_length_of :description, maximum: 255 #validates_length_of :description, maximum: 255
validates :name, :uniqueness => true validates :name, :uniqueness => true
after_destroy :delete_kindeditor_assets
acts_as_taggable acts_as_taggable
scope :by_join_date, order("created_at DESC") scope :by_join_date, order("created_at DESC")
#after_create :send_email #after_create :send_email
@ -48,5 +49,11 @@ class Forum < ActiveRecord::Base
["id = ?", forum_id]) ["id = ?", forum_id])
end end
# Time 2015-03-26 15:50:54
# Author lizanle
# Description 删除论坛后删除对应的资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,2
end
end end

@ -1,7 +1,9 @@
class Memo < ActiveRecord::Base class Memo < ActiveRecord::Base
include Redmine::SafeAttributes include Redmine::SafeAttributes
include UserScoreHelper include UserScoreHelper
include ApplicationHelper
belongs_to :forum belongs_to :forum
has_many_kindeditor_assets :assets, :dependent => :destroy
belongs_to :author, :class_name => "User", :foreign_key => 'author_id' belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
validates_presence_of :author_id, :forum_id, :subject,:content validates_presence_of :author_id, :forum_id, :subject,:content
# 若是主题帖,则内容可以是空 # 若是主题帖,则内容可以是空
@ -44,7 +46,7 @@ class Memo < ActiveRecord::Base
after_create :add_author_as_watcher, :reset_counters!, :sendmail after_create :add_author_as_watcher, :reset_counters!, :sendmail
# after_update :update_memos_forum # after_update :update_memos_forum
after_destroy :reset_counters!#,:down_user_score -- 公共区发帖暂不计入得分 after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分
# after_create :send_notification # after_create :send_notification
# after_save :plusParentAndForum # after_save :plusParentAndForum
# after_destroy :minusParentAndForum # after_destroy :minusParentAndForum
@ -170,4 +172,10 @@ class Memo < ActiveRecord::Base
update_replay_for_memo(User.current,1) update_replay_for_memo(User.current,1)
end end
# Time 2015-03-26 15:20:24
# Author lizanle
# Description 从硬盘上删除资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,1
end
end end

Loading…
Cancel
Save