-
Notifications
You must be signed in to change notification settings - Fork 3
/
upgrade-to-3.5.php
executable file
·71 lines (60 loc) · 2.47 KB
/
upgrade-to-3.5.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
#!/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.4') die("This script will update from 3.4, update to 3.4 first.\n");
file_put_contents($file, "3.5\n");
echo "Changed $file to 3.5\n";
function updateAclMenuUrls()
{
$c = file_get_contents('app/Acl.php');
$c = preg_replace_callback(
'#(new Kwf_Acl_Resource_MenuUrl\\(\'([^\']+)\',(.*?)),\s*\'(/(admin|kwf|vkwf)[^\']+)\'(\s*\)\s*(,\s*\'[^\']+\'\)?);)#s',
function($m) {
if ('/'.str_replace('_', '/', $m[2]) == $m[4]) {
return $m[1].$m[6];
} else {
return $m[0];
}
},
$c
);
file_put_contents('app/Acl.php', $c);
echo "updated app/Acl.php to set url only where required\n";
}
function updateHtaccess()
{
$c = file_get_contents('.htaccess');
$c = str_replace('RewriteRule ^(.*)$ /bootstrap.php [L]', 'RewriteRule ^(.*)$ bootstrap.php [L]', $c);
file_put_contents('.htaccess', $c);
echo "updated .htaccess to support running in subfolder\n";
}
function updateBootstrap()
{
$c = file_get_contents('bootstrap.php');
$c = str_replace("Kwf_Assets_Loader::load();\n", '', $c);
if (file_exists('vkwf_branch')) {
$r = "if (file_exists('include_path')) {\n";
$r .= " \$path = str_replace('%vkwf_branch%', trim(file_get_contents('vkwf_branch')), trim(file_get_contents('include_path')));\n";
$r .= "} else {\n";
$r .= " \$path = dirname(__FILE__).'/vkwf-lib';\n";
$r .= "}\n";
$c = str_replace($r, '', $c);
$c = str_replace("require_once \$path.'/Vkwf/SetupPoi.php';\n", "require_once 'vkwf-lib/Vkwf/SetupPoi.php';\n", $c);
$c = str_replace("require_once \$path.'/Vkwf/Setup.php';\n", "require_once 'vkwf-lib/Vkwf/Setup.php';\n", $c);
if (!file_exists('vkwf-lib')) {
symlink(trim(file_get_contents('include_path')), 'vkwf-lib');
unlink('include_path');
}
if (!file_exists('kwf-lib')) {
symlink(trim(file_get_contents('vkwf-lib/include_path')), 'kwf-lib');
unlink('vkwf-lib/include_path');
}
}
file_put_contents('bootstrap.php', $c);
echo "updated bootstrap.php to remove assets loader call which is not required anymore\n";
}
updateAclMenuUrls();
updateHtaccess();
updateBootstrap();