class Object
Public Instance Methods
detect_clean()
click to toggle source
# File lib/hem/tasks/magento1/patches.rb, line 16 def detect_clean status = shell('git status -z', :capture => true, :strip => false) status.split("\u0000").each do |line| match = line.match(/^([\s\S]{2})\s+(.*)$/) next if match.nil? if ![' ', '?'].include?($1[0]) || $2.start_with?(magento_path) raise Hem::UserError.new "Please remove all files from the git index, and stash all changes in '#{magento_path}' before continuing" end end end
detect_tools()
click to toggle source
# File lib/hem/tasks/magento1/patches.rb, line 73 def detect_tools use_vm = shell("which which", :exit_status => true) != 0 tools = ['patch', 'sed'] tools_command = tools.map {|tool| "which #{tool}"}.join " && " status = 0 unless use_vm status = shell(tools_command, :exit_status => true) use_vm = status != 0 end if use_vm status = run(tools_command, :exit_status => true) end if status != 0 raise Hem::UserError.new "Please make sure '#{tools.join(',')}' is installed on your host or VM before continuing" end use_vm end
detect_version()
click to toggle source
# File lib/hem/tasks/magento1/patches.rb, line 28 def detect_version config_dirty = false magento_version_file = "#{magento_path}/app/Mage.php" if Hem.project_config[:magento_edition].nil? magento_edition = nil if magento_version_file args = [ "php -r \"require '#{magento_version_file}'; echo Mage::getEdition();\""] magento_edition = run(*args, :capture => true).to_s.downcase end edition_options = ['community', 'enterprise', 'professional', 'go'] unless edition_options.include? magento_edition raise Hem::Error.new "Invalid Magento edition '#{magento_edition}' was found when calling Mage::getEdition(), skipping patches" end Hem.project_config[:magento_edition] = magento_edition config_dirty = true end if Hem.project_config[:magento_version].nil? magento_version = nil if magento_version_file args = [ "php -r \"require '#{magento_version_file}'; echo Mage::getVersion();\""] magento_version = run(*args, :capture => true) end version_regex = /^\d+(\.\d+){3}$/ unless version_regex.match(magento_version) raise Hem::Error.new "Invalid Magento version '#{magento_version}' was found when calling Mage::getVersion(), skipping patches" end Hem.project_config[:magento_version] = magento_version config_dirty = true end if config_dirty Hem::Config::File.save(Hem.project_config_file, Hem.project_config) end end
get_magento_patches(path)
click to toggle source
# File lib/hem/tasks/magento1/patches.rb, line 96 def get_magento_patches path patch_files = Dir.glob("#{path}/*.{sh,patch,diff}") patch_files.sort_by do |file| file.scan(/[^\d\.]+|[\d\.]+/).collect { |f| f.match(/\d+(\.\d+)?/) ? f.to_f : f } end end
magento_path()
click to toggle source
# File lib/hem/tasks/magento1/patches.rb, line 3 def magento_path unless @magento_path files = locate('app/Mage.php') unless files.length > 0 raise Hem::UserError.new "Could not find app/Mage.php in the git repository, this command should only be run for Magento projects" end /(?:(.*)\/)app\/Mage\.php/.match(files[0]) @magento_path = $1 end @magento_path end