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
|
# File 'lib/cortex_reaver/migrations/014_convert_projects_to_pages.rb', line 8
def up
pages = self[:pages]
projects = self[:projects]
unless root = pages.filter(:name => 'projects').first
pages.insert(
:name => 'projects',
:title => 'Projects',
:created_on => Time.now,
:updated_on => Time.now
)
end
root = pages.filter(:name => 'projects').first
projects.all.each do |project|
project_id = project[:id]
project.delete :description
project.delete :id
project[:page_id] = root[:id]
pages << project
page_id = pages.filter(:page_id => root[:id], :name => project[:name]).first[:id]
self[:comments].filter(:project_id => project_id).update(
:project_id => nil,
:page_id => page_id
)
self[:projects_tags].filter(:project_id => project_id).each do |t|
self[:pages_tags] << {:page_id => page_id, :tag_id => t[:tag_id]}
end
project_dir = File.join(
CortexReaver.config.public_root, 'data', 'projects', project_id.to_s
)
page_dir = File.join(
CortexReaver.config.public_root, 'data', 'pages', page_id.to_s
)
if File.directory? project_dir
if File.directory? page_dir
puts "WARNING: #{page_dir} already exists. Not moving contents of #{project_dir} into it. You should take a look."
else
FileUtils.move project_dir, page_dir
end
end
projects.filter(:id => project_id).delete
end
unless table_exists? :projects
drop_table :projects
end
end
|