-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupgrade-to-5.2.php
executable file
·133 lines (114 loc) · 4.17 KB
/
upgrade-to-5.2.php
1
2
3
4
5
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
127
128
129
130
131
132
#!/usr/bin/php
<?php
require __DIR__.'/util/globrecursive.php';
if (is_file('vkwf_branch') || is_file('kwf_branch')) {
die("This script will update from 5.1, update to 5.1 first.\n");
}
if (!is_file('composer.json')) {
die("composer.json not found.\n");
}
$changed = false;
$c = json_decode(file_get_contents('composer.json'));
foreach ($c->require as $packageName=>$packageVersion) {
if (substr($packageVersion, 0, 4) == "5.1.") {
$c->require->$packageName = '5.2.x-dev';
$changed = true;
}
}
if (!$changed) {
die("This script will update from 5.1, update to 5.1 first.\n");
}
file_put_contents('composer.json', json_encode($c, (defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0) + (defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0) ));
$files = array_merge(
glob_recursive('*.js')
);
foreach ($files as $file) {
$c = file_get_contents($file);
$origC = $c;
$c = str_replace('KWF_BASE_URL+', '', $c);
if ($c != $origC) {
file_put_contents($file, $c);
}
}
$files = array_merge(
glob_recursive('*.jsx')
);
foreach ($files as $file) {
$c = file_get_contents($file);
$origC = $c;
$c = str_replace('${KWF_BASE_URL}', '', $c);
if ($c != $origC) {
file_put_contents($file, $c);
}
}
// mark RTE styles as required
$files = array_merge(
glob_recursive('Web.scss')
);
foreach ($files as $file) {
$c = file_get_contents($file);
$origC = $c;
$c = preg_replace("#}\s(\/\*)\s(.+)\s\*\/$#m", "} /*! $2 */", $c);
if ($c != $origC) {
file_put_contents($file, $c);
}
}
// change IntegratorTemplates to repo-version (legacy-version for compatibility)
$integratorTemplateUsed = false;
foreach (glob_recursive('*.php') as $file) {
$c = file_get_contents($file);
$origC = $c;
$c = str_replace("Kwc_Advanced_IntegratorTemplate_", 'KwcIntegratorTemplate_Kwc_Advanced_IntegratorTemplateLegacy_', $c);
if ($c != $origC) {
echo "renamed to KwcIntegratorTemplate_Kwc_Advanced_IntegratorTemplate_Component: $file\n";
file_put_contents($file, $c);
$integratorTemplateUsed = true;
}
}
if ($integratorTemplateUsed) {
$c = json_decode(file_get_contents('composer.json'));
$c->require->{'koala-framework/kwc-integrator-template'} = "1.0.x-dev";
echo "Added koala-framework/kwc-integrator-template to require composer.json\n";
file_put_contents('composer.json', json_encode($c, (defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0) + (defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0)));
}
// add kwf-shop if necessary
$addShopPackage = false;
foreach (glob_recursive('*.php') as $file) {
$c = file_get_contents($file);
$origC = $c;
$c = str_replace("extends Kwc_Shop_", 'extends KwcShop_Kwc_Shop_', $c);
$c = str_replace("'Kwc_Shop_", '\'KwcShop_Kwc_Shop_', $c);
$c = str_replace("\"Kwc_Shop_", '"KwcShop_Kwc_Shop_', $c);
$c = str_replace("(Kwc_Shop_", '(KwcShop_Kwc_Shop_', $c);
$c = str_replace("= Kwc_Shop_", '= KwcShop_Kwc_Shop_', $c);
$c = str_replace("new Kwc_Shop_", 'new KwcShop_Kwc_Shop_', $c);
if ($c != $origC) {
echo "renamed to KwcShop_Kwc_Shop_: $file\n";
file_put_contents($file, $c);
$addShopPackage = true;
}
}
$files = array_merge(
glob_recursive('*.twig'),
glob_recursive('*.tpl')
);
foreach ($files as $file) {
$c = file_get_contents($file);
$origC = $c;
foreach (array("Shop") as $dir) {
$c = str_replace("vendor/koala-framework/koala-framework/Kwc/{$dir}", "vendor/koala-framework/kwc-shop/KwcShop/Kwc/Shop", $c);
}
if ($c != $origC) {
echo "renamed to kwc-shop vendor path: $file\n";
file_put_contents($file, $c);
$addShopPackage = true;
}
}
if ($addShopPackage) {
$c = json_decode(file_get_contents('composer.json'));
$c->require->{'koala-framework/kwc-shop'} = "1.0.x-dev";
echo "Added koala-framework/kwc-shop to require composer.json\n";
file_put_contents('composer.json', json_encode($c, (defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0) + (defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0) ));
}
echo "\n";
echo "run now 'composer update' to update dependencies\n";