From b95f479c1799de9caeda70628f61f01fb538e997 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 26 Mar 2015 16:05:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A7=E8=81=94=E5=88=A0=E9=99=A4=E8=B5=84?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/forum.rb | 9 ++++++++- app/models/memo.rb | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/models/forum.rb b/app/models/forum.rb index bdadcd8a9..6843ab678 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -1,5 +1,6 @@ class Forum < ActiveRecord::Base include Redmine::SafeAttributes + include ApplicationHelper 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 :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 :description, maximum: 255 validates :name, :uniqueness => true - + after_destroy :delete_kindeditor_assets acts_as_taggable scope :by_join_date, order("created_at DESC") #after_create :send_email @@ -48,5 +49,11 @@ class Forum < ActiveRecord::Base ["id = ?", forum_id]) 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 diff --git a/app/models/memo.rb b/app/models/memo.rb index b4e30dabe..eb0c86855 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,7 +1,9 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ApplicationHelper belongs_to :forum + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :author, :class_name => "User", :foreign_key => 'author_id' 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_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_save :plusParentAndForum # after_destroy :minusParentAndForum @@ -170,4 +172,10 @@ class Memo < ActiveRecord::Base update_replay_for_memo(User.current,1) 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