This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v5preupdate.php
162 lines (118 loc) · 5.21 KB
/
v5preupdate.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
158
159
160
161
162
<?php
include_once "core/module_system/bootstrap.php";
class_carrier::getInstance();
echo "<pre>\n";
echo "\n";
echo "<b>Kajona V5 pre update sequence</b>\n";
echo "\n";
echo "Welcome to the V5 update helper.\n";
echo "\n";
echo "This script backs up your v4 template and creates a new template pack out of it.\n";
echo "\n";
echo "\n";
if(version_compare(class_module_system_module::getModuleByName("system")->getStrVersion(), "4.7.1", "<=")) {
echo "<b>Error</b>\n";
echo "Your Kajona-Installation is currently on version ".class_module_system_module::getModuleByName("system")->getStrVersion()."\n";
echo "You need at least version 4.7.1 to upgrate to 5.0\n";
echo "Aborting!\n";
die();
}
V5PreUpdate::main();
echo "\n";
echo "\n";
echo "Update succeeded, please update the packages and database now\n";
echo "</pre>\n";
class V5PreUpdate {
public static function main()
{
$objUpdate = new V5PreUpdate();
$objUpdate->backupTemplatepack();
$objUpdate->moveProjectFiles();
}
private function moveProjectFiles()
{
echo "Updating /project redefinitions...\n";
$arrFiles = array(
"/project/system/config/config.php" => "/project/module_system/system/config/config.php",
"/project/portal/global_includes.php" => "/project/module_pages/portal/global_includes.php",
"/project/admin/scripts/ckeditor/config_kajona_standard.js" => "/project/module_system/admin/scripts/ckeditor/config_kajona_standard.js",
);
foreach($arrFiles as $strSource => $strTarget) {
if(is_file(__DIR__.$strSource)) {
$this->safeCopyFile(__DIR__.$strSource, __DIR__.$strTarget);
unlink(__DIR__.$strSource);
}
}
}
private function backupTemplatepack()
{
echo "Searching for currently active template pack\n";
$strName = class_module_system_setting::getConfigValue("_packagemanager_defaulttemplate_");
if($strName == "default") {
echo "Creating a new template-pack based on the default pack\n";
$strName = "kajonav4_backup";
$this->copyRecursive(__DIR__."/templates/default", __DIR__."/templates/".$strName);
echo "Setting ".$strName." as the default template pack\n";
$objSetting = class_module_system_setting::getConfigByName("_packagemanager_defaulttemplate_");
$objSetting->setStrValue($strName);
$objSetting->updateObjectToDb();
echo "Syncing template packs\n";
class_module_packagemanager_template::syncTemplatepacks();
/** @var class_module_packagemanager_template $objOneTemplate */
foreach(class_module_packagemanager_template::getObjectList() as $objOneTemplate) {
if($objOneTemplate->getStrName() == $strName) {
$objOneTemplate->setIntRecordStatus(1);
$objOneTemplate->updateObjectToDb();
}
}
}
echo "Adding un-modified templates to your custom template\n";
//fetch templates
$arrEntries = class_resourceloader::getInstance()->getFolderContent("/templates/default/tpl", array(), true);
foreach($arrEntries as $strPath => $strEntry) {
if(is_dir(__DIR__.$strPath)) {
$arrFiles = scandir(__DIR__.$strPath."/");
foreach($arrFiles as $strOneFile) {
if(in_array($strOneFile, array(".", ".."))) {
continue;
}
$this->safeCopyFile(__DIR__.$strPath."/".$strOneFile, __DIR__."/templates/".$strName."/tpl/".$strEntry."/".$strOneFile);
}
}
}
}
private function safeCopyFile($strSource, $strTarget) {
echo " Copying ".$strSource ." to ".$strTarget."\n";
if(!is_file($strTarget)) {
if(!is_dir(dirname($strTarget))) {
mkdir(dirname($strTarget), 0777, true);
}
if(copy($strSource, $strTarget)) {
echo " <span style='color: green'>copying ".$strSource ." to ".$strTarget." succeeded</span>";
}
else {
echo " <span style='color: red'>copying ".$strSource ." to ".$strTarget." failed</span>";
}
}
}
private function copyRecursive($strSourceDir, $strTargetDir) {
$arrEntries = scandir($strSourceDir);
foreach($arrEntries as $strOneEntry) {
if($strOneEntry == "." || $strOneEntry == "..") {
continue;
}
if(is_file($strSourceDir."/".$strOneEntry) && !is_file($strTargetDir."/".$strOneEntry)) {
if(!is_dir($strTargetDir)) {
mkdir($strTargetDir, 0777, true);
}
copy($strSourceDir."/".$strOneEntry, $strTargetDir."/".$strOneEntry);
}
elseif(is_dir($strSourceDir."/".$strOneEntry)) {
if(!is_dir($strTargetDir."/".$strOneEntry)) {
mkdir($strTargetDir."/".$strOneEntry, 0777, true);
}
$this->copyRecursive($strSourceDir."/".$strOneEntry, $strTargetDir."/".$strOneEntry);
}
}
}
}