diff --git a/app/controllers/admin/site_panel_controller.rb b/app/controllers/admin/site_panel_controller.rb index 1e6339a..9d01cb7 100644 --- a/app/controllers/admin/site_panel_controller.rb +++ b/app/controllers/admin/site_panel_controller.rb @@ -110,8 +110,14 @@ class Admin::SitePanelController < OrbitAdminController db_name = site_construct.db_name path = site_construct.path site_construct_id = params[:id] - Thread.new do - system("bundle exec rake create_site:create_site['#{git_template_url}','#{git_extension_url}','#{git_url}','#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}']") + if site_construct.copy_id + Thread.new do + system("bundle exec rake create_site:copy_site['#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}','#{site_construct.copy_id}']") + end + else + Thread.new do + system("bundle exec rake create_site:create_site['#{git_template_url}','#{git_extension_url}','#{git_url}','#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}']") + end end render :json =>{"success"=>true} end @@ -173,8 +179,6 @@ class Admin::SitePanelController < OrbitAdminController def site_construct_params site_construct_params = params.require(:site_construct).permit! - site_construct_params = site_construct_params.except(:copy_id) - return site_construct_params end def site_server_params params.require(:site_server).permit! diff --git a/app/models/site_construct.rb b/app/models/site_construct.rb index 771aaf1..e396725 100644 --- a/app/models/site_construct.rb +++ b/app/models/site_construct.rb @@ -20,6 +20,7 @@ class SiteConstruct field :status, type: String, :default => "" field :infos, type: Array, :default => [] field :hidden, type: Boolean, :default => false + field :copy_id after_initialize do |record| if record.status.nil? record.status = "" diff --git a/lib/tasks/copy_site.rake b/lib/tasks/copy_site.rake index 6a200ce..056e26d 100644 --- a/lib/tasks/copy_site.rake +++ b/lib/tasks/copy_site.rake @@ -94,6 +94,32 @@ namespace :create_site do end update_infos("Finish copying database!") + update_infos("Checking extensions!") + extensions = ["downloaded_extensions.rb","built_in_extensions.rb"] + extensions.each do |extension_file| + outputs = exec_ssh_command_by_sudo_for_create(ssh,"cat #{args.path}/#{@site_construct.get_site_name}/#{extension_file}") + if !outputs.include?("No such file or directory") + read_lines = outputs.split("\n").map{|l| l.split('#').first} + include_path_lines = read_lines.select{|l| l.include?("path")} + include_path_lines.each do |line| + path = line.split(/[:>]/).last.gsub(/[\'\"]/,"").strip + absolute_path = (path[0] == "/") ? path : ("#{template_site.path}/#{template_site.get_site_name}/#{path}") + absolute_path = (absolute_path[-1] == "/") ? absolute_path : (absolute_path + "/") + if @site_construct.server_type == template_site.server_type + exec_ssh_command_for_create(ssh,"rsync -arv --delete #{absolute_path} #{args.path}/#{args.site_name}/#{Pathname.new(absolute_path).basename}/") + else + server = SiteServer.where(:server_name => template_site.server_type).first + exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete #{server.account}@#{server.ip}:#{absolute_path} #{args.path}/#{args.site_name}/#{Pathname.new(absolute_path).basename}/") + end + outputs = outputs.gsub(path,"#{args.path}/#{args.site_name}/#{Pathname.new(absolute_path).basename}/") + end + if include_path_lines.count != 0 + exec_ssh_command_by_sudo_for_create(ssh,"sh -c \"echo '#{outputs.gsub("'","\\\"")}' > #{args.path}/#{@site_construct.get_site_name}/#{extension_file}\"") + end + end + end + update_infos("Finish checking extensions!") + update_infos("execing bundle install...") exec_ssh_command_by_sudo_for_create(ssh,"bash -l -c 'cd #{args.path}/#{@site_construct.get_site_name}\nbundle install'",true) exec_ssh_command_by_sudo_for_create(ssh,"bash -l -c 'cd #{args.path}/#{@site_construct.get_site_name}\nbundle install'")