From c91d1219d0c6202d6ddbf1412eae0ca4df6e5c68 Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Sat, 25 Jun 2011 19:23:46 +0400 Subject: [PATCH] Import fix if empty release group --- app/controllers/import_controller.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/controllers/import_controller.rb b/app/controllers/import_controller.rb index d48414d..c94ecd1 100644 --- a/app/controllers/import_controller.rb +++ b/app/controllers/import_controller.rb @@ -43,19 +43,21 @@ class ImportController < ApplicationController # Get album releases from MB releases_mb = brainz.release(nil, {'release-group' => mb_album['id']})['release_list']['release'] - if releases_mb.is_a? Hash - releases_mb = [releases_mb] - end - releases_mb.delete_if { |a| a['date'].nil? } - releases_mb.each do |release| - if release['date'].length == 4 - release['date'] += '-12-28' - elsif release['date'].length == 7 - release['date'] += '-28' + + unless releases_mb.empty? or releases_mb.nil? + + if releases_mb.is_a? Hash + releases_mb = [releases_mb] + end + + releases_mb.delete_if { |a| a['date'].nil? } + releases_mb.each do |release| + if release['date'].length == 4 + release['date'] += '-12-28' + elsif release['date'].length == 7 + release['date'] += '-28' + end end - end - - unless releases_mb.empty? # Sorting releases by date releases_mb.sort! { |a, b| a['date'].to_date <=> b['date'].to_date }