|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once __DIR__ . '/../vendor/autoload.php'; |
| 5 | + |
| 6 | +ini_set('display_errors', 1); |
| 7 | +ini_set('display_startup_errors', 1); |
| 8 | +error_reporting(E_ALL); |
| 9 | + |
| 10 | +set_error_handler(function ($level, $msg) { |
| 11 | + echo "Error: {$msg}"; |
| 12 | + exit(1); |
| 13 | +}); |
| 14 | + |
| 15 | +/** |
| 16 | + * Between openapi-generator v7.8.0 and v7.12.0 a change was made to the way |
| 17 | + * a few generators create constant names from values. The original way was |
| 18 | + * actually broken. For example "change-field-visibility" would generate a |
| 19 | + * constant name of "TYPE_FIELD_VISIBILITY", dropping the "change" part. |
| 20 | + * |
| 21 | + * The fix now generates the correct name, "TYPE_CHANGE_FIELD_VISIBILITY". |
| 22 | + * However, the fix also gets rid of the previous (incorrect) constant names, |
| 23 | + * making the fix a BC break. |
| 24 | + * |
| 25 | + * This simple script just adds the old constant names back, alongside the new |
| 26 | + * ones. |
| 27 | + */ |
| 28 | +class CopyConstants |
| 29 | +{ |
| 30 | + public function run(): void |
| 31 | + { |
| 32 | + $file = __DIR__ . '/../model/subFormFieldRuleAction.ts'; |
| 33 | + $contents = file_get_contents($file); |
| 34 | + |
| 35 | + $constant_1 = ' ChangeFieldVisibility = "change-field-visibility",'; |
| 36 | + $replace_1 = implode("\n", [ |
| 37 | + $constant_1, |
| 38 | + ' FieldVisibility = "change-field-visibility",', |
| 39 | + ]); |
| 40 | + |
| 41 | + $constant_2 = ' ChangeGroupVisibility = "change-group-visibility",'; |
| 42 | + $replace_2 = implode("\n", [ |
| 43 | + $constant_2, |
| 44 | + ' GroupVisibility = "change-group-visibility",', |
| 45 | + ]); |
| 46 | + |
| 47 | + $contents = str_replace( |
| 48 | + $constant_1, |
| 49 | + $replace_1, |
| 50 | + $contents, |
| 51 | + ); |
| 52 | + |
| 53 | + $contents = str_replace( |
| 54 | + $constant_2, |
| 55 | + $replace_2, |
| 56 | + $contents, |
| 57 | + ); |
| 58 | + |
| 59 | + file_put_contents($file, $contents); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +$copier = new CopyConstants(); |
| 64 | +$copier->run(); |
0 commit comments