Class: Mxrb::Frontend::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/frontend/migrator.rb

Overview

Updates installed pluggable-widget schemas and legacy layout-grid weights directly in an MPR. Package XML is the source of truth; no Studio Pro or mx invocation is involved. rubocop:disable Metrics/AbcSize, Metrics/BlockLength, Metrics/ClassLength rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength rubocop:disable Metrics/ParameterLists, Metrics/PerceivedComplexity rubocop:disable Lint/NonLocalExitFromIterator

Constant Summary collapse

SUPPORTED_MAJORS =
[10, 11].freeze
STANDARD_TYPE_KEYS =
%w[
  $ID $Type HelpUrl ObjectType OfflineCapable StudioCategory StudioProCategory
  SupportedPlatform WidgetDescription WidgetId WidgetName WidgetNeedsEntityContext
  WidgetPluginWidget
].freeze
STANDARD_OBJECT_KEYS =
%w[$ID $Type Properties TypePointer].freeze
WEIGHT_KEYS =

TabletWeight/PhoneWeight use -1 as a valid responsive inheritance sentinel. CE0535 concerns only the desktop Weight total.

%w[Weight].freeze
AUDITED_DATA_GRID_PACKAGE_SHA256 =
'8eabd99ef927b918dbb2bd5f05cf12dc14026b37e496bc1b0569c34369a0b713'
ACTIVE_VALUE_FIELDS =
{
  'Action' => %w[Action Microflow Nanoflow],
  'Association' => %w[EntityRef SourceVariable],
  'Attribute' => %w[AttributeRef SourceVariable],
  'DataSource' => %w[DataSource XPathConstraint],
  'Expression' => %w[Expression SourceVariable], 'Icon' => %w[Icon],
  'Image' => %w[Image], 'Object' => %w[Objects], 'Selection' => %w[Selection],
  'TextTemplate' => %w[TextTemplate TranslatableValue], 'Widgets' => %w[Widgets]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Migrator

Returns a new instance of Migrator.



94
95
96
97
98
# File 'lib/mxrb/frontend/migrator.rb', line 94

def initialize(path)
  @path = File.expand_path(path)
  @root = File.dirname(@path)
  @definitions = {}
end

Class Method Details

.plan(path) ⇒ Object



92
# File 'lib/mxrb/frontend/migrator.rb', line 92

def self.plan(path) = new(path).plan

Instance Method Details

#planObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/mxrb/frontend/migrator.rb', line 100

def plan
  mpr = IO::MprFile.open(@path, readonly: true)
  version = mpr.mendix_version.to_s
  issues = []
  unless SUPPORTED_MAJORS.include?(version.to_i)
    issues << MigrationIssue.new('', '', :unsupported_version,
                                 "Mendix #{version.inspect}; supported majors are 10 and 11")
    return MigrationPlan.new(path: @path, version:, changes: [], issues:)
  end
  validate_widget_packages!(issues)

  changes = mpr.all_units.filter_map do |unit|
    before = mpr.parse_contents(unit)
    after = deep_copy(before)
    counts = { widgets: 0, layout_rows: 0, design_properties: 0 }
    migrate_value!(after, unit.fetch('UnitID'), '$', issues, counts)
    next if after == before

    MigrationChange.new(
      unit.fetch('UnitID'), unit.fetch('ContentsHash'), before, after,
      counts.fetch(:widgets), counts.fetch(:layout_rows), counts.fetch(:design_properties)
    )
  end
  MigrationPlan.new(path: @path, version:, changes:, issues:)
ensure
  mpr&.close
end