hem-tasks-magento1 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 537f914a28dd20a0a140d802acf97e631fdd22c0
4
+ data.tar.gz: 2e45dba213a5eb0fdce228f70555b8a9ae8b0d3b
5
+ SHA512:
6
+ metadata.gz: 1dd8533fee5e99558db0a5fa39553c7f8b74d3c344e31478e0fd57dc2056491f5cc5568a24f87a3bee659abaab6a7b5705de0cb7194f362ab604411ebef0d966
7
+ data.tar.gz: 43ca6a5ec901d152d4eae2e175b3a2437d7dd5432f5d8ea255019c962a5aef9f82d42e22933761b3f05aa2e5aba13775478959bc2db5c0fd58a1729254e65781
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hem-tasks-magento1.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Hem::Tasks::Magento1
2
+
3
+ Contains tasks for [Hem](https://github.com/inviqa.com/) to provide functionality
4
+ for Magento 1.* projects
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Hemfile:
9
+
10
+ ```ruby
11
+ plugins
12
+ gem 'hem-tasks-magento1'
13
+ end
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Run the following to see usage:
19
+
20
+ ```bash
21
+ hem magento
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bundle install` to install dependencies.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/inviqa/hem-tasks-magento1. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'hem/tasks/magento1/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "hem-tasks-magento1"
9
+ spec.version = Hem::Tasks::Magento1::VERSION
10
+ spec.authors = ["Andy Thompson"]
11
+ spec.email = ["athompson@inviqa.com"]
12
+
13
+ spec.summary = %q{Magento 1 tasks for Hem}
14
+ spec.description = %q{Magento 1 tasks for Hem}
15
+ spec.homepage = ""
16
+ spec.licenses = ["MIT"]
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,281 @@
1
+ namespace :tools do
2
+ desc "Fetches the n98-magerun utility"
3
+ task :n98magerun do
4
+ FileUtils.mkdir_p "bin"
5
+ run_command '"wget" --no-check-certificate "https://raw.github.com/netz98/n98-magerun/master/n98-magerun.phar" -O bin/n98-magerun.phar'
6
+ FileUtils.chmod 0755, "bin/n98-magerun.phar"
7
+ end
8
+ end
9
+
10
+ desc "Magento related tasks"
11
+ namespace :magento do
12
+
13
+ desc "Patch tasks"
14
+ namespace :patches do
15
+ def magento_path
16
+ unless @magento_path
17
+ files = locate('*app/Mage.php')
18
+ unless files.length > 0
19
+ raise Hem::UserError.new "Could not find app/Mage.php in the git repository, this command should only be run for Magento projects"
20
+ end
21
+
22
+ /(?:(.*)\/)app\/Mage\.php/.match(files[0])
23
+ @magento_path = $1
24
+ end
25
+ @magento_path
26
+ end
27
+
28
+ def detect_clean
29
+ status = shell('git status -z', :capture => true, :strip => false)
30
+ status.split("\u0000").each do |line|
31
+ match = line.match(/^([\s\S]{2})\s+(.*)$/)
32
+ next if match.nil?
33
+
34
+ if ![' ', '?'].include?($1[0]) || $2.start_with?(magento_path)
35
+ raise Hem::UserError.new "Please remove all files from the git index, and stash all changes in '#{magento_path}' before continuing"
36
+ end
37
+ end
38
+ end
39
+
40
+ def detect_version
41
+ config_dirty = false
42
+ magento_version_file = "#{magento_path}/app/Mage.php"
43
+
44
+ if Hem.project_config[:magento_edition].nil?
45
+ magento_edition = nil
46
+ if magento_version_file
47
+ args = [ "php -r \"require '#{magento_version_file}'; echo Mage::getEdition();\""]
48
+
49
+ magento_edition = run_command(*args, :capture => true).to_s.downcase
50
+ end
51
+
52
+ edition_options = ['community', 'enterprise', 'professional', 'go']
53
+
54
+ unless edition_options.include? magento_edition
55
+ raise Hem::Error.new "Invalid Magento edition '#{magento_edition}' was found when calling Mage::getEdition(), skipping patches"
56
+ end
57
+
58
+ Hem.project_config[:magento_edition] = magento_edition
59
+ config_dirty = true
60
+ end
61
+
62
+ if Hem.project_config[:magento_version].nil?
63
+ magento_version = nil
64
+ if magento_version_file
65
+ args = [ "php -r \"require '#{magento_version_file}'; echo Mage::getVersion();\""]
66
+
67
+ magento_version = run_command(*args, :capture => true)
68
+ end
69
+
70
+ version_regex = /^\d+(\.\d+){3}$/
71
+
72
+ unless version_regex.match(magento_version)
73
+ raise Hem::Error.new "Invalid Magento version '#{magento_version}' was found when calling Mage::getVersion(), skipping patches"
74
+ end
75
+
76
+ Hem.project_config[:magento_version] = magento_version
77
+ config_dirty = true
78
+ end
79
+
80
+ if config_dirty
81
+ Hem::Config::File.save(Hem.project_config_file, Hem.project_config)
82
+ end
83
+ end
84
+
85
+ def detect_tools
86
+ use_vm = shell("which which", :exit_status => true) != 0
87
+
88
+ tools = ['patch', 'sed']
89
+ tools_command = tools.map {|tool| "which #{tool}"}.join " && "
90
+ status = 0
91
+
92
+ unless use_vm
93
+ status = shell(tools_command, :exit_status => true)
94
+ use_vm = status != 0
95
+ end
96
+
97
+ if use_vm
98
+ status = run_command(tools_command, :exit_status => true)
99
+ end
100
+
101
+ if status != 0
102
+ raise Hem::UserError.new "Please make sure '#{tools.join(',')}' is installed on your host or VM before continuing"
103
+ end
104
+
105
+ use_vm
106
+ end
107
+
108
+ desc "Apply patches to Magento"
109
+ task "apply" do
110
+ detect_clean
111
+ detect_version
112
+
113
+ config = Hem.project_config
114
+
115
+ sync = Hem::Lib::S3::Sync.new(Hem.aws_credentials)
116
+
117
+ patches_path = "#{Hem.project_path}/tools/patches"
118
+ incoming_path = "#{patches_path}/incoming"
119
+
120
+ Hem.ui.success("Downloading Magento #{config[:magento_edition].capitalize} #{config[:magento_version]} patches")
121
+ changes = sync.sync(
122
+ "s3://inviqa-assets-magento/#{config[:magento_edition]}/patches/#{config[:magento_version]}/",
123
+ "#{incoming_path}/",
124
+ :delete => false
125
+ )
126
+ Hem.ui.separator
127
+
128
+ use_vm = false
129
+ use_vm = detect_tools if Dir.glob("#{incoming_path}/*.sh").length > 0
130
+
131
+ patch_files = Dir.glob("#{incoming_path}/*.{sh,patch,diff}")
132
+
133
+ Hem.ui.success("#{patch_files.length} new patches found")
134
+
135
+ Hem.ui.separator
136
+
137
+ patch_files.each do |file|
138
+ filename = File.basename(file)
139
+ base_filename = File.basename(filename, File.extname(filename))
140
+
141
+ if File.exist?("#{patches_path}/#{filename}")
142
+ Hem.ui.debug("Patch #{filename} has already been applied, so skipping it")
143
+
144
+ File.delete file
145
+ next
146
+ end
147
+
148
+ if File.exist?("#{patches_path}/#{base_filename}.skip")
149
+ File.delete file
150
+ next
151
+ end
152
+
153
+ Hem.ui.success("Applying patch #{filename}")
154
+
155
+ yaml_file = File.join(File.dirname(file), base_filename + ".yaml")
156
+
157
+ metadata = {
158
+ 'commit_message' => "Apply Magento patch #{filename}"
159
+ }
160
+ if File.exist?(yaml_file)
161
+ metadata = Hem::Config::File.load(yaml_file)
162
+ end
163
+
164
+ Hem.ui.info(metadata['description']) unless metadata['description'].nil?
165
+
166
+ patch_options = %w( yes never skip )
167
+ answer = Hem.ui.ask_choice('Do you want to apply this patch?', patch_options)
168
+
169
+ if answer == 'skip'
170
+ next
171
+ end
172
+
173
+ if answer == 'never'
174
+ File.delete file
175
+ File.write("#{patches_path}/#{base_filename}.skip", '')
176
+
177
+ shell "git add '#{patches_path}/#{base_filename}.skip'"
178
+ shell "git commit -m 'Add a skip file for patch #{filename}'"
179
+ next
180
+ end
181
+
182
+ if /\.sh$/.match(file)
183
+ File.rename file, "#{magento_path}/#{filename}"
184
+ file = "#{magento_path}/#{filename}"
185
+ if use_vm
186
+ run_command "cd #{magento_path} && sh #{filename}", :realtime => true, :indent => 2
187
+ else
188
+ shell "cd #{magento_path} && sh #{filename}", :realtime => true, :indent => 2
189
+ end
190
+ else
191
+ shell "git apply --directory #{magento_path} #{file}"
192
+ end
193
+ File.rename file, "#{patches_path}/#{filename}"
194
+ shell "git add #{magento_path}"
195
+ shell "git add #{patches_path}/#{filename}"
196
+
197
+ if File.exist?(yaml_file)
198
+ yaml_filename = File.basename(yaml_file)
199
+ File.rename yaml_file, "#{patches_path}/#{yaml_filename}"
200
+ shell "git add #{patches_path}/#{yaml_filename}"
201
+ end
202
+ shell "git commit -m #{metadata['commit_message'].shellescape}"
203
+
204
+ Hem.ui.separator
205
+ end
206
+
207
+ Hem.ui.success("Finished applying #{patch_files.length} patches")
208
+ end
209
+ end
210
+
211
+ desc "Setup script tasks"
212
+ namespace :'setup-scripts' do
213
+ desc "Run magento setup scripts"
214
+ task :run => ['tools:n98magerun'] do
215
+ Hem.ui.success "Running setup scripts"
216
+ run_command("bin/n98-magerun.phar cache:clean config", :realtime => true, :indent => 2)
217
+ run_command("bin/n98-magerun.phar sys:setup:incremental -n", :realtime => true, :indent => 2)
218
+ Hem.ui.separator
219
+ end
220
+ end
221
+
222
+ desc "Cache tasks"
223
+ namespace :cache do
224
+ desc "Clear cache"
225
+ task :clear => ['tools:n98magerun'] do
226
+ Hem.ui.success "Clearing magento cache"
227
+ run_command("bin/n98-magerun.phar cache:flush", :realtime => true, :indent => 2)
228
+ Hem.ui.separator
229
+ end
230
+ end
231
+
232
+ desc "Configuration related tasks"
233
+ namespace :config do
234
+ desc "Configure magento base URLs"
235
+ task :'configure-urls' => ['tools:n98magerun'] do
236
+ Hem.ui.success "Configuring magento base urls"
237
+ domain = Hem.project_config.hostname
238
+ run_command("bin/n98-magerun.phar config:set web/unsecure/base_url 'http://#{domain}/'", :realtime => true, :indent => 2)
239
+ run_command("bin/n98-magerun.phar config:set web/secure/base_url 'https://#{domain}/'", :realtime => true, :indent => 2)
240
+ Hem.ui.separator
241
+ end
242
+
243
+ desc "Enable magento errors"
244
+ task :'enable-errors' do
245
+ error_config = File.join(Hem.project_path, 'public/errors/local.xml')
246
+
247
+ FileUtils.cp(
248
+ error_config + ".sample",
249
+ error_config
250
+ ) unless File.exists? error_config
251
+ end
252
+
253
+ desc "Create admin user"
254
+ task :'create-admin-user' do
255
+ initialized = run_command("bin/n98-magerun.phar admin:user:list | grep admin", :exit_status => true) == 0
256
+ unless initialized
257
+ Hem.ui.success "Creating admin user"
258
+ run_command("bin/n98-magerun.phar admin:user:create admin '' admin admin admin", :realtime => true, :indent => 2)
259
+ Hem.ui.separator
260
+ end
261
+ end
262
+
263
+ desc "Enable rewrites"
264
+ task :'enable-rewrites' do
265
+ Hem.ui.success "Enabling rewrites"
266
+ run_command("bin/n98-magerun.phar config:set web/seo/use_rewrites 1", :realtime => true, :indent => 2)
267
+ Hem.ui.separator
268
+ end
269
+ end
270
+
271
+ desc "Initializes magento specifics on the virtual machine after a fresh build"
272
+ task :'initialize-vm' => [
273
+ 'magento:config:enable-errors',
274
+ 'tools:n98magerun',
275
+ 'magento:setup-scripts:run',
276
+ 'magento:config:configure-urls',
277
+ 'magento:config:create-admin-user',
278
+ 'magento:config:enable-rewrites',
279
+ 'magento:cache:clear'
280
+ ]
281
+ end
@@ -0,0 +1,7 @@
1
+ module Hem
2
+ module Tasks
3
+ module Magento1
4
+ VERSION = '1.0.0'
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hem-tasks-magento1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andy Thompson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Magento 1 tasks for Hem
42
+ email:
43
+ - athompson@inviqa.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - hem-tasks-magento1.gemspec
53
+ - lib/hem/tasks/magento1.rb
54
+ - lib/hem/tasks/magento1/version.rb
55
+ homepage: ''
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.8
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Magento 1 tasks for Hem
79
+ test_files: []