| 31 | | |
|---|
| 32 | | ################################################################### |
|---|
| 33 | | # Old |
|---|
| 34 | | ################################################################### |
|---|
| 35 | | def clear_components_dir |
|---|
| 36 | | clear_dirs = ['components', 'install'] |
|---|
| 37 | | public_dirs = ['images', 'javascripts', 'stylesheets'] |
|---|
| 38 | | target_components = Dir["#{RAILS_ROOT}/test/rzips/*.rzip"] |
|---|
| 39 | | clear_dirs.each do |target_dir| |
|---|
| 40 | | target_components.each do |target_component_path| |
|---|
| 41 | | target_component = target_component_path.sub(%r(^.*/([^/]*)\.rzip$), '\1') |
|---|
| 42 | | clear_dirs.each do |dir| |
|---|
| 43 | | dir_name = "#{RAILS_ROOT}/#{dir}/#{target_component}" |
|---|
| 44 | | rzip_name = "#{dir_name}.rzip" |
|---|
| 45 | | RubricksLib.rm(dir_name) |
|---|
| 46 | | RubricksLib.rm(rzip_name) |
|---|
| 47 | | end |
|---|
| 48 | | public_dirs.each do |dir| |
|---|
| 49 | | dir_name = "#{RAILS_ROOT}/public/#{dir}/components/#{target_component}" |
|---|
| 50 | | RubricksLib.rm(dir_name) |
|---|
| 51 | | end |
|---|
| 52 | | end |
|---|
| 53 | | end |
|---|
| 54 | | scripts = ['before_install', 'after_install', 'before_uninstall', 'after_uninstall', 'before_update', 'after_update'] |
|---|
| 55 | | scripts.each do |script| |
|---|
| 56 | | RubricksLib.rm("#{RAILS_ROOT}/test/#{script}.txt") |
|---|
| 57 | | end |
|---|
| 58 | | render :text => 'clear components directory.' |
|---|
| 59 | | end |
|---|
| 60 | | |
|---|
| 61 | | def clear_skin_dirs(skin_name) |
|---|
| 62 | | targets = ['javascripts', 'images', 'stylesheets'] |
|---|
| 63 | | targets.each do |target| |
|---|
| 64 | | RubricksLib.rm("#{RAILS_ROOT}/public/#{target}/dashboard/widgets/#{skin_name}") |
|---|
| 65 | | end |
|---|
| 66 | | RubricksLib.rm("#{RAILS_ROOT}/dashboard/widgets/#{skin_name}") |
|---|
| 67 | | end |
|---|
| 68 | | |
|---|
| 69 | | def clear_skin_files |
|---|
| 70 | | skin_name = params[:skin_name] || 'test' |
|---|
| 71 | | clear_skin_dirs(skin_name) |
|---|
| 72 | | render :text => "clear_skin_files. (#{skin_name})" |
|---|
| 73 | | end |
|---|
| 74 | | |
|---|
| 75 | | def clear_skin_testdirs |
|---|
| 76 | | skin_testdirs = [ |
|---|
| 77 | | 'skin32characters0000000000000000', |
|---|
| 78 | | 'skinblue', |
|---|
| 79 | | 'skingreen', |
|---|
| 80 | | 'skin33characters00000000000000000', |
|---|
| 81 | | 'skin6', |
|---|
| 82 | | 'skin7', |
|---|
| 83 | | 'skin8', |
|---|
| 84 | | 'skin(_marks)', |
|---|
| 85 | | ] |
|---|
| 86 | | skin_testdirs.each do |dir| |
|---|
| 87 | | clear_skin_dirs(dir) |
|---|
| 88 | | end |
|---|
| 89 | | render :text => "clear_skin_testdirs." |
|---|
| 90 | | end |
|---|
| 91 | | |
|---|
| 92 | | def clear_theme_dirs(theme_name) |
|---|
| 93 | | targets = ['images', 'javascripts', 'stylesheets'] |
|---|
| 94 | | targets.each do |target| |
|---|
| 95 | | RubricksLib.rm("#{RAILS_ROOT}/public/#{target}/themes/#{theme_name}") |
|---|
| 96 | | end |
|---|
| 97 | | RubricksLib.rm("#{RAILS_ROOT}/themes/#{theme_name}") |
|---|
| 98 | | end |
|---|
| 99 | | |
|---|
| 100 | | def clear_theme_files |
|---|
| 101 | | theme_name = params[:theme_name] || 'test' |
|---|
| 102 | | clear_theme_dirs(theme_name) |
|---|
| 103 | | render :text => "clear_theme_files. (#{theme_name})" |
|---|
| 104 | | end |
|---|
| 105 | | |
|---|
| 106 | | def clear_theme_testdirs |
|---|
| 107 | | theme_testdirs = [ |
|---|
| 108 | | 'theme32characters000000000000000', |
|---|
| 109 | | 'themeblue', |
|---|
| 110 | | 'themegreen', |
|---|
| 111 | | 'theme33characters0000000000000000', |
|---|
| 112 | | 'theme3', |
|---|
| 113 | | 'theme4', |
|---|
| 114 | | 'theme5', |
|---|
| 115 | | 'theme(_marks)', |
|---|
| 116 | | ] |
|---|
| 117 | | theme_testdirs.each do |dir| |
|---|
| 118 | | clear_theme_dirs(dir) |
|---|
| 119 | | end |
|---|
| 120 | | render :text => "clear_theme_testdirs." |
|---|
| 121 | | end |
|---|
| 122 | | |
|---|
| 123 | | def confirm_delivery_mail |
|---|
| 124 | | if ActionMailer::Base.deliveries.blank? |
|---|
| 125 | | render :text => 'No Mail' |
|---|
| 126 | | else |
|---|
| 127 | | text = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />' |
|---|
| 128 | | ActionMailer::Base.deliveries.each do |mail| |
|---|
| 129 | | text << "To: #{mail[:recipient]}<br>" |
|---|
| 130 | | text << "Cc: #{mail[:cc]}<br>" |
|---|
| 131 | | text << "Bcc: #{mail[:bcc]}<br>" |
|---|
| 132 | | text << "From: #{mail[:from]}<br>" |
|---|
| 133 | | text << "Subject: #{mail[:subject]}<br>" |
|---|
| 134 | | text << "Template: #{mail[:template]}<br>" |
|---|
| 135 | | end |
|---|
| 136 | | ActionMailer::Base.deliveries.clear |
|---|
| 137 | | render :text => text |
|---|
| 138 | | end |
|---|
| 139 | | end |
|---|
| 140 | | |
|---|
| 141 | | def confirm_permission |
|---|
| 142 | | ru = current_user |
|---|
| 143 | | render :text => (guest?) ? 'Guest' : current_user.login_name |
|---|
| 144 | | end |
|---|
| 145 | | |
|---|
| 146 | | def confirm_skin_files_exist |
|---|
| 147 | | skin_name = params[:skin_name] |
|---|
| 148 | | skin_flag = true |
|---|
| 149 | | targets = ['images', 'stylesheets'] |
|---|
| 150 | | targets.each do |target| |
|---|
| 151 | | if target == 'stylesheets' |
|---|
| 152 | | from_path = "#{RAILS_ROOT}/dashboard/widgets/#{skin_name}/#{target}/sample.css" |
|---|
| 153 | | copy_path = "#{RAILS_ROOT}/public/#{target}/dashboard/widgets/#{skin_name}/sample.css" |
|---|
| 154 | | else |
|---|
| 155 | | from_path = "#{RAILS_ROOT}/dashboard/widgets/#{skin_name}/#{target}/from.txt" |
|---|
| 156 | | copy_path = "#{RAILS_ROOT}/public/#{target}/dashboard/widgets/#{skin_name}/from.txt" |
|---|
| 157 | | end |
|---|
| 158 | | skin_flag = false unless File.exists?(from_path) |
|---|
| 159 | | skin_flag = false unless File.exists?(copy_path) |
|---|
| 160 | | end |
|---|
| 161 | | render :text => (skin_flag) ? 'ok' : 'ng' |
|---|
| 162 | | end |
|---|
| 163 | | |
|---|
| 164 | | def confirm_theme_files_exist |
|---|
| 165 | | theme_name = params[:theme_name] |
|---|
| 166 | | theme_flag = true |
|---|
| 167 | | targets = ['images', 'javascripts', 'stylesheets'] |
|---|
| 168 | | targets.each do |target| |
|---|
| 169 | | if target == 'stylesheets' |
|---|
| 170 | | from_path = "#{RAILS_ROOT}/themes/#{theme_name}/#{target}/common.css" |
|---|
| 171 | | copy_path = "#{RAILS_ROOT}/public/#{target}/themes/#{theme_name}/style.css" |
|---|
| 172 | | else |
|---|
| 173 | | from_path = "#{RAILS_ROOT}/themes/#{theme_name}/#{target}/from.txt" |
|---|
| 174 | | copy_path = "#{RAILS_ROOT}/public/#{target}/themes/#{theme_name}/from.txt" |
|---|
| 175 | | end |
|---|
| 176 | | theme_flag = false unless File.exists?(from_path) |
|---|
| 177 | | theme_flag = false unless File.exists?(copy_path) |
|---|
| 178 | | end |
|---|
| 179 | | render :text => (theme_flag) ? 'ok' : 'ng' |
|---|
| 180 | | end |
|---|
| 181 | | |
|---|
| 182 | | def drop_table |
|---|
| 183 | | table_name = params[:table] |
|---|
| 184 | | begin |
|---|
| 185 | | ActiveRecord::Migration.execute("drop table if exists #{table_name};") |
|---|
| 186 | | rescue Exception |
|---|
| 187 | | render :text => 'failed to drop table.' |
|---|
| 188 | | else |
|---|
| 189 | | render :text => "drop table '#{table_name}'." |
|---|
| 190 | | end |
|---|
| 191 | | end |
|---|
| 192 | | |
|---|
| 193 | | def init_skin_files |
|---|
| 194 | | skin_name = params[:skin_name] || 'test' |
|---|
| 195 | | clear_skin_dirs(skin_name) |
|---|
| 196 | | targets = ['images', 'stylesheets'] |
|---|
| 197 | | targets.each do |target| |
|---|
| 198 | | from_path = "#{RAILS_ROOT}/dashboard/widgets/#{skin_name}/#{target}" |
|---|
| 199 | | to_path = "#{RAILS_ROOT}/public/#{target}/dashboard/widgets/#{skin_name}" |
|---|
| 200 | | RubricksLib.mkdir(from_path) |
|---|
| 201 | | RubricksLib.mkdir(to_path) |
|---|
| 202 | | if target == 'stylesheets' |
|---|
| 203 | | File.open("#{from_path}/sample.css", 'w') do |file| |
|---|
| 204 | | file.puts 'body{color:#cccccc;}' |
|---|
| 205 | | end |
|---|
| 206 | | else |
|---|
| 207 | | File.open("#{from_path}/from.txt", 'w') do |file| |
|---|
| 208 | | file.puts 'test' |
|---|
| 209 | | end |
|---|
| 210 | | File.open("#{to_path}/to.txt", 'w') do |file| |
|---|
| 211 | | file.puts 'test' |
|---|
| 212 | | end |
|---|
| 213 | | end |
|---|
| 214 | | end |
|---|
| 215 | | render :text => "initialize_skin_dir. (#{skin_name})" |
|---|
| 216 | | end |
|---|
| 217 | | |
|---|
| 218 | | def init_skin_images |
|---|
| 219 | | skin_name = params[:skin_name] || 'test' |
|---|
| 220 | | image_name = params[:image_name] || 'screenshot.jpg' |
|---|
| 221 | | from_path = "#{RAILS_ROOT}/dashboard/widgets/#{skin_name}/images" |
|---|
| 222 | | to_path = "#{RAILS_ROOT}/public/images/dashboard/widgets/#{skin_name}" |
|---|
| 223 | | File.open("#{from_path}/#{image_name}", 'w') do |file| |
|---|
| 224 | | end |
|---|
| 225 | | File.open("#{to_path}/#{image_name}", 'w') do |file| |
|---|
| 226 | | end |
|---|
| 227 | | render :text => "initialize_image. (#{image_name})" |
|---|
| 228 | | end |
|---|
| 229 | | |
|---|
| 230 | | def init_theme_files |
|---|
| 231 | | theme_name = params[:theme_name] || 'test' |
|---|
| 232 | | clear_theme_dirs(theme_name) |
|---|
| 233 | | targets = ['images', 'javascripts', 'stylesheets'] |
|---|
| 234 | | targets.each do |target| |
|---|
| 235 | | from_path = "#{RAILS_ROOT}/themes/#{theme_name}/#{target}" |
|---|
| 236 | | to_path = "#{RAILS_ROOT}/public/#{target}/themes/#{theme_name}" |
|---|
| 237 | | RubricksLib.mkdir(from_path) |
|---|
| 238 | | RubricksLib.mkdir(to_path) |
|---|
| 239 | | if target == 'stylesheets' |
|---|
| 240 | | File.open("#{from_path}/stylesheet.rb", 'w') do |file| |
|---|
| 241 | | file.puts 'def css_list ' |
|---|
| 242 | | file.puts ' {' |
|---|
| 243 | | file.puts ':style => [:common],' |
|---|
| 244 | | file.puts ' }' |
|---|
| 245 | | file.puts 'end' |
|---|
| 246 | | end |
|---|
| 247 | | File.open("#{from_path}/common.css", 'w') do |file| |
|---|
| 248 | | file.puts 'body{color:#cccccc;}' |
|---|
| 249 | | end |
|---|
| 250 | | else |
|---|
| 251 | | File.open("#{from_path}/from.txt", 'w') do |file| |
|---|
| 252 | | file.puts 'test' |
|---|
| 253 | | end |
|---|
| 254 | | File.open("#{to_path}/to.txt", 'w') do |file| |
|---|
| 255 | | file.puts 'test' |
|---|
| 256 | | end |
|---|
| 257 | | end |
|---|
| 258 | | end |
|---|
| 259 | | render :text => "initialize_theme_dir. (#{theme_name})" |
|---|
| 260 | | end |
|---|
| 261 | | |
|---|
| 262 | | def init_theme_images |
|---|
| 263 | | theme_name = params[:theme_name] || 'test' |
|---|
| 264 | | image_name = params[:image_name] || 'screenshot.jpg' |
|---|
| 265 | | from_path = "#{RAILS_ROOT}/themes/#{theme_name}/images" |
|---|
| 266 | | to_path = "#{RAILS_ROOT}/public/images/themes/#{theme_name}" |
|---|
| 267 | | File.open("#{from_path}/#{image_name}", 'w') do |file| |
|---|
| 268 | | end |
|---|
| 269 | | File.open("#{to_path}/#{image_name}", 'w') do |file| |
|---|
| 270 | | end |
|---|
| 271 | | render :text => "initialize_image. (#{image_name})" |
|---|
| 272 | | end |
|---|
| 273 | | |
|---|
| 274 | | def install |
|---|
| 275 | | component_name = params[:component_name] || 'dummy002' |
|---|
| 276 | | from_path = "#{RAILS_ROOT}/test/rzips/#{component_name}.rzip" |
|---|
| 277 | | to_path = "#{RAILS_ROOT}/install/#{component_name}.rzip" |
|---|
| 278 | | RubricksLib.cp(from_path, to_path) |
|---|
| 279 | | RubricksComponent.component_install(component_name) |
|---|
| 280 | | render :text => "install #{component_name}" |
|---|
| 281 | | end |
|---|
| 282 | | |
|---|
| 283 | | def setup_install_rzip |
|---|
| 284 | | component_name = params[:rzip] || 'dummy002' |
|---|
| 285 | | from_path = "#{RAILS_ROOT}/test/rzips/#{component_name}.rzip" |
|---|
| 286 | | to_path = "#{RAILS_ROOT}/install/#{component_name}.rzip" |
|---|
| 287 | | RubricksLib.cp(from_path, to_path) |
|---|
| 288 | | render :text => "setup RZIP. (#{component_name}.rzip)" |
|---|
| 289 | | end |
|---|
| 290 | | |
|---|
| 291 | | def setup_update_rzip |
|---|
| 292 | | component_name = params[:rzip] || 'dummy002' |
|---|
| 293 | | prefix = params[:prefix] || 'update' |
|---|
| 294 | | from_path = "#{RAILS_ROOT}/test/rzips/#{prefix}_#{component_name}.rzip" |
|---|
| 295 | | to_path = "#{RAILS_ROOT}/install/#{component_name}.rzip" |
|---|
| 296 | | RubricksLib.cp(from_path, to_path) |
|---|
| 297 | | render :text => "setup RZIP. (#{component_name}.rzip)" |
|---|
| 298 | | end |
|---|
| 299 | | |
|---|
| 300 | | def truncate_table |
|---|
| 301 | | table_name = params[:table] |
|---|
| 302 | | begin |
|---|
| 303 | | ActiveRecord::Migration.execute("TRUNCATE TABLE #{table};") |
|---|
| 304 | | ActiveRecord::Migration.execute("ALTER TABLE #{table} AUTO_INCREMENT=1;") |
|---|
| 305 | | rescue Exception |
|---|
| 306 | | render :text => 'failed to truncate table.' |
|---|
| 307 | | else |
|---|
| 308 | | render :text => "truncate table '#{table_name}'." |
|---|
| 309 | | end |
|---|
| 310 | | end |
|---|
| 311 | | |
|---|
| 312 | | def uninstall |
|---|
| 313 | | component_name = params[:component_name] || 'dummy002' |
|---|
| 314 | | rc = RubricksComponent.find_by_name(component_name) |
|---|
| 315 | | if rc |
|---|
| 316 | | rc.active = false |
|---|
| 317 | | rc.save! |
|---|
| 318 | | messages = RubricksComponent.component_uninstall(rc.id, rc.display_name) |
|---|
| 319 | | if messages.empty? |
|---|
| 320 | | render :text => "install #{component_name}" |
|---|
| 321 | | else |
|---|
| 322 | | render :text => 'failed to uninstall.' |
|---|
| 323 | | end |
|---|
| 324 | | else |
|---|
| 325 | | render :text => 'failed to uninstall.' |
|---|
| 326 | | end |
|---|
| 327 | | end |
|---|
| 328 | | ################################################################### |
|---|
| 329 | | # Old |
|---|
| 330 | | ################################################################### |
|---|