Diff
Modified: branches/versions/app/controllers/blobs_controller.rb (3048 => 3049)
--- branches/versions/app/controllers/blobs_controller.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/app/controllers/blobs_controller.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -133,12 +133,8 @@
@blob = Blob.new(params[:blob])
@blob.content_blob = ContentBlob.new(:data ="" data)
- @blob.content_type = ContentType.find_by_mime_type(content_type)
+ @blob.content_type = ContentType.find_or_create_by_mime_type(:user => current_user, :mime_type => content_type, :category=> 'Blob')
- if @blob.content_type.nil?
- @blob.content_type = ContentType.create(:user_id => current_user.id, :mime_type => content_type, :title => content_type, :category => 'Blob')
- end
-
respond_to do |format|
if @blob.save
if params[:blob][:tag_list]
@@ -186,8 +182,18 @@
params[:blob][:license_id] = nil if params[:blob][:license_id] && params[:blob][:license_id] == "0"
- # 'Data' (ie: the actual file) cannot be updated!
- params[:blob].delete('data') if params[:blob][:data]
+ # Create a new content blob entry if new data is provided.
+ if params[:blob][:data] && params[:blob][:data].size > 0
+ puts "AAAAAAAAAAAAAA"
+ @blob.build_content_blob(:data ="" params[:blob][:data].read)
+ puts "BBBBBBBBBBBBBB"
+ @blob.local_name = params[:blob][:data].original_filename
+ puts "CCCCCCCCCCCCCC"
+ @blob.content_type = ContentType.find_or_create_by_mime_type(:user => current_user, :title => params[:blob][:data].content_type, :mime_type => params[:blob][:data].content_type, :category => 'Blob')
+puts "@blob.content_type = address@hidden"
+ end
+
+ params[:blob].delete(:data)
respond_to do |format|
if @blob.update_attributes(params[:blob])
Modified: branches/versions/app/models/blob.rb (3048 => 3049)
--- branches/versions/app/models/blob.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/app/models/blob.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -25,6 +25,13 @@
acts_as_attributor
acts_as_attributable
+ has_versions :blob_versions,
+
+ :attributes => [ :title, :body, :body_html, :content_type, :content_blob,
+ :local_name ],
+
+ :mutable => [ :title, :body, :body_html ]
+
acts_as_solr(:fields => [:title, :local_name, :body, :kind, :uploader, :tag_list],
:boost => "rank",
:include => [ :comments ]) if Conf.solr_enable
Added: branches/versions/app/models/blob_version.rb (0 => 3049)
--- branches/versions/app/models/blob_version.rb (rev 0)
+++ branches/versions/app/models/blob_version.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -0,0 +1,20 @@
+# myExperiment: app/models/blob_versions.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class BlobVersion < ActiveRecord::Base
+
+ is_version_of :blob
+
+ format_attribute :body
+
+ belongs_to :content_blob, :dependent => :destroy
+ belongs_to :content_type
+
+ validates_presence_of :content_blob
+ validates_presence_of :content_type
+ validates_presence_of :title
+
+end
+
Modified: branches/versions/app/views/blobs/edit.rhtml (3048 => 3049)
--- branches/versions/app/views/blobs/edit.rhtml 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/app/views/blobs/edit.rhtml 2012-07-27 15:23:41 UTC (rev 3049)
@@ -7,8 +7,18 @@
<%= error_messages_for :blob %>
-<% form_for(:blob, :url ="" blob_path(@blob), :html => { :method => :put }) do |f| %>
+<% form_for(:blob, :url ="" blob_path(@blob), :html => { :method => :put, :multipart => true }) do |f| %>
+ <div style="text-align: center;">
+ <div>
+ <strong>File to upload: </strong>
+ <%= file_field :blob, :data %>
+ </div>
+ <div><small><em>Leave this field blank unless you want to replace the file content</em></small></div>
+ </div>
+
+ <br/>
+
<p style="text-align: center;">
<strong>Title: </strong>
<br/>
Deleted: branches/versions/config/schema.d/files.xml (3048 => 3049)
--- branches/versions/config/schema.d/files.xml 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/config/schema.d/files.xml 2012-07-27 15:23:41 UTC (rev 3049)
@@ -1,21 +0,0 @@
-<?xml version="1.0"?>
-<schema>
-
- <table name="blobs">
-
- <column type="integer" name="contributor_id"/>
- <column type="string" name="contributor_type"/>
- <column type="string" name="local_name"/>
- <column type="datetime" name="created_at"/>
- <column type="datetime" name="updated_at"/>
- <column type="string" name="title"/>
- <column type="text" name="body"/>
- <column type="text" name="body_html"/>
- <column type="integer" name="content_blob_id"/>
- <column type="integer" name="content_type_id"/>
- <column type="integer" name="license_id"/>
-
- </table>
-
-</schema>
-
Modified: branches/versions/db/migrate/012_create_blobs.rb (3048 => 3049)
--- branches/versions/db/migrate/012_create_blobs.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/012_create_blobs.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -5,18 +5,18 @@
class CreateBlobs < ActiveRecord::Migration
def self.up
-# create_table :blobs do |t|
-# t.column :contributor_id, :integer
-# t.column :contributor_type, :string
-# t.column :local_name, :string
-# t.column :content_type, :string
-# t.column :data, :binary
-# t.column :created_at, :datetime
-# t.column :updated_at, :datetime
-# end
+ create_table :blobs do |t|
+ t.column :contributor_id, :integer
+ t.column :contributor_type, :string
+ t.column :local_name, :string
+ t.column :content_type, :string
+ t.column :data, :binary
+ t.column :created_at, :datetime
+ t.column :updated_at, :datetime
+ end
end
def self.down
-# drop_table :blobs
+ drop_table :blobs
end
end
Modified: branches/versions/db/migrate/029_modify_blobs.rb (3048 => 3049)
--- branches/versions/db/migrate/029_modify_blobs.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/029_modify_blobs.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -1,12 +1,12 @@
class ModifyBlobs < ActiveRecord::Migration
def self.up
-# add_column :blobs, :title, :string
-# add_column :blobs, :description, :text
+ add_column :blobs, :title, :string
+ add_column :blobs, :description, :text
end
def self.down
-# remove_column :blobs, :title
-# remove_column :blobs, :description
+ remove_column :blobs, :title
+ remove_column :blobs, :description
end
end
Modified: branches/versions/db/migrate/030_add_license_to_blobs.rb (3048 => 3049)
--- branches/versions/db/migrate/030_add_license_to_blobs.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/030_add_license_to_blobs.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -1,10 +1,10 @@
class AddLicenseToBlobs < ActiveRecord::Migration
def self.up
-# add_column :blobs, :license, :string, :limit => 10, :null => false, :default => "by-nd"
+ add_column :blobs, :license, :string, :limit => 10, :null => false, :default => "by-nd"
end
def self.down
-# remove_column :blobs, :license
+ remove_column :blobs, :license
end
end
Modified: branches/versions/db/migrate/031_rename_desc_to_body.rb (3048 => 3049)
--- branches/versions/db/migrate/031_rename_desc_to_body.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/031_rename_desc_to_body.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -1,12 +1,12 @@
class RenameDescToBody < ActiveRecord::Migration
def self.up
-# rename_column :blobs, :description, :body
-# add_column :blobs, :body_html, :text
+ rename_column :blobs, :description, :body
+ add_column :blobs, :body_html, :text
end
def self.down
-# rename_column :blobs, :body, :description
-# remove_column :blobs, :body_html
+ rename_column :blobs, :body, :description
+ remove_column :blobs, :body_html
end
end
Modified: branches/versions/db/migrate/033_increase_blob_size.rb (3048 => 3049)
--- branches/versions/db/migrate/033_increase_blob_size.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/033_increase_blob_size.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -1,16 +1,16 @@
class IncreaseBlobSize < ActiveRecord::Migration
def self.up
-# rename_column :blobs, :data, :temp
-# add_column :blobs, :data, :binary, :limit => 1073741824
-# execute 'UPDATE blobs SET data = ""
-# remove_column :blobs, :temp
+ rename_column :blobs, :data, :temp
+ add_column :blobs, :data, :binary, :limit => 1073741824
+ execute 'UPDATE blobs SET data = ""
+ remove_column :blobs, :temp
end
def self.down
-# rename_column :blobs, :data, :temp
-# add_column :blobs, :data, :binary
-# execute 'UPDATE blobs SET data = ""
-# remove_column :blobs, :temp
+ rename_column :blobs, :data, :temp
+ add_column :blobs, :data, :binary
+ execute 'UPDATE blobs SET data = ""
+ remove_column :blobs, :temp
end
end
Modified: branches/versions/db/migrate/053_modify_blobs_for_content_blobs.rb (3048 => 3049)
--- branches/versions/db/migrate/053_modify_blobs_for_content_blobs.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/053_modify_blobs_for_content_blobs.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -1,9 +1,9 @@
class ModifyBlobsForContentBlobs < ActiveRecord::Migration
def self.up
-# add_column :blobs, :content_blob_id, :integer
+ add_column :blobs, :content_blob_id, :integer
end
def self.down
-# remove_column :blobs, :content_blob_id
+ remove_column :blobs, :content_blob_id
end
end
Modified: branches/versions/db/migrate/054_move_blob_data_to_content_blobs.rb (3048 => 3049)
--- branches/versions/db/migrate/054_move_blob_data_to_content_blobs.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/054_move_blob_data_to_content_blobs.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -1,17 +1,17 @@
class MoveBlobDataToContentBlobs < ActiveRecord::Migration
def self.up
-# Blob.find(:all).each do |b|
-# b.content_blob = ContentBlob.new(:data ="" b.data)
-# b.save
-# end
+ Blob.find(:all).each do |b|
+ b.content_blob = ContentBlob.new(:data ="" b.data)
+ b.save
+ end
-# remove_column :blobs, :data
+ remove_column :blobs, :data
end
def self.down
-# add_column :blobs, :data, :binary, :limit => 1073741824
+ add_column :blobs, :data, :binary, :limit => 1073741824
-# execute 'UPDATE blobs,content_blobs SET blobs.data = "" WHERE blobs.content_blob_id = content_blobs.id'
+ execute 'UPDATE blobs,content_blobs SET blobs.data = "" WHERE blobs.content_blob_id = content_blobs.id'
end
end
Modified: branches/versions/db/migrate/076_create_content_types.rb (3048 => 3049)
--- branches/versions/db/migrate/076_create_content_types.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/076_create_content_types.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -17,7 +17,7 @@
# add_column :workflows, :content_type_id, :integer
# add_column :workflow_versions, :content_type_id, :integer
-# add_column :blobs, :content_type_id, :integer
+ add_column :blobs, :content_type_id, :integer
# Create ContentType records for workflows with processors
@@ -96,18 +96,18 @@
# remove_column :workflows, :content_type
# remove_column :workflow_versions, :content_type
-# remove_column :blobs, :content_type
+ remove_column :blobs, :content_type
end
def self.down
# add_column :workflows, :content_type, :string
# add_column :workflow_versions, :content_type, :string
-# add_column :blobs, :content_type, :string
+ add_column :blobs, :content_type, :string
# remove_column :workflows, :content_type_id
# remove_column :workflow_versions, :content_type_id
-# remove_column :blobs, :content_type_id
+ remove_column :blobs, :content_type_id
# drop_table :content_types
end
Modified: branches/versions/db/migrate/080_add_license_id_to_workflows_and_blobs.rb (3048 => 3049)
--- branches/versions/db/migrate/080_add_license_id_to_workflows_and_blobs.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/migrate/080_add_license_id_to_workflows_and_blobs.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -2,19 +2,19 @@
def self.up
#Need to rename columns so that license method and license field do not get confused
# rename_column :workflows, :license, :license_name
-# rename_column :blobs, :license, :license_name
+ rename_column :blobs, :license, :license_name
#
# add_column :workflows, :license_id, :integer, :default => nil
-# add_column :blobs, :license_id, :integer, :default => nil
+ add_column :blobs, :license_id, :integer, :default => nil
# Workflow.find(:all).each do |w|
# execute("UPDATE workflows SET license_id = #{License.find(:first,:conditions=>[ 'unique_name = ?', w.license_name ]).id } WHERE id = #{w.id}")
# end
-# Blob.find(:all).each do |b|
-# execute("UPDATE blobs SET license_id = #{License.find(:first,:conditions=>[ 'unique_name = ?', b.license_name ]).id } WHERE id = #{b.id}")
-# end
+ Blob.find(:all).each do |b|
+ execute("UPDATE blobs SET license_id = #{License.find(:first,:conditions=>[ 'unique_name = ?', b.license_name ]).id } WHERE id = #{b.id}")
+ end
# remove_column :workflows, :license_name
-# remove_column :blobs, :license_name
+ remove_column :blobs, :license_name
end
def self.down
@@ -22,16 +22,16 @@
# :limit => 10, :null => false,
# :default => "by-sa"
#
-# add_column :blobs, :license, :string,
-# :limit => 10, :null => false,
-# :default => "by-sa"
+ add_column :blobs, :license, :string,
+ :limit => 10, :null => false,
+ :default => "by-sa"
# Workflow.find(:all).each do |w|
# execute("UPDATE workflows SET license = '#{License.find(w.license_id).unique_name }' WHERE id = #{w.id}")
# end
-# Blob.find(:all).each do |b|
-# execute("UPDATE blobs SET license = '#{License.find(b.license_id).unique_name }' WHERE id = #{b.id}")
-# end
+ Blob.find(:all).each do |b|
+ execute("UPDATE blobs SET license = '#{License.find(b.license_id).unique_name }' WHERE id = #{b.id}")
+ end
# remove_column :workflows, :license_id
-# remove_column :blobs, :license_id
+ remove_column :blobs, :license_id
end
end
Added: branches/versions/db/migrate/096_create_blob_versions.rb (0 => 3049)
--- branches/versions/db/migrate/096_create_blob_versions.rb (rev 0)
+++ branches/versions/db/migrate/096_create_blob_versions.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -0,0 +1,35 @@
+# myExperiment: db/migrate/096_create_blob_versions.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class CreateBlobVersions < ActiveRecord::Migration
+
+ def self.up
+ create_table :blob_versions do |t|
+ t.integer "blob_id"
+ t.integer "version"
+ t.string "title"
+ t.text "body"
+ t.text "body_html"
+ t.integer "content_type_id"
+ t.integer "content_blob_id"
+ t.string "local_name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_column :blobs, :current_version, :integer
+
+ execute "UPDATE blobs SET current_version = 1"
+
+ execute "INSERT INTO blob_versions (blob_id, version, title, body, body_html, content_type_id, content_blob_id, local_name, created_at, updated_at) SELECT id, 1, title, body, body_html, content_type_id, content_blob_id, local_name, created_at, updated_at FROM blobs"
+ end
+
+ def self.down
+ remove_column :blobs, :current_version
+
+ drop_table :blob_versions
+ end
+end
+
Modified: branches/versions/db/schema.rb (3048 => 3049)
--- branches/versions/db/schema.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/db/schema.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 95) do
+ActiveRecord::Schema.define(:version => 96) do
create_table "activity_limits", :force => true do |t|
t.string "contributor_type", :null => false
@@ -45,6 +45,19 @@
t.text "schema"
end
+ create_table "blob_versions", :force => true do |t|
+ t.integer "blob_id"
+ t.integer "version"
+ t.string "title"
+ t.text "body"
+ t.text "body_html"
+ t.integer "content_type_id"
+ t.integer "content_blob_id"
+ t.string "local_name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "blobs", :force => true do |t|
t.integer "contributor_id"
t.string "contributor_type"
@@ -57,6 +70,7 @@
t.integer "content_blob_id"
t.integer "content_type_id"
t.integer "license_id"
+ t.integer "current_version"
end
create_table "blog_posts", :force => true do |t|
Modified: branches/versions/vendor/plugins/versioning/lib/versioning.rb (3048 => 3049)
--- branches/versions/vendor/plugins/versioning/lib/versioning.rb 2012-07-26 14:44:18 UTC (rev 3048)
+++ branches/versions/vendor/plugins/versioning/lib/versioning.rb 2012-07-27 15:23:41 UTC (rev 3049)
@@ -37,46 +37,55 @@
return "(latest)" if version_number == versions.last.version
return ""
end
+
+ def changed_versioned_attributes
+ versioned_attributes.select do |attr|
+ changes[attr.to_s] || (send(attr).respond_to?(:changed) && send(attr).changed?)
+ end
+ end
+
+ # If this is a new record or a versioned attribute has changed that is
+ # not marked as mutable, then this will be a new version.
+
+ def new_version?
+ new_record? || (changed_versioned_attributes - mutable_attributes).length > 0
+ end
end
before_save do |resource|
unless resource.inhibit_version_check
- # Create a new version if we need to. We need to do this if either this is
- # a new record or an attribute has changed that is version tracked.
+ if resource.new_version?
- new_version = resource.version_class.new
+ new_version = resource.version_class.new
- changed_attributes = resource.changes.keys.map do |attr| attr.to_sym end
+ resource.current_version = resource.current_version ? resource.current_version + 1 : 1
+ new_version[:version] = resource.current_version
- changed_versioned_attributes = versioned_attributes & changed_attributes
+ resource.versioned_attributes.each do |attr|
+ new_version.send("#{attr}=", resource.send(attr))
+ end
- if resource.new_record? || ((versioned_attributes - mutable_attributes) & changed_attributes).length > 0
+ resource.versions << new_version
- # If this is a new record or a versioned attribute has changed that is
- # not marked as mutable, then create a new version.
+ else
- resource.current_version = new_version[:version] = resource.current_version ? resource.current_version + 1 : 1
+ changed_attributes = resource.changed_versioned_attributes
+
+ if !changed_attributes.empty?
- versioned_attributes.each do |attr|
- new_version[attr] = resource[attr]
- end
+ # A new version wasn't created, but some attributes in the latest
+ # version need updating.
- resource.versions << new_version
+ version = resource.find_version(resource.current_version)
- elsif !changed_versioned_attributes.empty?
+ changed_attributes.each do |attr|
+ version[attr] = resource[attr]
+ end
- # A new version wasn't created, but some attributes in the latest
- # version need updating.
-
- version = resource.find_version(resource.current_version)
-
- changed_versioned_attributes.each do |attr|
- version[attr] = resource[attr]
+ version.save
end
-
- version.save
end
end
end