app/controllers/management/cms_controller.rb in imagine_cms-4.0.1 vs app/controllers/management/cms_controller.rb in imagine_cms-4.1.0

- old
+ new

@@ -216,11 +216,11 @@ existing_tags = @pg.tags.map(&:name) tags_to_delete = @pg.tags.all params[:tags].split(',').map(&:strip).reject(&:blank?).each do |t| if existing_tags.include?(t) # still in use, don't delete - tags_to_delete.reject! { |tag| tag.name == t } + tags_to_delete = tags_to_delete.reject { |tag| tag.name == t } else # doesn't exist, create @pg.tags.create(:name => t) end end @@ -239,11 +239,11 @@ if key =~ /^obj-(\w+?)-(.+?)$/ obj = @pg.objects.where(:name => $2, :obj_type => $1).first obj ||= @pg.objects.build(:name => $2, :obj_type => $1) obj.content = val obj.save - objects_to_delete.reject! { |obj| obj.name == $2 } + objects_to_delete = objects_to_delete.reject { |obj| obj.name == $2 } end end objects_to_delete.each { |t| t.destroy } # rescue Exception => e @@ -483,11 +483,11 @@ obj.content = val obj.save end old_objs.each do |obj| - unless @pg.objects.find(:all, :conditions => [ 'name = ? and cms_page_version = ?', obj.name, @pg.version]) + unless @pg.objects.where(name: obj.name, cms_page_version: @pg.version) obj = @pg.objects.build(:name => obj.name, :obj_type => obj.type, :content => obj.content) end end # update index for searching @@ -502,11 +502,11 @@ def insert_page_object_config @pg = CmsPage.find(params[:id]) load_page_objects @pg.revert_to(params[:version]) if params[:version] - @pg.objects.find(:all, :conditions => [ 'cms_page_version = ?', @pg.version]).each do |obj| + @pg.objects.where(cms_page_version: @pg.version).each do |obj| key = "obj-#{obj.obj_type.to_s}-#{obj.name}" @page_objects[key] = obj.content end name = params[:name] @@ -563,11 +563,11 @@ @pg = CmsPage.find(params[:id]) @version = params[:version].to_i # send email to request administrative review # find all users with email address set - User.find(:all).reject { |u| !u.active? || !u.can_manage_cms_publishing? || !u.cms_allowed_sections.blank? }.each do |u| + User.all.reject { |u| !u.active? || !u.can_manage_cms_publishing? || !u.cms_allowed_sections.blank? }.each do |u| next unless valid_email_address?(u.email_address) begin Mailer.deliver_cms_request_review(url_for(:controller => '/cms/content', :action => 'show', :content_path => []) + @pg.path, @pg.title, @version, u, @user, params[:change_description].to_s) rescue Exception => e logger.error(e) @@ -1528,19 +1528,24 @@ def upload_to_s3(filename, page, bucket = nil, prefix = nil) s3retries = 0 s3success = false if ImagineCmsConfig['amazon_s3'] && ImagineCmsConfig['amazon_s3']['enabled'] + s3 = Aws::S3::Client.new + bucket ||= ImagineCmsConfig['amazon_s3'][Rails.env]['image_bucket'] prefix ||= ImagineCmsConfig['amazon_s3']['image_prefix'] - # set options + metadata - options = ImagineCmsConfig['amazon_s3']['metadata'] - options[:access] = :public_read + params = {} + params[:bucket] = bucket + params[:key] = "#{prefix}/#{page.path.blank? ? 'index' : page.path}/#{File.basename(filename)}" + params[:body] = open(filename) + params[:acl] = 'public-read' + params[:metadata] = ImagineCmsConfig['amazon_s3']['metadata'] - while s3retries < 2 && !s3success - response = AWS::S3::S3Object.store("#{prefix}/#{page.path.blank? ? 'index' : page.path}/#{File.basename(filename)}", open(filename), bucket, options) - s3success = response.code == 200 + while !s3success && s3retries < 2 + response = s3.put_object(params) + s3success = response.successful? s3retries += 1 end File.unlink(filename) if s3success end