Diff
Modified: branches/snapshots/app/models/pack.rb (3168 => 3169)
--- branches/snapshots/app/models/pack.rb 2012-10-20 06:29:51 UTC (rev 3168)
+++ branches/snapshots/app/models/pack.rb 2012-10-20 06:46:03 UTC (rev 3169)
@@ -24,6 +24,15 @@
has_many :relationships, :dependent => :destroy, :as => :context
+ has_many :versions, :class_name => "PackVersion"
+
+ def find_version(version)
+ match = versions.find(:first, :conditions => ["version = ?", version])
+ return match if match
+
+ raise ActiveRecord::RecordNotFound.new("Couldn't find Pack with pack_id=#{id} and version=#{v}")
+ end
+
validates_presence_of :title
format_attribute :description
@@ -35,12 +44,14 @@
has_many :contributable_entries,
:class_name => "PackContributableEntry",
:foreign_key => :pack_id,
+ :conditions => "version IS NULL",
:order => "created_at DESC",
:dependent => :destroy
has_many :remote_entries,
:class_name => "PackRemoteEntry",
:foreign_key => :pack_id,
+ :conditions => "version IS NULL",
:order => "created_at DESC",
:dependent => :destroy
@@ -631,6 +642,51 @@
APIStatistics.statistics(self)
end
+ def snapshot!
+
+ self.current_version = self.current_version ? self.current_version + 1 : 1
+
+ inhibit_timestamps do
+
+ version = versions.build(
+ :version => current_version,
+ :contributor => contributor,
+ :title => title,
+ :description => description,
+ :description_html => description_html)
+
+ contributable_entries.each do |entry|
+
+ version.contributable_entries.build(
+ :pack => self,
+ :contributable_id => entry.contributable_id,
+ :contributable_type => entry.contributable_type,
+ :contributable_version => entry.contributable_version,
+ :comment => entry.comment,
+ :user_id => entry.user_id,
+ :version => current_version,
+ :created_at => entry.created_at,
+ :updated_at => entry.updated_at)
+ end
+
+ remote_entries.each do |entry|
+
+ tt = version.remote_entries.build(
+ :pack => self,
+ :title => entry.title,
+ :uri => entry.uri,
+ :alternate_uri => entry.alternate_uri,
+ :comment => entry.comment,
+ :user_id => entry.user_id,
+ :version => current_version,
+ :created_at => entry.created_at,
+ :updated_at => entry.updated_at)
+ end
+ end
+
+ save
+ end
+
protected
# produces html string containing the required messaged, enclosed within left-padded P tag, belonging to 'none_text' class
Modified: branches/snapshots/app/models/pack_contributable_entry.rb (3168 => 3169)
--- branches/snapshots/app/models/pack_contributable_entry.rb 2012-10-20 06:29:51 UTC (rev 3168)
+++ branches/snapshots/app/models/pack_contributable_entry.rb 2012-10-20 06:46:03 UTC (rev 3169)
@@ -21,12 +21,26 @@
after_destroy :touch_pack
def check_unique
- if self.contributable_version.blank?
- i = PackContributableEntry.find(:first, :conditions => ["pack_id = ? AND contributable_type = ? AND contributable_id = ? AND contributable_version IS NULL", self.pack_id, self.contributable_type, self.contributable_id])
+
+ conditions = ["pack_id = ?", "version = ?", "contributable_type = ?", "contributable_id = ?"]
+ arguments = [self.pack_id, self.version, self.contributable_type, self.contributable_id]
+
+ if self.contributable_version.nil?
+ conditions << "contributable_version IS NULL"
else
- i = PackContributableEntry.find(:first, :conditions => ["pack_id = ? AND contributable_type = ? AND contributable_id = ? AND contributable_version = ?", self.pack_id, self.contributable_type, self.contributable_id, self.contributable_version])
+ conditions << "contributable_version = ?"
+ arguments << self.contributable_version
end
-
+
+ if self.version.nil?
+ conditions << "version IS NULL"
+ else
+ conditions << "version = ?"
+ arguments << self.version
+ end
+
+ i = PackContributableEntry.find(:first, :conditions => [conditions.join(" AND ")] + arguments)
+
if i
errors.add_to_base("This item already exists in the pack")
return false
Modified: branches/snapshots/app/models/pack_remote_entry.rb (3168 => 3169)
--- branches/snapshots/app/models/pack_remote_entry.rb 2012-10-20 06:29:51 UTC (rev 3168)
+++ branches/snapshots/app/models/pack_remote_entry.rb 2012-10-20 06:46:03 UTC (rev 3169)
@@ -19,7 +19,7 @@
after_destroy :touch_pack
def check_unique
- if PackRemoteEntry.find(:first, :conditions => ["pack_id = ? AND uri = ?", self.pack_id, self.uri])
+ if PackRemoteEntry.find(:first, :conditions => ["pack_id = ? AND version = ? AND uri = ?", self.pack_id, self.version, self.uri])
errors.add_to_base("This external link already exists in the pack")
return false
else
Modified: branches/snapshots/config/routes.rb (3168 => 3169)
--- branches/snapshots/config/routes.rb 2012-10-20 06:29:51 UTC (rev 3168)
+++ branches/snapshots/config/routes.rb 2012-10-20 06:46:03 UTC (rev 3169)
@@ -136,6 +136,10 @@
map.blob_version '/files/:id/versions/:version', :conditions => { :method => :get }, :controller => 'blobs', :action ="" 'show'
map.formatted_blob_version '/files/:id/versions/:version.:format', :conditions => { :method => :get }, :controller => 'blobs', :action ="" 'show'
+ # pack redirect for linked data model
+ map.blob_version '/packs/:id/versions/:version', :conditions => { :method => :get }, :controller => 'packs', :action ="" 'show'
+ map.formatted_blob_version '/packs/:id/versions/:version.:format', :conditions => { :method => :get }, :controller => 'packs', :action ="" 'show'
+
map.blob_version_suggestions '/files/:id/versions/:version/suggestions', :conditions => { :method => :get }, :controller => 'blobs', :action ="" 'suggestions'
map.blob_version_process_suggestions '/files/:id/versions/:version/process_suggestions', :conditions => { :method => :post }, :controller => 'blobs', :action ="" 'process_suggestions'
Modified: branches/snapshots/config/schema.d/packs.xml (3168 => 3169)
--- branches/snapshots/config/schema.d/packs.xml 2012-10-20 06:29:51 UTC (rev 3168)
+++ branches/snapshots/config/schema.d/packs.xml 2012-10-20 06:46:03 UTC (rev 3169)
@@ -10,6 +10,7 @@
<column type="text" name="description_html"/>
<column type="datetime" name="created_at"/>
<column type="datetime" name="updated_at"/>
+ <column type="integer" name="current_version"/>
</table>
@@ -23,6 +24,7 @@
<column type="integer" name="user_id" null="false"/>
<column type="datetime" name="created_at"/>
<column type="datetime" name="updated_at"/>
+ <column type="integer" name="version"/>
</table>
@@ -36,6 +38,7 @@
<column type="integer" name="user_id" null="false"/>
<column type="datetime" name="created_at"/>
<column type="datetime" name="updated_at"/>
+ <column type="integer" name="version"/>
</table>
Added: branches/snapshots/db/migrate/098_create_pack_versions.rb (0 => 3169)
--- branches/snapshots/db/migrate/098_create_pack_versions.rb (rev 0)
+++ branches/snapshots/db/migrate/098_create_pack_versions.rb 2012-10-20 06:46:03 UTC (rev 3169)
@@ -0,0 +1,33 @@
+# myExperiment: db/migrate/097_create_pack_versions.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class CreatePackVersions < ActiveRecord::Migration
+
+ def self.up
+ create_table :pack_versions do |t|
+ t.integer "pack_id"
+ t.integer "version"
+ t.text "revision_comments"
+ t.string "title"
+ t.text "description"
+ t.text "description_html"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_column :packs, :current_version, :integer
+ add_column :pack_contributable_entries, :version, :integer
+ add_column :pack_remote_entries, :version, :integer
+ end
+
+ def self.down
+ remove_column :packs, :current_version
+ remove_column :pack_contributable_entries, :version
+ remove_column :pack_remote_entries, :version
+
+ drop_table :pack_versions
+ end
+end
+
Modified: branches/snapshots/db/schema.rb (3168 => 3169)
--- branches/snapshots/db/schema.rb 2012-10-20 06:29:51 UTC (rev 3168)
+++ branches/snapshots/db/schema.rb 2012-10-20 06:46:03 UTC (rev 3169)
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 97) do
+ActiveRecord::Schema.define(:version => 98) do
create_table "activity_limits", :force => true do |t|
t.string "contributor_type", :null => false
@@ -418,6 +418,7 @@
t.integer "user_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "version"
end
create_table "pack_remote_entries", :force => true do |t|
@@ -429,8 +430,20 @@
t.integer "user_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "version"
end
+ create_table "pack_versions", :force => true do |t|
+ t.integer "pack_id"
+ t.integer "version"
+ t.text "revision_comments"
+ t.string "title"
+ t.text "description"
+ t.text "description_html"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "packs", :force => true do |t|
t.integer "contributor_id"
t.string "contributor_type"
@@ -439,6 +452,7 @@
t.text "description_html"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "current_version"
end
create_table "pending_invitations", :force => true do |t|