diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 8d38338..01ef61b 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -47,7 +47,7 @@ class GroupsController < ApplicationController end def addUser - @user = User.first conditions: {username: params[:username]} + @user = User.where(username: params[:username]) raise AccessError unless @group.can_update? cuser raise Error, t(:duplicate_user) if @group.users.include? @user diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 9b3aa5a..cf5a586 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -2,8 +2,8 @@ class ServersController < ApplicationController before_action :get_server, except: [:index, :refresh, :new, :create] def index - @servers = Server.hlds.active.ordered.all :include => :user - @ns2 = Server.ns2.active.ordered.all :include => :user + @servers = Server.hlds.active.ordered.includes(:user).all + @ns2 = Server.ns2.active.ordered.includes(:user).all @officials = Server.ns2.active.ordered.where ["name LIKE ?", "%NSL%"] end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 63efec8..4caa00d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -178,6 +178,7 @@ module ApplicationHelper f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)") end + # FIXME: this won't work. def link_to_add_fields(name, f, association) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, new_object, child_index: "new_#{association}") do |builder| diff --git a/app/models/article.rb b/app/models/article.rb index 0eadf49..d534699 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -121,11 +121,11 @@ class Article < ActiveRecord::Base if (new_record? or status_changed?) and status == STATUS_PUBLISHED case category.domain when Category::DOMAIN_NEWS - Profile.includes(:user).all(conditions: "notify_news = 1").each do |p| + Profile.includes(:user).where("notify_news = 1").each do |p| Notifications.news p.user, self if p.user end when Category::DOMAIN_ARTICLES - Profile.includes(:user).all(conditions: "notify_articles = 1").each do |p| + Profile.includes(:user).where("notify_articles = 1").each do |p| Notifications.article p.user, self if p.user end end diff --git a/app/models/data_file.rb b/app/models/data_file.rb index 7eac3b1..a57c54c 100644 --- a/app/models/data_file.rb +++ b/app/models/data_file.rb @@ -123,7 +123,7 @@ class DataFile < ActiveRecord::Base if location.include? "_preview.mp4" and !related stripped = location.gsub(/_preview\.mp4/, "") - DataFile.all(:conditions => ["path LIKE ?", stripped + "%"]).each do |r| + DataFile.where(["path LIKE ?", stripped + "%"]).each do |r| if r.location.match(/#{stripped}\.\w{1,5}$/) self.related = r end diff --git a/app/models/directory.rb b/app/models/directory.rb index 3219a6a..f8b7e60 100644 --- a/app/models/directory.rb +++ b/app/models/directory.rb @@ -149,6 +149,7 @@ class Directory < ActiveRecord::Base strio = StringIO.new logger = Logger.new(strio) logger.info 'Starting recreate on Directory(%d): %s.' % [id, name] + logger.info 'DataFiles: %d Directories: %d' % [DataFile.all.count, Directory.all.count] ActiveRecord::Base.transaction do # We use destroy lists so technically there can be seperate roots destroy_dirs = Hash.new @@ -159,9 +160,11 @@ class Directory < ActiveRecord::Base destroy_dirs = recreate(destroy_dirs, logger: logger) destroy_dirs.each do |key, dir| logger.info 'Removed dir: %s' % dir.full_path + dir.preserve_files = true dir.destroy! end end + logger.info 'DataFiles: %d Directories: %d' % [DataFile.all.count, Directory.all.count] logger.info 'Finish recreate' return strio # TODO: check items that weren't checked. diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index 5b9005c..33cd0ca 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -4,7 +4,11 @@ class FileUploader < CarrierWave::Uploader::Base # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: def store_dir - model.directory.full_path + if model and model.directory + model.directory.full_path + else + Directory.find(Directory::ROOT).full_path + end # .gsub(/public\//, '') end