Skip to content

Commit

Permalink
Merge commit 'core/quota' into development
Browse files Browse the repository at this point in the history
Conflicts:
	lib/tasks/restore.rake
  • Loading branch information
cykod committed Jul 15, 2010
2 parents 76d120a + 83782e8 commit 1c79ef8
Show file tree
Hide file tree
Showing 37 changed files with 871 additions and 231 deletions.
26 changes: 23 additions & 3 deletions app/controllers/application_controller.rb
Expand Up @@ -460,7 +460,10 @@ def handle_file_upload(parameters,key,options = {})

if !parameters[key].to_s.empty? && DomainFile.available_file_storage > 0
image_folder = options[:folder] || Configuration.options.default_image_location
file = DomainFile.create(:skip_transform => true,:filename => parameters[key],:parent_id => image_folder,:creator_id => myself.id )
file = DomainFile.create(:filename => parameters[key],
:parent_id => image_folder,
:creator_id => myself.id,
:process_immediately => true)
if file.id
parameters[key] = file.id
else
Expand All @@ -483,7 +486,8 @@ def handle_image_upload(parameters,key,options = {})
image_folder = options[:folder] || Configuration.options.default_image_location
file = DomainFile.create(:filename => parameters[key],
:parent_id => image_folder,
:creator_id => myself.id)
:creator_id => myself.id,
:process_immediately => true)
if file.file_type == 'img'
parameters[key] = file.id
else
Expand All @@ -495,7 +499,23 @@ def handle_image_upload(parameters,key,options = {})
end
parameters.delete(key.to_s + "_clear")
end


def send_domain_file(df, opts={})
df = DomainFile.find_by_id(df) if df.is_a?(Integer)
return false unless df

df.filename # copy locally
return false unless File.exists?(df.filename)

opts[:stream] = true unless opts.key?(:stream)
opts[:type] ||= df.mime_type
opts[:disposition] ||= 'attachment'
opts[:filename] ||= df.name

send_file(df.filename, opts)
true
end

private

def sanitize_backtrace(trace) # :nodoc:
Expand Down
9 changes: 1 addition & 8 deletions app/controllers/content_export_controller.rb
Expand Up @@ -55,14 +55,7 @@ def download_file
@content_model = ContentModel.find(content_id)
if(session[:content_download_worker_key])
results = Workling.return.get(session[:content_download_worker_key])

send_file(results[:filename],
:stream => true,
:type => "text/" + results[:type],
:disposition => 'attachment',
:filename => sprintf("%s_%d.%s",@content_model.name.humanize,Time.now.strftime("%Y_%m_%d"),results[:type])
)

send_domain_file results[:domain_file_id], :type => "text/" + results[:type]
session[:content_download_worker_key] = nil
else
render :nothing => true
Expand Down
27 changes: 15 additions & 12 deletions app/controllers/content_import_controller.rb
Expand Up @@ -72,8 +72,10 @@ def fields
redirect_to :action => 'index'; return
return
end

filename = session[:content_import_wizard][:index][:filename]

file = DomainFile.find_by_id(session[:content_import_wizard][:index][:csv_file])
filename = file.filename

@deliminator = @@deliminators[session[:content_import_wizard][:index][:field_deliminator]]

@available_fields = csv_fields(filename,@deliminator)
Expand Down Expand Up @@ -138,8 +140,9 @@ def confirm

@content_model = ContentModel.find(content_id)


filename = session[:content_import_wizard][:index][:filename]
file = DomainFile.find_by_id(session[:content_import_wizard][:index][:csv_file])
filename = file.filename

@deliminator = @@deliminators[session[:content_import_wizard][:index][:field_deliminator]]

@content_fields = [ContentModelField.new(:field => 'id', :name => 'Identifier'.t)] + @content_model.content_model_fields
Expand All @@ -153,12 +156,14 @@ def confirm
if request.post?
# Posting? Do it Do it

worker_args = { :domain_id => DomainModel.active_domain_id,
:content_model_id => content_id,
:filename => filename,
:deliminator => @deliminator,
:data => session[:content_import_wizard][:fields]
}
worker_args = {
:domain_id => DomainModel.active_domain_id,
:csv_file => session[:content_import_wizard][:index][:csv_file],
:content_model_id => content_id,
:deliminator => @deliminator,
:data => session[:content_import_wizard][:fields]
}

session[:content_import_worker_key] = ContentImportWorker.async_do_work(worker_args)
# Start a worker that will create any necessary fields
# and actually import the data
Expand Down Expand Up @@ -203,8 +208,6 @@ def status
if session[:content_import_worker_key]
begin
results = Workling.return.get(session[:content_import_worker_key]) || { }
logger.error(session[:content_import_worker_key])
logger.error(results.inspect)
@initialized = results[:initialized] || false
@completed = results[:completed] || false
@entries = results[:entries] || 0
Expand Down
42 changes: 32 additions & 10 deletions app/controllers/file_controller.rb
Expand Up @@ -175,7 +175,7 @@ def file_manager_update
def upload

if DomainFile.available_file_storage > 0
@upload_file = DomainFile.create(:filename => params[:upload_file][:filename], :parent_id => params[:upload_file][:parent_id], :creator_id => myself.id, :skip_transform => true)
@upload_file = DomainFile.create(:filename => params[:upload_file][:filename], :parent_id => params[:upload_file][:parent_id], :creator_id => myself.id, :skip_transform => true, :skip_post_processing => true)

worker_key = FileWorker.async_do_work(:domain_file_id => @upload_file.id,
:domain_id => DomainModel.active_domain_id,
Expand Down Expand Up @@ -233,14 +233,29 @@ def move_files

render :nothing => true
end


def processing_file
@processing_key = params[:processing_key]
return render :nothing => true unless @processing_key

processor = @processing_key ? Workling.return.get(@processing_key) : nil
@processed = processor && processor[:processed]
if @processed
@file = DomainFile.find_by_id processor[:domain_file_id]
session[:replace_file_worker] = nil
session[:extract_file_worker] = nil
end
end

def replace_file
@file = DomainFile.find_by_id(params[:file_id].to_i)

@replace = DomainFile.find_by_id(params[:replace_id].to_i)

if @file && @replace
@replaced = @file.replace(@replace)

if @file && @replace && @file.id != @replace.id && ! @file.folder? && ! @replace.folder?
worker_key = @file.run_worker(:replace_file, :replace_id => @replace.id)
@processing_key = session[:replace_file_worker] = worker_key
else
render :nothing => true
end
end

Expand All @@ -256,7 +271,12 @@ def delete_revision

def extract_revision
@revision = DomainFileVersion.find_by_id(params[:revision_id].to_i)
@file = @revision.extract
if @revision
worker_key = @revision.run_worker(:extract_file)
@processing_key = session[:extract_file_worker] = worker_key
else
render :nothing => true
end
end

def copy_file
Expand Down Expand Up @@ -288,16 +308,18 @@ def create_folder
end

def delete_file
file_id = params[:file_id].to_i

file_id = params[:file_id]
render :nothing => true unless file_id

file = DomainFile.find(file_id)
file.destroy
render :nothing => true
end

def delete_files
file_id = params[:file_id]

render :nothing => true unless file_id

files = DomainFile.find(file_id)
dirs = []
files.each do |fl|
Expand Down
10 changes: 1 addition & 9 deletions app/controllers/member_export_controller.rb
Expand Up @@ -49,15 +49,7 @@ def status
def download_file
if(session[:member_download_worker_key])
results = Workling.return.get(session[:member_download_worker_key])
domain_file = DomainFile.find results[:domain_file_id]
send_file(domain_file.filename,
:stream => true,
:type => "text/" + results[:type],
:disposition => 'attachment',
:filename => sprintf("%s_%d.%s",'Email_Targets'.t,Time.now.strftime("%Y_%m_%d"),results[:type])
)


send_domain_file results[:domain_file_id], :type => "text/" + results[:type]
session[:member_download_worker_key] = nil
else
render :nothing => true
Expand Down
20 changes: 11 additions & 9 deletions app/controllers/member_import_controller.rb
Expand Up @@ -74,8 +74,8 @@ def fields

@deliminator = @@deliminators[session[:member_import_wizard][:index][:field_deliminator]]


filename = session[:member_import_wizard][:index][:filename]
file = DomainFile.find_by_id(session[:member_import_wizard][:index][:csv_file])
filename = file.filename

begin
@available_fields = csv_fields(filename,@deliminator)
Expand Down Expand Up @@ -161,7 +161,8 @@ def confirm
[ 'Email Targets', url_for(:controller =>'members' ) ],
'Member Import - Confirm' ], 'e_marketing' )

filename = session[:member_import_wizard][:index][:filename]
file = DomainFile.find_by_id(session[:member_import_wizard][:index][:csv_file])
filename = file.filename

@deliminator = @@deliminators[session[:member_import_wizard][:index][:field_deliminator]]

Expand All @@ -170,12 +171,13 @@ def confirm
if request.post?
# Posting? Do it Do it

worker_args = { :domain_id => DomainModel.active_domain_id,
:filename => filename,
:data => session[:member_import_wizard][:fields],
:options => session[:member_import_wizard][:options],
:deliminator => @deliminator
}
worker_args = {
:domain_id => DomainModel.active_domain_id,
:csv_file => session[:member_import_wizard][:index][:csv_file],
:data => session[:member_import_wizard][:fields],
:options => session[:member_import_wizard][:options],
:deliminator => @deliminator
}
worker_key = MemberImportWorker.async_do_work(worker_args)
session[:member_import_worker_key] = worker_key
# Start a worker that will create any necessary fields
Expand Down
2 changes: 1 addition & 1 deletion app/models/domain.rb
Expand Up @@ -192,6 +192,6 @@ def execute(environment='production')
active_domain = DomainModel.active_domain
DomainModel.activate_domain(self.get_info, environment) unless active_domain_id == self.id
yield
DomainModel.activate_domain(active_domain, environment) unless active_domain_id == self.id || active_domain_id.nil?
DomainModel.activate_domain(active_domain, environment) unless active_domain_id == self.id || active_domain_id.blank?
end
end

0 comments on commit 1c79ef8

Please sign in to comment.