From 655e30f99507cada357e87febc3d17ee5402fd30 Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Wed, 29 Jun 2011 00:54:46 +0400 Subject: [PATCH] Import dry run --- app/coffeescripts/session.coffee | 1 - app/controllers/import_controller.rb | 12 +++++++----- lib/tasks/db_import.rake | 5 ++--- public/javascripts/coffee/session.js | 1 - 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/coffeescripts/session.coffee b/app/coffeescripts/session.coffee index 611c513..1642f80 100644 --- a/app/coffeescripts/session.coffee +++ b/app/coffeescripts/session.coffee @@ -10,7 +10,6 @@ class Session if params[key]? _params[key] = params[key] @vk_params = _params - false setUser: (user) -> @user = user diff --git a/app/controllers/import_controller.rb b/app/controllers/import_controller.rb index db1d8e2..785c121 100644 --- a/app/controllers/import_controller.rb +++ b/app/controllers/import_controller.rb @@ -11,7 +11,7 @@ class ImportController < ApplicationController @@brainz_login = 'magnolia_fan' @@brainz_password = '111111' - def self.importArtist name + def self.importArtist name, dry_run = false # Initializing gems brainz = MusicBrainz::Client.new(@@brainz_login, @@brainz_password, @@user_agent) @@ -52,7 +52,7 @@ class ImportController < ApplicationController # Checking if there is already an album with the same name albums_db = Album.where(:artist_id => artist.id, :name => album_name, :album_type => mb_album['type']) - + # Get album releases from MB releases_mb = brainz.release(nil, {'release-group' => mb_album['id']}) @@ -121,7 +121,8 @@ class ImportController < ApplicationController album.mbid = mb_album['id'] album.album_type = mb_album['type'] album.pic_url = album_image - album.save + album.save unless dry_run + ap album if dry_run # Creating hashed array for matching mb_main_tracks_hashed = [] @@ -175,7 +176,7 @@ class ImportController < ApplicationController track.live = mb_track['recording']['title'].downcase.include? 'live' track.acoustic = mb_track['recording']['title'].downcase.include? 'acoustic' track.mbid = mb_track['recording']['id'] - track.save + track.save unless dry_run end end @@ -199,7 +200,8 @@ class ImportController < ApplicationController artist.status = 2 end - artist.save + artist.save unless dry_run + ap artist if dry_run end # def self.importArtist name diff --git a/lib/tasks/db_import.rake b/lib/tasks/db_import.rake index fc4bb98..0095d71 100644 --- a/lib/tasks/db_import.rake +++ b/lib/tasks/db_import.rake @@ -4,10 +4,9 @@ namespace :db do desc 'Imports test data from MusicBrainz database' task :import => :environment do - ati = ['Ashes Divide'] + ati = ['Vampire Weekend'] ati.each do |name| - ImportController.importArtist(name) - #ap res = ArtistController.musicBrainzExactSearch(name) + ImportController.importArtist(name, true) end end end \ No newline at end of file diff --git a/public/javascripts/coffee/session.js b/public/javascripts/coffee/session.js index 312ef85..2d3a5ce 100644 --- a/public/javascripts/coffee/session.js +++ b/public/javascripts/coffee/session.js @@ -13,7 +13,6 @@ Session = (function() { } } this.vk_params = _params; - false; } Session.prototype.setUser = function(user) { this.user = user;