2013-12-24 07:58:13 +00:00
|
|
|
class Admin::ModuleStoreController < OrbitBackendController
|
2014-01-06 06:47:44 +00:00
|
|
|
|
2014-01-14 03:20:30 +00:00
|
|
|
@@store = STORE_CONFIG[:store_settings]["url"]
|
|
|
|
|
2012-11-28 18:02:37 +00:00
|
|
|
def index
|
2014-01-14 03:20:30 +00:00
|
|
|
@extensions = get_extensions
|
2012-11-28 18:02:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2014-01-14 03:20:30 +00:00
|
|
|
@extension = get_extension(params[:id]) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def download
|
|
|
|
#get extension related values
|
|
|
|
extension = get_extension(params[:id]) rescue nil
|
|
|
|
download_link = @@store + "/"+ extension["extension"]["extension"]["url"]
|
|
|
|
downloaded_file_name = extension["extension_filename"]
|
|
|
|
module_app_name = downloaded_file_name.split(/(.zip)/).first
|
|
|
|
|
|
|
|
#check if the directory exists or not
|
|
|
|
if Dir.exists?("#{Rails.root}/vendor/built_in_modules/#{module_app_name}")
|
|
|
|
flash[:notice] = "This module is already installed"
|
|
|
|
else
|
|
|
|
download_extension(download_link, downloaded_file_name,module_app_name)
|
|
|
|
flash[:notice] = "This module has been successfully installed"
|
|
|
|
end
|
|
|
|
redirect_to admin_module_store_path
|
2012-11-28 18:02:37 +00:00
|
|
|
end
|
|
|
|
|
2014-01-14 03:20:30 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def get_extensions
|
|
|
|
JSON.parse(open("#{@@store}/api/extensions").read)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_extension(id)
|
|
|
|
JSON.parse(open("#{@@store}/api/extensions/#{id}").read)
|
|
|
|
end
|
|
|
|
|
|
|
|
def download_extension(download_link, downloaded_file_name,module_app_name)
|
|
|
|
puts %x(wget "#{download_link}")
|
|
|
|
puts %x(unzip "#{downloaded_file_name}")
|
|
|
|
puts %x(mv #{module_app_name} "#{Rails.root}/vendor/built_in_modules/")
|
|
|
|
puts %x(rm "#{downloaded_file_name}")
|
|
|
|
|
|
|
|
Rails.logger.info"@@@@@@@@"+Dir.exists?("#{Rails.root}/vendor/built_in_modules/location").inspect
|
|
|
|
site_restart
|
|
|
|
end
|
2012-11-28 18:02:37 +00:00
|
|
|
end
|