myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [3046] branches/versions/app/controllers/workflow


From: noreply
Subject: [myexperiment-hackers] [3046] branches/versions/app/controllers/workflows_controller.rb: simplified update_version for workflows
Date: Wed, 25 Jul 2012 15:28:45 +0000 (UTC)

Revision
3046
Author
dgc
Date
2012-07-25 15:28:44 +0000 (Wed, 25 Jul 2012)

Log Message

simplified update_version for workflows

Modified Paths

Diff

Modified: branches/versions/app/controllers/workflows_controller.rb (3045 => 3046)


--- branches/versions/app/controllers/workflows_controller.rb	2012-07-25 13:58:48 UTC (rev 3045)
+++ branches/versions/app/controllers/workflows_controller.rb	2012-07-25 15:28:44 UTC (rev 3046)
@@ -547,43 +547,40 @@
   # PUT /workflows/1;update_version
   def update_version
 
-    wv = @workflow.find_version(params[:version])
+    success = false
 
-    workflow_title = @workflow.title
-    
     if params[:version]
-      # Update differently based on whether a new preview image has been specified or not:
-      # (But only set image if platform is not windows).
-      if params[:workflow][:preview].blank? || params[:workflow][:preview].size == 0
-        success = wv.update_attributes(:title => params[:workflow][:title], 
-                                       :body => params[:workflow][:body],
-                                       :last_edited_by => current_user.id) 
-      else
-        logger.debug("Preview image provided. Attempting to set the version's preview image.")
-        
-        # Disable updating image on windows due to issues to do with file locking, that prevent file_column from working sometimes.
-        #
-        # The dependency on file_column has been removed, but this code remains
-        # disabled on Windows until it is confirmed as working.
-        if RUBY_PLATFORM =~ /mswin32/
-          success = false
-        else
-          success = wv.update_attributes(:title => params[:workflow][:title], 
-                                         :body => params[:workflow][:body], 
-                                         :image => params[:workflow][:preview].read,
-                                         :last_edited_by => current_user.id)
-        end
-      end
-    else
-      success = false
+
+      original_title = @workflow.title
+      version        = @workflow.find_version(params[:version])
+      do_preview     = !params[:workflow][:preview].blank? && params[:workflow][:preview].size > 0
+      
+      attributes_to_update = {
+        :title          => params[:workflow][:title], 
+        :body           => params[:workflow][:body],
+        :last_edited_by => current_user.id
+      }
+
+      # only set the preview to update if one was provided
+
+      attributes_to_update[:image] = params[:workflow][:preview] if do_preview
+
+      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 #{params[:version]}: \"#{workflow_title}\" has been updated."
+        flash[:notice] = "Workflow version #{version.version}: \"#{original_title}\" has been updated."
         format.html { redirect_to(workflow_url(@workflow) + "?version=#{params[:version]}") }
       else
-        flash[:error] = "Failed to update Workflow version."
+        flash[:error] = "Failed to update Workflow."
         if params[:version]
           format.html { render :action ="" :edit_version }
         else

reply via email to

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