<commit_before>if defined? Spree::Admin::ProductsController
  class Spree::Admin::SubscriptionLineItemsController < Spree::StoreController
    rescue_from ActiveRecord::RecordNotFound, :with => :render_404
    helper "spree/subscriptions"

    def destroy
      @subscription = Spree::Subscription.where(:id => params[:subscription_id]).first
      @subscription.line_items.select{|li| li.id = params[:id]}.first.update_column(:subscription_id, nil)
      @subscription.suspend if Spree::LineItem.where(:subscription_id => @subscription.id).count == 0
      redirect_to url_for([:edit, :admin, @subscription])
    end
  
    def update
      @subscription = Spree::Subscription.where(:id => params[:subscription_id]).first
      original_line_item = @subscription.line_items.select{|li| li.id = params[:id]}.first
      if original_line_item.try(:parts) && original_line_item.part_line_items.present?
        new_line_item = Spree::LineItem.new(original_line_item.attributes.merge({ :id => nil, :updated_at => nil, :created_at => nil , :quantity => params[:line_item][:quantity]})) 
      else
        new_line_item_attributes = original_line_item.attributes.merge({ :id => nil, :updated_at => nil, :created_at => nil}, :quantity => params[:line_item][:quantity])
        new_line_item_attributes[:variant_id] = params[:line_item][:variant_id] if params[:line_item][:variant_id].present?
        new_line_item = Spree::LineItem.new(new_line_item_attributes)
        new_line_item
      end
      new_line_item.order = nil
      new_line_item.order_id = nil
      
      begin
        Spree::LineItem.skip_callback(:create, :after, :update_tax_charge)
        Spree::LineItem.skip_callback(:save, :after, :update_inventory)
        Spree::LineItem.skip_callback(:save, :after, :update_adjustments)
        new_line_item.save(validate: false)
        if original_line_item.try(:parts) && original_line_item.part_line_items.present?
          populate_part_line_items(new_line_item, new_line_item.variant.product.assemblies_parts,  new_line_item.variant.product.assemblies_parts.first.id => params[:line_item][:variant_id])
          new_line_item.save(validate: false)
        end
      ensure
        Spree::LineItem.set_callback(:create, :after, :update_tax_charge)
        Spree::LineItem.set_callback(:save, :after, :update_inventory)
        Spree::LineItem.set_callback(:save, :after, :update_adjustments)
      end
    
      original_line_item.update_column(:subscription_id, nil)
      redirect_to url_for([:edit, :admin, @subscription])
    end
    <commit_msg>fix closing bracket in wrong place<commit_after>if defined? Spree::Admin::ProductsController
  class Spree::Admin::SubscriptionLineItemsController < Spree::StoreController
    rescue_from ActiveRecord::RecordNotFound, :with => :render_404
    helper "spree/subscriptions"

    def destroy
      @subscription = Spree::Subscription.where(:id => params[:subscription_id]).first
      @subscription.line_items.select{|li| li.id = params[:id]}.first.update_column(:subscription_id, nil)
      @subscription.suspend if Spree::LineItem.where(:subscription_id => @subscription.id).count == 0
      redirect_to url_for([:edit, :admin, @subscription])
    end
  
    def update
      @subscription = Spree::Subscription.where(:id => params[:subscription_id]).first
      original_line_item = @subscription.line_items.select{|li| li.id = params[:id]}.first
      if original_line_item.try(:parts) && original_line_item.part_line_items.present?
        new_line_item = Spree::LineItem.new(original_line_item.attributes.merge({ :id => nil, :updated_at => nil, :created_at => nil , :quantity => params[:line_item][:quantity]})) 
      else
        new_line_item_attributes = original_line_item.attributes.merge({ :id => nil, :updated_at => nil, :created_at => nil, :quantity => params[:line_item][:quantity]})
        new_line_item_attributes[:variant_id] = params[:line_item][:variant_id] if params[:line_item][:variant_id].present?
        new_line_item = Spree::LineItem.new(new_line_item_attributes)
        new_line_item
      end
      new_line_item.order = nil
      new_line_item.order_id = nil
      
      begin
        Spree::LineItem.skip_callback(:create, :after, :update_tax_charge)
        Spree::LineItem.skip_callback(:save, :after, :update_inventory)
        Spree::LineItem.skip_callback(:save, :after, :update_adjustments)
        new_line_item.save(validate: false)
        if original_line_item.try(:parts) && original_line_item.part_line_items.present?
          populate_part_line_items(new_line_item, new_line_item.variant.product.assemblies_parts,  new_line_item.variant.product.assemblies_parts.first.id => params[:line_item][:variant_id])
          new_line_item.save(validate: false)
        end
      ensure
        Spree::LineItem.set_callback(:create, :after, :update_tax_charge)
        Spree::LineItem.set_callback(:save, :after, :update_inventory)
        Spree::LineItem.set_callback(:save, :after, :update_adjustments)
      end
    
      original_line_item.update_column(:subscription_id, nil)
      redirect_to url_for([:edit, :admin, @subscription])
    end
    
{'fraction_non_alphanumeric': 0.12327970536925761, 'fraction_numerical': 0.0015506881178522969, 'mean_word_length': 4.443037974683544, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3435800', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1608, 'n_words': 237}