myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3048] branches/versions: various improvements to


From: noreply
Subject: [myexperiment-hackers] [3048] branches/versions: various improvements to versioning
Date: Thu, 26 Jul 2012 14:44:18 +0000 (UTC)

Revision
3048
Author
dgc
Date
2012-07-26 14:44:18 +0000 (Thu, 26 Jul 2012)

Log Message

various improvements to versioning

Modified Paths

Diff

Modified: branches/versions/app/controllers/workflows_controller.rb (3047 => 3048)


--- branches/versions/app/controllers/workflows_controller.rb	2012-07-26 08:06:27 UTC (rev 3047)
+++ branches/versions/app/controllers/workflows_controller.rb	2012-07-26 14:44:18 UTC (rev 3048)
@@ -447,11 +447,10 @@
       # TODO: wrap this in a transaction!
       @workflow.content_blob = ContentBlob.create(:data ="" file.read)
       @workflow.preview = nil
+      @workflow[:revision_comments] = params[:new_workflow][:rev_comments]
 
       if @workflow.save
 
-        @workflow.versions.last.update_attribute(:revision_comments, params[:new_workflow][:rev_comments])
-
         # Extract workflow metadata using a Workflow object that includes the
         # newly created version.
 
@@ -568,13 +567,6 @@
       success = version.update_attributes(attributes_to_update)
     end
 
-    # ensure that the preview image gets saved and the cache is cleared for that image
-
-    if success && version.preview && version.preview.image_blob && version.preview.image_blob.changed?
-      version.preview.image_blob.save 
-      version.preview.clear_cache
-    end
-    
     respond_to do |format|
       if success
         flash[:notice] = "Workflow version #{version.version}: \"#{original_title}\" has been updated."

Modified: branches/versions/app/models/preview.rb (3047 => 3048)


--- branches/versions/app/models/preview.rb	2012-07-26 08:06:27 UTC (rev 3047)
+++ branches/versions/app/models/preview.rb	2012-07-26 14:44:18 UTC (rev 3048)
@@ -7,13 +7,17 @@
 
   PREFIX = "tmp/previews"
 
+  after_save :clear_cache
+
   belongs_to :image_blob, :class_name  => "ContentBlob",
                           :foreign_key => :image_blob_id,
-                          :dependent   => :destroy
+                          :dependent   => :destroy,
+                          :autosave    => true
 
   belongs_to :svg_blob,   :class_name  => "ContentBlob",
                           :foreign_key => :svg_blob_id,
-                          :dependent   => :destroy
+                          :dependent   => :destroy,
+                          :autosave    => true
 
   def file_name(type)
     "#{PREFIX}/#{id}/#{type}"

Modified: branches/versions/app/models/workflow.rb (3047 => 3048)


--- branches/versions/app/models/workflow.rb	2012-07-26 08:06:27 UTC (rev 3047)
+++ branches/versions/app/models/workflow.rb	2012-07-26 14:44:18 UTC (rev 3048)
@@ -50,14 +50,14 @@
 
   has_versions :workflow_versions,
   
-    :attributes => [ :title, :unique_name, :body, :body_html, :content_blob_id,
-                     :file_ext, :last_edited_by, :content_type_id ],
+    :attributes => [ :contributor, :title, :unique_name, :body, :body_html,
+                     :content_blob_id, :file_ext, :last_edited_by,
+                     :content_type_id, :preview_id, :image, :svg,
+                     :revision_comments ],
 
-    :mutable => [ :title, :unique_name, :body, :body_html, :file_ext,
-                  :last_edited_by, :content_type_id ],
+    :mutable => [ :contributor, :title, :unique_name, :body, :body_html,
+                  :file_ext, :last_edited_by, :content_type_id, :image, :svg ]
 
-    :ignore_columns => [ :preview_id, :image, :svg ]
-
   acts_as_solr(:fields => [ :title, :body, :tag_list, :contributor_name, :kind, :get_all_search_terms ],
                :boost => "rank",
                :include => [ :comments ]) if Conf.solr_enable

Modified: branches/versions/lib/previews.rb (3047 => 3048)


--- branches/versions/lib/previews.rb	2012-07-26 08:06:27 UTC (rev 3047)
+++ branches/versions/lib/previews.rb	2012-07-26 14:44:18 UTC (rev 3048)
@@ -5,7 +5,7 @@
 
     self.class_eval do
 
-      belongs_to :preview, :dependent => :destroy
+      belongs_to :preview, :dependent => :destroy, :autosave => true
 
       def image
         preview.image_blob.data if preview && preview.image_blob
@@ -34,29 +34,6 @@
 
         self.preview.svg_blob.data = x
       end
-
-      after_save { |ob|
-      
-        p = ob.preview
-
-        if p
-
-          ib = p.image_blob
-          sb = p.svg_blob
-
-          if ib && ib.data_changed?
-            ib.save
-            ob.preview.clear_cache
-          end
-
-          if sb && sb.data_changed?
-            sb.save
-            ob.preview.clear_cache
-          end
-          
-          p.save
-        end
-      }
     end
   end
 end

Modified: branches/versions/lib/rest.rb (3047 => 3048)


--- branches/versions/lib/rest.rb	2012-07-26 08:06:27 UTC (rev 3047)
+++ branches/versions/lib/rest.rb	2012-07-26 14:44:18 UTC (rev 3048)
@@ -1090,12 +1090,15 @@
       return rest_response(500, :reason => "Unable to extract metadata")
     end
 
-    success = if (action == 'create' and opts[:query]['id'])
-      ob.save_as_new_version(revision_comment)
-    else
-      ob.save
+    new_version = action == 'create' && opts[:query]['id']
+
+    if new_version
+      ob.preview = nil
+      ob[:revision_comments] = revision_comment
     end
 
+    success = ob.save
+
     return rest_response(400, :object => ob) unless success
 
     # Elements to update if we're not dealing with a workflow version

Modified: branches/versions/vendor/plugins/versioning/lib/versioning.rb (3047 => 3048)


--- branches/versions/vendor/plugins/versioning/lib/versioning.rb	2012-07-26 08:06:27 UTC (rev 3047)
+++ branches/versions/vendor/plugins/versioning/lib/versioning.rb	2012-07-26 14:44:18 UTC (rev 3048)
@@ -9,7 +9,7 @@
 
     def has_versions(version_class, opts = {})
 
-      cattr_accessor :version_class, :versioned_attributes, :mutable_attributes, :versioned_resource_column, :ignore_columns
+      cattr_accessor :version_class, :versioned_attributes, :mutable_attributes, :versioned_resource_column
 
       attr_accessor :inhibit_version_check
 
@@ -17,13 +17,12 @@
       self.versioned_attributes      = opts[:attributes]                || []
       self.mutable_attributes        = opts[:mutable]                   || []
       self.versioned_resource_column = opts[:versioned_resource_column] || "#{self.table_name.singularize}_id"
-      self.ignore_columns            = [:id, :version, :created_at, :updated_at, self.versioned_resource_column.to_sym]
 
       inhibit_version_check = false
 
       class_eval do
 
-        has_many :versions, :class_name => self.version_class.to_s
+        has_many :versions, :class_name => self.version_class.name
 
         def find_version(v)
           match = self.version_class.find(:first, :conditions => ["#{self.versioned_resource_column} = ? AND version = ?", id, v])
@@ -49,8 +48,6 @@
 
           new_version = resource.version_class.new
 
-          versioned_attributes = new_version.attribute_names.map do |name| name.to_sym end - ignore_columns
-
           changed_attributes = resource.changes.keys.map do |attr| attr.to_sym end
 
           changed_versioned_attributes = versioned_attributes & changed_attributes
@@ -112,7 +109,6 @@
           blocking_attributes  = immutable_attributes & changed_attributes
 
           blocking_attributes.each do |attr|
-puts "ADDING ERROR"
             version.errors.add(attr, 'is immutable')
           end
         end

reply via email to

[Prev in Thread] Current Thread [Next in Thread]