From 7d5d45bb879af32585c23635203a204609f3b6f4 Mon Sep 17 00:00:00 2001 From: cHinn Date: Wed, 2 Dec 2015 12:02:33 +0700 Subject: [PATCH] Saving changes after finish uploading each language --- lib/deliver/upload_screenshots.rb | 40 ++++++++++++++++++------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/deliver/upload_screenshots.rb b/lib/deliver/upload_screenshots.rb index d3b272b..cd68c25 100644 --- a/lib/deliver/upload_screenshots.rb +++ b/lib/deliver/upload_screenshots.rb @@ -22,27 +22,33 @@ def upload(options, screenshots) # Now, fill in the new ones indized = {} # per language and device type - screenshots.each do |screenshot| - indized[screenshot.language] ||= {} - indized[screenshot.language][screenshot.device_type] ||= 0 - indized[screenshot.language][screenshot.device_type] += 1 # we actually start with 1... wtf iTC - index = indized[screenshot.language][screenshot.device_type] + screenshots_per_language = screenshots.group_by(&:language) + screenshots_per_language.each do |language, screenshots_for_language| + Helper.log.info "Uploading #{screenshots_for_language.length} screenshots for language #{language}" + screenshots_for_language.each do |screenshot| + indized[screenshot.language] ||= {} + indized[screenshot.language][screenshot.device_type] ||= 0 + indized[screenshot.language][screenshot.device_type] += 1 # we actually start with 1... wtf iTC - if index > 5 - Helper.log.error "Too many screenshots found for device '#{screenshot.device_type}' in '#{screenshot.language}'" - next - end + index = indized[screenshot.language][screenshot.device_type] - Helper.log.info "Uploading '#{screenshot.path}'..." - v.upload_screenshot!(screenshot.path, - index, - screenshot.language, - screenshot.device_type) - end + if index > 5 + Helper.log.error "Too many screenshots found for device '#{screenshot.device_type}' in '#{screenshot.language}'" + next + end - Helper.log.info "Saving changes" - v.save! + Helper.log.info "Uploading '#{screenshot.path}'..." + v.upload_screenshot!(screenshot.path, + index, + screenshot.language, + screenshot.device_type) + end + # ideally we should only save once, but itunes server can't cope it seems + # so we save per language. See issue #349 + Helper.log.info "Saving changes" + v.save! + end Helper.log.info "Successfully uploaded screenshots to iTunes Connect".green end