Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Delete duplicator.rb

Damian Legawiec7f7e9cf9774a
diff --git a/spree/core/app/services/spree/themes/duplicator.rb b/spree/core/app/services/spree/themes/duplicator.rb
deleted file mode 100644
index 7cf8a53ffe..0000000000
--- a/spree/core/app/services/spree/themes/duplicator.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module Spree
- module Themes
- class Duplicator
- def initialize(theme)
- @theme = theme
- end
-
- def duplicate
- duplicated_theme = @theme.dup
- duplicated_theme.duplicating = true
- duplicated_theme.default = false
- duplicated_theme.ready = false
- duplicated_theme.name = generate_new_name(@theme.name)
- duplicated_theme.save!
-
- # We need to duplicate files, pages and sections in the background
- Spree::Themes::DuplicateComponentsJob.set(wait: 5.seconds).perform_later(@theme.id, duplicated_theme.id)
-
- duplicated_theme
- end
-
- protected
-
- def generate_new_name(name)
- depth_of_name = name.count('#')
- highest_number_for_each_depth = Spree::Theme.where('spree_themes.name LIKE ?', "%#{name}").
- pluck(:name).
- group_by { |theme_name| theme_name.count('#') }.
- transform_values do |names|
- # ['Copy #3 of Theme', 'Copy #2 of Theme', Copy #1 of Theme'] => '3'
- names.map{ |n| n.split.select { |s| s.starts_with?('#') }.first&.delete('#') }.max
- end
-
- next_usable_number = highest_number_for_each_depth[depth_of_name + 1].to_i + 1
-
- "Copy ##{next_usable_number} of #{name}"
- end
- end
- end
-end