do_not_delete_version_referenced_by_cf.diff

Noya B, 2015-06-23 14:53

Download (1.22 KB)

View differences:

app/controllers/versions_controller.rb
146 146
  end
147 147

  
148 148
  def destroy
149
    if @version.fixed_issues.empty?
149
    if @version.fixed_issues.empty? and !@version.referenced_by_a_custom_field?
150 150
      @version.destroy
151 151
      respond_to do |format|
152 152
        format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') }
app/models/version.rb
168 168
    @closed_issues_count
169 169
  end
170 170

  
171
  def referenced_by_a_custom_field?
172
    !CustomValue.where("custom_field_id IN (SELECT id
173
                                            FROM #{CustomField.table_name}
174
                                            WHERE field_format='version')
175
                        AND value = ?", id).empty?
176
  end
177

  
171 178
  def wiki_page
172 179
    if project.wiki && !wiki_page_title.blank?
173 180
      @wiki_page ||= project.wiki.find_page(wiki_page_title)