リビジョン | 964c3e1a9103cb585c816bc2fc630bfa8d8e6cf0 (tree) |
---|---|
日時 | 2013-01-21 11:33:36 |
作者 | ![]() |
コミッター | yasushiito |
t#30487:fix export error
@@ -108,8 +108,13 @@ class ApplicationController < ActionController::Base | ||
108 | 108 | end |
109 | 109 | |
110 | 110 | def export_from_provider url |
111 | - json = RestClient.get url | |
112 | - JSON.parse json | |
111 | + res = nil | |
112 | + begin | |
113 | + json = RestClient.get url | |
114 | + res = JSON.parse json | |
115 | + rescue | |
116 | + end | |
117 | + res | |
113 | 118 | end |
114 | 119 | |
115 | 120 | def export_by action, provider_status, ymd |
@@ -1,7 +1,31 @@ | ||
1 | 1 | class ProviderStatusesController < ApplicationController |
2 | 2 | layout 'test' if MagicNumber['test_layout'] |
3 | 3 | before_filter :authenticate_admin!, :only => [:index, :show, :edit, :update, :destroy, :licenses_import, :artists_import, :original_pictures_import] |
4 | - | |
4 | + | |
5 | + private | |
6 | + | |
7 | + def licenses_port | |
8 | + licenses = export_by('licenses_export', @provider_status, params[:date]) | |
9 | + return nil unless licenses | |
10 | + ProviderLicense.import @provider_status.provider.id, licenses | |
11 | + end | |
12 | + | |
13 | + def artists_port | |
14 | + artists = export_by('artists_export', @provider_status, params[:date]) | |
15 | + return nil unless artists | |
16 | + ProviderArtist.import @provider_status.provider.id, artists | |
17 | + end | |
18 | + | |
19 | + def original_pictures_port | |
20 | + original_pictures = export_by('original_pictures_export', @provider_status, params[:date]) | |
21 | + return nil unless original_pictures | |
22 | + pictures = export_by('pictures_export', @provider_status, params[:date]) | |
23 | + return nil unless pictures | |
24 | + ProviderOriginalPicture.import @provider_status.provider.id, original_pictures, pictures | |
25 | + end | |
26 | + | |
27 | + public | |
28 | + | |
5 | 29 | def index |
6 | 30 | @page = ProviderStatus.page params[:page] |
7 | 31 | @page_size = ProviderStatus.page_size params[:page_size] |
@@ -69,9 +93,7 @@ class ProviderStatusesController < ApplicationController | ||
69 | 93 | def licenses_import |
70 | 94 | @provider_status = ProviderStatus.show(params[:id], @admin) |
71 | 95 | raise ActiveRecord::Forbidden if @provider_status.status == 0 |
72 | - t = ymd_to_time params[:date] | |
73 | - url = export_url @provider_status.provider.demander_url, 'licenses_export', @provider_status.token, t | |
74 | - @failures = ProviderLicense.import @provider_status.provider.id, export_from_provider(url) | |
96 | + @failures = licenses_port | |
75 | 97 | respond_to do |format| |
76 | 98 | format.html # show.html.erb |
77 | 99 | format.json { render :json => @failures.to_json() } |
@@ -81,9 +103,7 @@ class ProviderStatusesController < ApplicationController | ||
81 | 103 | def artists_import |
82 | 104 | @provider_status = ProviderStatus.show(params[:id], @admin) |
83 | 105 | raise ActiveRecord::Forbidden if @provider_status.status == 0 |
84 | - t = ymd_to_time params[:date] | |
85 | - url = export_url @provider_status.provider.demander_url, 'artists_export', @provider_status.token, t | |
86 | - @failures = ProviderArtist.import @provider_status.provider.id, export_from_provider(url) | |
106 | + @failures = artists_port | |
87 | 107 | respond_to do |format| |
88 | 108 | format.html # show.html.erb |
89 | 109 | format.json { render :json => @failures.to_json() } |
@@ -93,9 +113,7 @@ class ProviderStatusesController < ApplicationController | ||
93 | 113 | def original_pictures_import |
94 | 114 | @provider_status = ProviderStatus.show(params[:id], @admin) |
95 | 115 | raise ActiveRecord::Forbidden if @provider_status.status == 0 |
96 | - original_pictures = export_by('original_pictures_export', @provider_status, params[:date]) | |
97 | - pictures = export_by('pictures_export', @provider_status, params[:date]) | |
98 | - @failures = ProviderOriginalPicture.import @provider_status.provider.id, original_pictures, pictures | |
116 | + @failures = original_pictures_port | |
99 | 117 | respond_to do |format| |
100 | 118 | format.html # show.html.erb |
101 | 119 | format.json { render :json => @failures.to_json() } |
@@ -1,7 +1,9 @@ | ||
1 | 1 | <h1><%= t('.title') %></h1> |
2 | 2 | <p id="notice"><%= notice %></p> |
3 | 3 | |
4 | -<% if @failures.empty? %> | |
4 | +<% if @failures == nil %> | |
5 | + <h1>No Response</h1> | |
6 | +<% elsif @failures.empty? %> | |
5 | 7 | <h2> |
6 | 8 | <%= t('provider_statuses.artists_import.success') %> |
7 | 9 | </h2> |
@@ -1,7 +1,9 @@ | ||
1 | 1 | <h1><%= t('.title') %></h1> |
2 | 2 | <p id="notice"><%= notice %></p> |
3 | 3 | |
4 | -<% if @failures.empty? %> | |
4 | +<% if @failures == nil %> | |
5 | + <h1>No Response</h1> | |
6 | +<% elsif @failures.empty? %> | |
5 | 7 | <h2> |
6 | 8 | <%= t('provider_statuses.licenses_import.success') %> |
7 | 9 | </h2> |
@@ -1,7 +1,9 @@ | ||
1 | 1 | <h1><%= t('.title') %></h1> |
2 | 2 | <p id="notice"><%= notice %></p> |
3 | 3 | |
4 | -<% if @failures[:original_pictures].any? %> | |
4 | +<% if @failures == nil %> | |
5 | + <h1>No Response</h1> | |
6 | +<% elsif @failures[:original_pictures].any? %> | |
5 | 7 | <h2> |
6 | 8 | <%= t('provider_statuses.original_pictures_import.fail', :size => @failures[:original_pictures].size) %> |
7 | 9 | </h2> |