Guest User

Untitled

a guest
Jul 6th, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. def highline
  2. @highline ||= begin
  3. require "highline"
  4. HighLine.new
  5. end
  6. end
  7.  
  8. # Ugh. As much as I hate ugly hacks, I have to do this.
  9. # For what reason? It defaults to test. Always.
  10. # I have absolutely no clue why.
  11. # It is late on a Sunday night, all I want to do is relax and go to bed with a clear mind.
  12. # If you can fix this better than I am, you are a better man (or woman)
  13. # I have to do this.
  14. # Forgive me.
  15. def establish_connection
  16. ActiveRecord::Base.establish_connection(YAML.load_file("#{RAILS_ROOT}/config/database.yml")[ENV['RAILS_ENV']])
  17. end
  18.  
  19. task :install => :environment do
  20. puts "Creating databases..."
  21. # Check the comment for this method.
  22. establish_connection
  23. Rake::Task["db:create:all"].invoke if STANDALONE
  24. puts "Loading schema..."
  25. # Check the comment for this method.
  26. establish_connection
  27. Rake::Task["db:schema:load"].invoke
  28.  
  29. puts "*" * 50
  30. puts "Welcome to rBoard's install process."
  31. puts "*" * 50
  32. login = highline.ask("What would you like your login for the administrator account to be?")
  33.  
  34. password = highline.ask("What would you like your password for this account to be?")
  35.  
  36. email = highline.ask("What is your email address for this account?")
  37.  
  38. login, password, email = [login, password, email].map!(&:strip)
  39.  
  40. puts "Creating admin user now..."
  41. administrator = User.new(:login => login, :password => password, :password_confirmation => password, :email => email)
  42. administrator.identifier = "administrator"
  43. administrator.save!
  44.  
  45. Theme.create(:name => "blue", :is_default => true)
  46.  
  47. # Administrator account
  48.  
  49. administrator_group = Group.new(:name => "Administrators", :owner => administrator)
  50. administrator_group.identifier = "administrators"
  51. administrator_group.save!
  52.  
  53. # Admin can do everything!
  54. permissions = {}
  55. Permission.column_names.grep(/can/).each do |permission|
  56. permissions.merge!(permission => true)
  57. end
  58.  
  59. administrator_group.permissions.create!(permissions)
  60.  
  61. puts "Creating anonymous user now..."
  62. anonymous_password = Digest::SHA1.hexdigest(rand(99999999).to_s)
  63. u = User.new(:login => "anonymous", :password => anonymous_password, :password_confirmation => anonymous_password, :email => "anonymous@rboard.com", :user_level => UserLevel.find_by_name(I18n.t(:Anonymous)))
  64. u.identifier = "anonymous"
  65. u.save!
  66.  
  67. anonymous_group = Group.new(:name => "Anonymous", :owner => u)
  68. anonymous_group.identifier = "anonymous"
  69. anonymous_group.save!
  70.  
  71. anonymous_group.permissions.create!(:can_see_forum => true,
  72. :can_see_category => true)
  73.  
  74.  
  75.  
  76. puts "Creating registered users group..."
  77. registered_group = Group.new(:name => "Registered Users", :owner => administrator)
  78. registered_group.identifier = "registered_users"
  79. registered_group.save!
  80.  
  81. registered_group.permissions.create!(:can_see_forum => true,
  82. :can_see_category => true,
  83. :can_start_new_topics => true,
  84. :can_use_signature => true,
  85. :can_delete_own_posts => true,
  86. :can_edit_own_posts => true,
  87. :can_subscribe => true,
  88. :can_read_private_messages => true,
  89. :can_see_category => true)
  90.  
  91. puts "Generating some configuration options..."
  92. Configuration.create(:key => "subforums_display", :title => I18n.t(:subforums_display), :value => 3, :description => I18n.t(:subforums_display_description))
  93.  
  94. if SEARCHING
  95. puts "Configuring thinking sphinx..."
  96. Rake::Task['ts:config']
  97. puts "Running the index..."
  98. Rake::Task['ts:index']
  99. puts "Starting thinking sphinx up!"
  100. Rake::Task['ts:start']
  101. end
  102.  
  103.  
  104. puts "Creating first forum..."
  105.  
  106. f = Forum.create(:title => I18n.t(:Welcome_to_rBoard), :description => I18n.t(:example_forum_description))
  107.  
  108. puts "Creating first topic..."
  109. t = f.topics.build(:subject => I18n.t(:Welcome_to_rBoard), :user => u)
  110. puts "... and first topic..."
  111. t.posts.build(:text => I18n.t(:Welcome_to_rBoard_post), :user => u)
  112. t.save
  113. puts "Done!"
  114.  
  115. end
Add Comment
Please, Sign In to add comment