Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate tasks in core/lib/tasks #2080

Merged
merged 4 commits into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions core/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Loads seed data out of default dir
default_path = File.join(File.dirname(__FILE__), 'default')

Rake::Task['db:load_dir'].reenable
Rake::Task['db:load_dir'].invoke(default_path)
%w(
stores
store_credit
countries
return_reasons
states
stock_locations
zones
refund_reasons
roles
shipping_categories
).each do |seed|
puts "Loading seed file: #{seed}"
require_relative "default/spree/#{seed}"
end
1 change: 0 additions & 1 deletion core/lib/generators/spree/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'rails/generators'
require 'highline/import'
require 'bundler'
require 'bundler/cli'

Expand Down
27 changes: 17 additions & 10 deletions core/lib/tasks/core.rake
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
require 'active_record'

def prompt_for_agree(prompt)
print prompt
["y", "yes"].include? STDIN.gets.strip.downcase
end

namespace :db do
desc 'Loads a specified fixture file:
use rake db:load_file[/absolute/path/to/sample/filename.rb]'

task :load_file, [:file, :dir] => :environment do |_t, args|
Spree::Deprecation.warn("load_file has been deprecated. Please load your own file.")
file = Pathname.new(args.file)

puts "loading ruby #{file}"
Expand All @@ -13,6 +19,7 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]'

desc "Loads fixtures from the the dir you specify using rake db:load_dir[loadfrom]"
task :load_dir, [:dir] => :environment do |_t, args|
Spree::Deprecation.warn("rake spree:load_dir has been deprecated and will be removed with Solidus 3.0. Please load your files directly.")
dir = args.dir
dir = File.join(Rails.root, "db", dir) if Pathname.new(dir).relative?

Expand All @@ -32,9 +39,9 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]'

desc "Migrate schema to version 0 and back up again. WARNING: Destroys all data in tables!!"
task remigrate: :environment do
require 'highline/import'
Spree::Deprecation.warn("remigrate has been deprecated. Please use db:reset or other db: commands instead.")

if ENV['SKIP_NAG'] || ENV['OVERWRITE'].to_s.casecmp('true') || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")
if ENV['SKIP_NAG'] || ENV['OVERWRITE'].to_s.casecmp('true') || prompt_for_agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")

# Drop all tables
ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.drop_table t }
Expand All @@ -45,45 +52,45 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]'
# Dump the schema
Rake::Task["db:schema:dump"].invoke
else
say "Task cancelled."
puts "Task cancelled."
exit
end
end

desc "Bootstrap is: migrating, loading defaults, sample data and seeding (for all extensions) and load_products tasks"
task :bootstrap do
require 'highline/import'
Spree::Deprecation.warn("rake bootstrap has been deprecated, please run db:setup instead.")

# remigrate unless production mode (as saftey check)
if %w[demo development test].include? Rails.env
if ENV['AUTO_ACCEPT'] || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")
if ENV['AUTO_ACCEPT'] || prompt_for_agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")
ENV['SKIP_NAG'] = 'yes'
Rake::Task["db:create"].invoke
Rake::Task["db:remigrate"].invoke
else
say "Task cancelled, exiting."
puts "Task cancelled, exiting."
exit
end
else
say "NOTE: Bootstrap in production mode will not drop database before migration"
puts "NOTE: Bootstrap in production mode will not drop database before migration"
Rake::Task["db:migrate"].invoke
end

ActiveRecord::Base.send(:subclasses).each(&:reset_column_information)

load_defaults = Spree::Country.count == 0
unless load_defaults # ask if there are already Countries => default data hass been loaded
load_defaults = agree('Countries present, load sample data anyways? [y/n]: ')
load_defaults = prompt_for_agree('Countries present, load sample data anyways? [y/n]: ')
end
if load_defaults
Rake::Task["db:seed"].invoke
end

if Rails.env.production? && Spree::Product.count > 0
load_sample = agree("WARNING: In Production and products exist in database, load sample data anyways? [y/n]:" )
load_sample = prompt_for_agree("WARNING: In Production and products exist in database, load sample data anyways? [y/n]:" )
else
load_sample = true if ENV['AUTO_ACCEPT']
load_sample = agree('Load Sample Data? [y/n]: ') unless load_sample
load_sample = prompt_for_agree('Load Sample Data? [y/n]: ') unless load_sample
end

if load_sample
Expand Down
1 change: 0 additions & 1 deletion core/solidus_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Gem::Specification.new do |s|
s.add_dependency 'cancancan', '~> 1.10'
s.add_dependency 'ffaker', '~> 2.0'
s.add_dependency 'friendly_id', '~> 5.0'
s.add_dependency 'highline', '~> 1.7' # Necessary for the install generator
s.add_dependency 'kaminari', '>= 0.17', '< 2.0'
s.add_dependency 'monetize', '~> 1.1'
s.add_dependency 'paperclip', ['>= 4.2', '< 6']
Expand Down