2014-12-30 11:52:45 +00:00
|
|
|
module RegisteredModuleHelper
|
|
|
|
def install_on_server(site, mod)
|
2014-12-31 08:13:43 +00:00
|
|
|
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}
|
2014-12-30 11:52:45 +00:00
|
|
|
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
|
2014-12-31 08:41:05 +00:00
|
|
|
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)
|
2014-12-30 11:52:45 +00:00
|
|
|
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
|