register_modules/app/helpers/registered_module_helper.rb

52 lines
1.8 KiB
Ruby

module RegisteredModuleHelper
def install_on_server(site, mod)
params_to_send = {"site_token" => site.site_token, "module_name" => mod.name, "git_path" => mod.git_path, "template" => "http://store.tp.rulingcom.com#{mod.template.url}", "module_key" => mod.module_key,"template_filename" => mod.template.file.filename}
uri = URI.parse("http://#{site.site_domain}/")
http = Net::HTTP.new(uri.host,uri.port)
request = Net::HTTP::Post.new("/store/install_module")
request.body = params_to_send.to_query
response = http.request(request)
data = JSON.parse(response.body)
if data["success"]
im = InstalledModule.new
im.r_module = mod.id
im.permission_granted = true
im.save
site.installed_modules << im
site.save
end
restart_remote_server(site)
end
def restart_remote_server(site)
uri = URI.parse("http://#{site.site_domain}/")
http = Net::HTTP.new(uri.host,uri.port)
request = Net::HTTP::Post.new("/store/restart_server_after_install")
request.body = params_to_send.to_query
response = http.request(request)
end
def uninstall_on_server(site, mod)
im = InstalledModule.where(:registered_site_id => site.id, :r_module => mod.id).first
im.destroy
params_to_send = {"site_token" => site.site_token, "module_name" => mod.name, "git_path" => mod.git_path,"module_key" => mod.module_key}
uri = URI.parse("http://#{site.site_domain}/")
http = Net::HTTP.new(uri.host,uri.port)
request = Net::HTTP::Post.new("/store/uninstall_module")
request.body = params_to_send.to_query
response = http.request(request)
end
def install_modules_on_websites(websites,mod)
websites.each do |website|
install_on_server(RegisteredSite.find(website),mod)
end
end
def uninstall_modules_on_websites(websites,mod)
websites.each do |website|
uninstall_on_server(RegisteredSite.find(website),mod)
end
end
end