-
Notifications
You must be signed in to change notification settings - Fork 3
/
upgrade-to-3.6.php
executable file
·157 lines (141 loc) · 4.82 KB
/
upgrade-to-3.6.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/php
<?php
require __DIR__.'/util/globrecursive.php';
$file = is_file('vkwf_branch') ? 'vkwf_branch' : 'kwf_branch';
if (!file_exists($file)) die("Execute this script in app root.\n");
if (trim(file_get_contents($file)) != '3.5') die("This script will update from 3.5, update to 3.5 first.\n");
file_put_contents($file, "3.6\n");
echo "Changed $file to 3.6\n";
function replaceFiles($files, $from, $to) {
foreach ($files as $f) {
$content = file_get_contents($f);
if (strpos($content, $from)) {
file_put_contents($f, str_replace($from, $to, $content));
echo "Change $f: $from -> $to\n";
}
}
}
function createTrlCacheFolder()
{
if (!is_dir('cache/trl')) {
mkdir('cache/trl');
file_put_contents('cache/trl/.gitignore', "*\n!.gitignore\n");
system("git add cache/trl/.gitignore");
echo "folder \"cache/trl\" created\n";
}
}
function createScssCacheFolder()
{
if (!is_dir('cache/scss')) {
mkdir('cache/scss');
file_put_contents('cache/scss/.gitignore', "*\n!.gitignore\n");
system("git add cache/scss/.gitignore");
echo "folder \"cache/scss\" created\n";
}
}
function updateErrorViews($files)
{
foreach ($files as $f) {
$content = file_get_contents($f);
$origContent = $content;
$content = preg_replace('#<\?=\s*trl#', '<'.'?=$this->data->trl', $content);
if ($origContent != $content) {
file_put_contents($f, $content);
echo "Change $f: update trl\n";
}
}
}
function checkFileForCropParameter($path)
{
$c = file_get_contents($path);
$parameterChanged = false;
$c = preg_replace_callback(
'#\'scale\'\s*=>\s*Kwf_Media_Image::SCALE_BESTFIT#s',
function($m) use (&$parameterChanged) {
$parameterChanged = true;
return '\'cover\' => false';
},
$c
);
$c = preg_replace_callback(
'#\'scale\'\s*=>\s*Kwf_Media_Image::SCALE_ORIGINAL#s',
function($m) use (&$parameterChanged) {
$parameterChanged = true;
return '\'cover\' => false';
},
$c
);
$c = preg_replace_callback(
'#\'scale\'\s*=>\s*Kwf_Media_Image::SCALE_CROP#s',
function($m) use (&$parameterChanged) {
$parameterChanged = true;
return '\'cover\' => true';
},
$c
);
$c = preg_replace_callback(
'#\'scale\'\s*=>\s*Kwf_Media_Image::SCALE_DEFORM#s',
function($m) use (&$parameterChanged) {
$parameterChanged = true;
return '\'cover\' => true';
},
$c
);
if ($parameterChanged) {
file_put_contents($path, $c);
}
}
function recursiveCropImageOptionsReplace($directory)
{
if (!is_dir($directory)) {
return false;
}
$files = scandir($directory);
foreach ($files as $file) {
$path = $directory.'/'.$file;
if ($file != '.' && $file != '..' && !recursiveCropImageOptionsReplace($path)) {
$info = pathinfo($path, PATHINFO_EXTENSION);
if ($info == 'php' || $info == 'yml' ) {
checkFileForCropParameter($path);
}
}
}
}
function updateIncludePath()
{
$defaultPaths = array(
'app', 'controllers', 'models', 'components', 'themes'
);
$addConfig = "";
$c = file_get_contents('bootstrap.php');
preg_match_all('#\$include_path\s*\.=\s*PATH_SEPARATOR\s*\.\s*\'([^\']+)\';'."\n?#", $c, $m);
$c = str_replace('$include_path = get_include_path();'."\n", '', $c);
$c = str_replace('set_include_path($include_path);'."\n", '', $c);
foreach ($m[0] as $k=>$i) {
$c = str_replace($i, '', $c);
$path = $m[1][$k];
if (!in_array($path, $defaultPaths)) {
$addConfig = "includepath.web".ucfirst($path)." = $path\n";
}
}
file_put_contents('bootstrap.php', $c);
echo "removed include paths from bootstrap.php\n";
if ($addConfig) {
$c = file_get_contents('config.ini');
$c = str_replace("[production]\n", "[production]\n".$addConfig, $c);
file_put_contents('config.ini', $c);
echo "added custom include paths to config.ini\n";
}
}
createTrlCacheFolder();
createScssCacheFolder();
$files = glob_recursive('Events.php');
replaceFiles($files, 'Kwf_Component_Event_ComponentClass_PartialsChanged', 'Kwf_Component_Event_ComponentClass_AllPartialChanged');
$files = glob_recursive('Component.php');
$files = array_merge($files, glob_recursive('config.ini'));
replaceFiles($files, 'Kwc_Basic_Headlines_Component', 'Kwc_Legacy_Headlines_Component');
replaceFiles($files, 'Kwc_Basic_Headline_Component', 'Kwc_Legacy_Headline_Component');
updateErrorViews(glob('views/error*.tpl'));
echo "Update Image-Parameter\n";
recursiveCropImageOptionsReplace('components');
updateIncludePath();