RM_16886_Documents_move_error_messages_in_console.diff

Jérôme BATAILLE, 2014-05-14 15:43

Download (1.2 KB)

View differences:

app/models/attachment.rb (revision 2944)
265 265

  
266 266
  # Moves an existing attachment to its target directory
267 267
  def move_to_target_directory!
268
    if !new_record? & readable?
269
      src = diskfile
270
      self.disk_directory = target_directory
271
      dest = diskfile
272
      if src != dest && FileUtils.mkdir_p(File.dirname(dest)) && FileUtils.mv(src, dest)
273
        update_column :disk_directory, disk_directory
274
      end
268
    # Specific : error messages in console
269
    return unless !new_record? & readable?
270

  
271
    src = diskfile
272
    self.disk_directory = target_directory
273
    dest = diskfile
274

  
275
    return if src == dest
276

  
277
    if !FileUtils.mkdir_p(File.dirname(dest))
278
      puts "Could not mkdir #{File.dirname(dest)} !"
279
      return
275 280
    end
281

  
282
    if !FileUtils.mv(src, dest)
283
      puts "Could not mv #{src} -> #{dest} !"
284
      return
285
    end
286

  
287
    puts "#{src} -> #{dest}"
288
    update_column :disk_directory, disk_directory
289
    # END -- Specific : error messages in console
276 290
  end
277 291

  
278 292
  # Moves existing attachments that are stored at the root of the files