Module: Maruto::MagentoVersion

Defined in:
lib/maruto/magento_version.rb

Class Method Summary collapse

Class Method Details

.read_magento_versionObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/maruto/magento_version.rb', line 6

def self.read_magento_version()
  mage = 'app/Mage.php'
  return nil unless File.exist? mage
  File.open mage do |file|
    # newer magento version have a getVersionInfo function
    newer = file.find { |line| line =~ /getVersionInfo/ }
    file.rewind
    if newer
      # newer Magento version
      function = read_function(file, 'getVersionInfo')
      match    = function.match(/return array\(.*'major'.*'(\d+)'.*'minor'.*'(\d+)'.*'revision'.*'(\d+)'.*'patch'.*'(\d+)'.*'stability'.*'number'.*\)/)
      version    = []
      version[0] = match[1].to_i unless match[1].nil?
      version[1] = match[2].to_i unless match[2].nil?
      version[2] = match[3].to_i unless match[3].nil?
      version[3] = match[4].to_i unless match[4].nil?
      return version
    else
      # older Magento version
      function = read_function(file, 'getVersion')
      match    = function.match(/return '(\d+)\.(\d+)\.?(\d+)?\.?(\d+)?';/)
      version    = []
      version[0] = match[1].to_i unless match[1].nil?
      version[1] = match[2].to_i unless match[2].nil?
      version[2] = match[3].to_i unless match[3].nil?
      version[3] = match[4].to_i unless match[4].nil?
      return version
    end
  end
end