-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
130 lines (104 loc) · 3.53 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
Ada::Application.load_tasks
namespace :ada do
task :rebuild => :environment do
if ["development", "devs", "test", "staging"].include? Rails.env or `hostname` =~ /\.local/
["db:drop", "db:create", "db:migrate", "db:bootstrap", "db:seed", "install_theme", "publish_all"].each do |t|
Rake::Task[t].execute
end
else
puts "ada:rebuild isn't meant to run on staff, public, or any other production level environment."
end
end
end
task :install_theme => :environment do
Inkling::Theme.install_from_dir("config/theme")
end
#tasks necessary for cruisecontrolrb
task :cruise => [:test_env, :bundler, :environment, "ada:rebuild", :spec]
task :test_env do
ENV['RAILS_ENV'] = 'test'
end
task :bundler do
system('bundle install')
end
task :regenerate_paths => :environment do
for klass in [Page, ArchiveNews, ArchiveStudy, Document, Image, ArchiveCatalog, Inkling::Feed]
klass.all.each do |content|
content.save!
puts "#{klass.to_s}-(title #{content.title}): #{content.path.slug}"
end
end
end
task :create_feeds => :environment do
for archive in Archive.all
Inkling::Feed.create!(:title => "#{archive.name} Atom Feed", :format => "Inkling::Feeds::Atom", :source => "NewsFeedsSource", :authors => archive.name, :criteria => {:archive_id => archive.id})
end
end
task :ensure_menu_items => :environment do
MenuItem.delete_all
parent_pages = Page.find_all_by_parent_id(nil)
parent_pages.each do |page|
menu_items_for_tree(page)
end
end
def menu_items_for_tree(page)
MenuItem.create_from_page(page)
for child in page.children
menu_items_for_tree(child)
end
end
task :reindex => :environment do
extend TimeInWords
log = Inkling::Log.create!(:category => "search-index", :text => "Solr began reindexing")
system("rake sunspot:solr:reindex")
duration = time_in_words(Time.now, log.created_at)
Inkling::Log.create!(:category => "search-index", :text => "Solr finished index after #{duration}")
end
task :var_count => :environment do
Archive.all.each do |archive|
next if archive.name == "ADA"
study_ids = archive.studies.collect {|s| s.id}
study_ids = study_ids.join ","
study_ids = "(#{study_ids})"
puts "#{archive.name}: has #{Variable.count(:conditions => ["study_id in #{study_ids}"])} vars"
end
end
namespace :postgres do
dbhost = Secrets::DATABASE_HOST
dbport = 5432
dbuser = Secrets::DATABASE_USERNAME
dbpass = Secrets::DATABASE_PASSWORD
connection = "-U #{dbuser} --host #{dbhost} -p #{dbport}"
task :pull => :environment do
source_db = "adacms_#{ENV['source']}"
target_db = "adacms_#{Rails.env}"
filename = "tmp/#{source_db}.tar"
Rake::Task['db:drop'].execute
Rake::Task['db:create'].execute
system "export PGPASSWORD=#{dbpass} &&
pg_dump -Ft -b #{connection} #{source_db} > #{filename} &&
pg_restore -O #{connection} -d #{target_db} #{filename} &&
rm #{filename}"
end
end
# task :prime_cache => :environment do
# require 'httparty'
# include HTTParty
# Inkling::Path.all.each do |path|
# get "http://localhost:3000#{path.slug}"
# end
# end
task :publish_all => :environment do
u = User.first
publishables = Page.all + News.all
publishables.each do |o|
o.publish!(u)
end
end
task :destroy_paths => :environment do
Inkling::Path.delete_all
end