cortex-reaver 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ module CortexReaver
2
+ class AdminController < Ramaze::Controller
3
+
4
+ map '/admin'
5
+ layout '/text_layout'
6
+ engine :Erubis
7
+
8
+ helper :error,
9
+ :auth,
10
+ :form,
11
+ :workflow
12
+
13
+ def index
14
+ end
15
+
16
+ # Recalculate tag counts and vacuum unused tags
17
+ def update_tags
18
+ @updated = Tag.refresh_counts
19
+ @deleted = []
20
+ Tag.unused.order(:title).all.each do |tag|
21
+ @deleted << tag.destroy
22
+ end
23
+ end
24
+ end
25
+ end
@@ -122,8 +122,6 @@ module Ramaze
122
122
  raise unless @model.save
123
123
  end
124
124
 
125
- raise RuntimeError.new("Ack!")
126
-
127
125
  flash[:notice] = "Created #{model_class.to_s.demodulize.downcase} #{h @model.to_s}."
128
126
  redirect @model.url
129
127
  end
@@ -0,0 +1,18 @@
1
+ module CortexReaver
2
+ # Changes MySQL table engines to InnoDB
3
+ class MySQLSchema < Sequel::Migration
4
+ def down
5
+ # Noop
6
+ end
7
+
8
+ def up
9
+ db = CortexReaver.db
10
+ if db.is_a? Sequel::MySQL::Database
11
+ # Use InnoDB storage for everything
12
+ db.tables.each do |table|
13
+ db << "ALTER TABLE `#{table.to_s}` ENGINE = InnoDB;"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -7,6 +7,8 @@ module CortexReaver
7
7
  many_to_many :projects, :class => 'CortexReaver::Project'
8
8
  many_to_many :pages, :class => 'CortexReaver::Page'
9
9
 
10
+ subset :unused, :count => 0
11
+
10
12
  validates do
11
13
  uniqueness_of :name
12
14
  presence_of :name
@@ -30,9 +32,12 @@ module CortexReaver
30
32
 
31
33
  # Recalculates the number of children on each tag, and saves the updated values.
32
34
  def self.refresh_counts
33
- all.each do |tag|
34
- tag.refresh_count
35
+ updated = []
36
+ order(:title).all.each do |tag|
37
+ result = tag.refresh_count
38
+ updated << [tag, result] if result
35
39
  end
40
+ updated
36
41
  end
37
42
 
38
43
  def self.get(id)
@@ -47,18 +52,24 @@ module CortexReaver
47
52
  '/tags/atom/' + name
48
53
  end
49
54
 
50
- # Recalculates the number of children on this tag, and saves the update value.
55
+ # Recalculates the number of children on this tag, and saves the update value. Returns [old_count, new_count] if changed.
51
56
  def refresh_count
52
57
  # Find counts
58
+ old_count = self[:count]
53
59
  self[:count] = photographs_dataset.count +
54
60
  journals_dataset.count +
55
61
  pages_dataset.count +
56
62
  projects_dataset.count
57
63
 
58
64
  # Save and return
59
- self.skip_timestamp_update = true
65
+ changed = changed_columns.include? :count
60
66
  self.save
61
- self[:count]
67
+
68
+ if changed
69
+ [old_count, self[:count]]
70
+ else
71
+ nil
72
+ end
62
73
  end
63
74
 
64
75
  def url
@@ -1,6 +1,6 @@
1
1
  module CortexReaver
2
2
  APP_NAME = 'Cortex Reaver'
3
- APP_VERSION = '0.0.5'
3
+ APP_VERSION = '0.0.6'
4
4
  APP_AUTHOR = 'aphyr'
5
5
  APP_EMAIL = 'aphyr@aphyr.com'
6
6
  APP_URL = 'http://aphyr.com'
@@ -0,0 +1,5 @@
1
+ <h2>Administration</h2>
2
+
3
+ <ul>
4
+ <li><%= A('Update tags', :href => Rs(:update_tags)) %></li>
5
+ </ul>
@@ -0,0 +1,37 @@
1
+ <h2>Updated tag counts</h2>
2
+
3
+ <% if @updated.empty? %>
4
+ <p>Everything up to date.</p>
5
+ <% else %>
6
+ <p>These tags had an incorrectly cached number of associated objects, and were updated to reflect the correct value.</p>
7
+
8
+ <table>
9
+ <thead>
10
+ <th>Tag</th>
11
+ <th>Old</th>
12
+ <th>New</th>
13
+ </thead>
14
+ <tbody>
15
+ <% @updated.each do |tag, counts| %>
16
+ <tr>
17
+ <td><%=h tag.title %></td>
18
+ <td><%= counts[0] %></td>
19
+ <td><%= counts[1] %></td>
20
+ </tr>
21
+ <% end %>
22
+ </tbody>
23
+ </table>
24
+ <% end %>
25
+
26
+
27
+ <h2>Deleted unused tags</h2>
28
+ <% if @deleted.empty? %>
29
+ <p>Every tag is currently in use.</p>
30
+ <% else %>
31
+ <p>These tags had no associated objects, and were deleted:</p>
32
+ <ul>
33
+ <% @deleted.each do |tag| %>
34
+ <li><%=h tag.title %></li>
35
+ <% end %>
36
+ </ul>
37
+ <% end %>
@@ -12,7 +12,7 @@
12
12
  <li><a href="/comments">Comments</a></li>
13
13
  <li><a href="/tags">Tags</a></li>
14
14
  <li><a href="/users">Users</a></li>
15
- <li><a href="/config">Config</a></li>
15
+ <li><a href="/admin">Admin</a></li>
16
16
  </ul>
17
17
  </td>
18
18
  </tr>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cortex-reaver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - aphyr
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-24 00:00:00 -08:00
12
+ date: 2008-12-29 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -139,6 +139,7 @@ files:
139
139
  - lib/cortex_reaver/controller/journal.rb
140
140
  - lib/cortex_reaver/controller/documentation.rb
141
141
  - lib/cortex_reaver/controller/photograph.rb
142
+ - lib/cortex_reaver/controller/admin.rb
142
143
  - lib/cortex_reaver/controller/page.rb
143
144
  - lib/cortex_reaver/controller/tag.rb
144
145
  - lib/cortex_reaver/support
@@ -160,6 +161,9 @@ files:
160
161
  - lib/cortex_reaver/view/users/user.rhtml
161
162
  - lib/cortex_reaver/view/users/list.rhtml
162
163
  - lib/cortex_reaver/view/users/form.rhtml
164
+ - lib/cortex_reaver/view/admin
165
+ - lib/cortex_reaver/view/admin/index.rhtml
166
+ - lib/cortex_reaver/view/admin/update_tags.rhtml
163
167
  - lib/cortex_reaver/view/text_layout.rhtml
164
168
  - lib/cortex_reaver/view/pages
165
169
  - lib/cortex_reaver/view/pages/show.rhtml
@@ -261,6 +265,7 @@ files:
261
265
  - lib/cortex_reaver/migrations/006_tags.rb
262
266
  - lib/cortex_reaver/migrations/008_config.rb
263
267
  - lib/cortex_reaver/migrations/007_comments.rb
268
+ - lib/cortex_reaver/migrations/009_mysql.rb
264
269
  - lib/cortex_reaver/migrations/001_users.rb
265
270
  - lib/cortex_reaver/migrations/003_journals.rb
266
271
  - lib/cortex_reaver/version.rb