aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/import.rb31
-rw-r--r--config/deploy.rb14
-rw-r--r--db/schema.rb18
-rw-r--r--lib/tasks/demo.rake23
4 files changed, 37 insertions, 49 deletions
diff --git a/app/models/import.rb b/app/models/import.rb
index 34736eb90..e0c95f911 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -6,6 +6,7 @@ class Import < ActiveRecord::Base
validates_inclusion_of :status, :in => %w{ pending completed failed }
+ attr_accessor :background
attr_accessor :resources
attr_accessor :loader
@@ -35,7 +36,7 @@ class Import < ActiveRecord::Base
def self.types
# if Rails.env.development? and subclasses.blank?
- # Dir[File.expand_path("../*_import.rb", __FILE__)].each do |f|
+ # Dir[File.expand_path("../*_import.rb", __FILE__)].each do |f|
# require f
# end
# end
@@ -67,15 +68,24 @@ class Import < ActiveRecord::Base
before_validation :extract_file_type, :on => :create
def extract_file_type
- if ! resources.nil?
- self.file_type = resources.original_filename.rpartition(".").last
+ if ! resources.nil?
+ self.file_type = resources.original_filename.rpartition(".").last
end
end
after_create :delayed_import
def delayed_import
save_resources
- delay.import
+ if import_in_background?
+ delay.import
+ else
+ # do not call self.inport
+ import
+ end
+ end
+
+ def import_in_background?
+ return background.nil? || background
end
@@root = "#{Rails.root}/tmp/imports"
@@ -83,7 +93,7 @@ class Import < ActiveRecord::Base
def save_resources
FileUtils.mkdir_p root
- FileUtils.cp resources.path, saved_resources
+ FileUtils.cp resources.path, saved_resources
end
after_destroy :destroy_resources
@@ -106,14 +116,9 @@ class Import < ActiveRecord::Base
def import
begin
log_messages.create :key => :started
- if resources
- with_original_filename do |file|
- # chouette-command checks the file extension (and requires .zip) :(
- loader.import file
- end
- else
- loader.import saved_resources, import_options
- end
+
+ loader.import saved_resources, import_options
+
update_attribute :status, "completed"
rescue => e
Rails.logger.error "Import #{id} failed : #{e}, #{e.backtrace}"
diff --git a/config/deploy.rb b/config/deploy.rb
index 7af18a26c..3ef80bc8a 100644
--- a/config/deploy.rb
+++ b/config/deploy.rb
@@ -3,16 +3,16 @@ require './config/boot'
set :stages, %w(sandbox unstable staging production)
set :application, "chouette2"
-set :user, "ldonnet"
+set :user, "mflorisson"
set :scm, :git
-set :repository, "git@github.com:afimb/chouette2.git"
+set :repository, "https://github.com/afimb/chouette2.git"
set :deploy_to, "/var/www/chouette2"
set :use_sudo, false
default_run_options[:pty] = true
set :group_writable, true
set :rake, "bundle exec rake"
set :keep_releases, 4
-set :rails_env, "production" #added for delayed job
+set :rails_env, "production" #added for delayed job
after "deploy:update", "deploy:cleanup", "deploy:group_writable"
after "deploy:update_code", "deploy:symlink_shared", "deploy:chouette_command", "deploy:gems"
@@ -31,7 +31,7 @@ namespace :deploy do
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
- end
+ end
# Prevent errors when chmod isn't allowed by server
task :setup, :except => { :no_release => true } do
@@ -63,14 +63,14 @@ namespace :deploy do
run "mkdir -p /var/lib/chouette/validations"
run "mkdir -p /usr/local/opt/chouette-command/"
end
-
+
desc "Make group writable all deployed files"
- task :group_writable do
+ task :group_writable do
run "sudo /usr/local/sbin/cap-fix-permissions /var/www/chouette2"
end
# desc "Generate jekyll static sites"
- # task :jekyll, :except => { :no_release => true } do
+ # task :jekyll, :except => { :no_release => true } do
# run "cd #{release_path} && jekyll --auto doc/functional public/help"
# end
diff --git a/db/schema.rb b/db/schema.rb
index a60776988..f6e27009d 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -204,16 +204,6 @@ ActiveRecord::Schema.define(:version => 20130710123351) do
t.integer "organisation_id", :limit => 8
end
- create_table "geometry_columns", :id => false, :force => true do |t|
- t.string "f_table_catalog", :limit => 256, :null => false
- t.string "f_table_schema", :limit => 256, :null => false
- t.string "f_table_name", :limit => 256, :null => false
- t.string "f_geometry_column", :limit => 256, :null => false
- t.integer "coord_dimension", :null => false
- t.integer "srid", :null => false
- t.string "type", :limit => 30, :null => false
- end
-
create_table "group_of_lines", :force => true do |t|
t.string "objectid", :null => false
t.integer "object_version"
@@ -370,14 +360,6 @@ ActiveRecord::Schema.define(:version => 20130710123351) do
t.integer "line_id", :limit => 8
end
- create_table "spatial_ref_sys", :id => false, :force => true do |t|
- t.integer "srid", :null => false
- t.string "auth_name", :limit => 256
- t.integer "auth_srid"
- t.string "srtext", :limit => 2048
- t.string "proj4text", :limit => 2048
- end
-
create_table "stop_areas", :force => true do |t|
t.integer "parent_id", :limit => 8
t.string "objectid", :null => false
diff --git a/lib/tasks/demo.rake b/lib/tasks/demo.rake
index 092bd317d..6d844734b 100644
--- a/lib/tasks/demo.rake
+++ b/lib/tasks/demo.rake
@@ -1,20 +1,21 @@
namespace :demo do
desc "restore demo account"
task :restore => :environment do
- puts "A" * 40
- oo = Organisation.find_by_name("demo").destroy
- if oo
- oo.users.each &:destroy
+ puts "Restore demo environment"
+ old_organisation = Organisation.find_by_name("demo")
+ if old_organisation
+ old_organisation.users.each &:destroy
+ old_organisation.destroy
end
- o = Organisation.create!(:name => "demo")
- u = o.users.build( :name => "Demo", :email => "demo@chouette.mobi", :password => "chouette", :password_confirmation =>"chouette")
- u.save
- u.confirm!
- r = o.referentials.create( :name => "Tatrobus", :slug => "tatrobus", :prefix => "TAT")
+ organisation = Organisation.create!(:name => "demo")
+ user = organisation.users.create( :name => "Demo", :email => "demo@chouette.mobi", :password => "chouette", :password_confirmation =>"chouette")
+ user.confirm!
+ referential = organisation.referentials.create( :name => "Tatrobus", :slug => "tatrobus", :prefix => "TAT")
- res = Rack::Test::UploadedFile.new( Rails.application.config.demo_data, 'application/zip', false)
- i = r.imports.create( :resources => res, :referential_id => r.id)
+ resource = Rack::Test::UploadedFile.new( Rails.application.config.demo_data, 'application/zip', false)
+ import_instance = referential.imports.create( :resources => resource, :referential_id => referential.id, :background => false)
+ puts "Restore demo environment complete"
end
end