This repository was 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
Expand file tree
/
Copy pathupgrade.php
More file actions
188 lines (141 loc) · 5.73 KB
/
upgrade.php
File metadata and controls
188 lines (141 loc) · 5.73 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
class KajonaUpgrade
{
public function main()
{
if (!$this->checkPhpVersion()) {
return;
}
if (!is_dir(__DIR__."/core")) {
echo "/core directory not found, aborting\n";
}
//check some permissions
if (!$this->checkPermissions()) {
return;
}
//download each phar and move to core
foreach ($this->getPharList() as $strOnePhar) {
$this->updatePhar($strOnePhar);
}
//create / call installer
if (!$this->createInstallerFile()) {
echo "Failed to create installer file, please create manually and call the installer\n";
}
echo "Download succeeded, please continue with the installer\n";
echo "<a href='installer.php?step=install'>Open Installer</a>\n";
}
private function updatePhar($strPhar)
{
echo "Updating phar <b>".$strPhar."</b>\n";
//fetch the local version
if (is_file("phar://".__DIR__."/core/".$strPhar."/metadata.xml")) {
$objMedatadata = new SimpleXMLElement(file_get_contents("phar://".__DIR__."/core/".$strPhar."/metadata.xml"));
$strModule = $objMedatadata->title;
$strVersion = $objMedatadata->version;
echo " Local version: {$strModule}, V{$strVersion}\n";
//fetch the remote version
$strRemote = file_get_contents("https://www.kajona.de/xml.php?module=packageserver&action=list&protocolversion=5&title=".urlencode($strModule));
if (empty($strRemote)) {
echo " Failed to load remote version\n";
return;
}
$arrRemote = json_decode($strRemote, true);
if(isset($arrRemote["numberOfTotalItems"]) && isset($arrRemote["numberOfTotalItems"]) == 1) {
$strRemoteVersion = $arrRemote["items"][0]["version"];
$strSystemid = $arrRemote["items"][0]["systemid"];
echo " Remote version: V{$strRemoteVersion}\n";
if(version_compare($strVersion, $strRemoteVersion, "<")) {
echo " Downloading new phar module\n";
ob_flush();
flush();
file_put_contents(__DIR__."/project/temp/".$strPhar, file_get_contents("https://www.kajona.de/download.php?systemid=".$strSystemid));
if(is_file(__DIR__."/project/temp/".$strPhar)) {
//get filesize
$intBytes = filesize(__DIR__."/project/temp/".$strPhar);
$intSize = number_format($intBytes / 1024 / 1024, 2);
echo " Downloaded {$intSize}MB, moving new phar to /core replacing old version\n";
rename(__DIR__."/project/temp/".$strPhar, __DIR__."/core/".$strPhar);
} else {
echo " Download failed\n";
}
}
else {
echo " Skipping, no new version found\n";
}
}
}
else {
echo " Skipping, no valid Kajona phar\n";
}
echo "\n";
ob_flush();
flush();
}
private function getPharList()
{
$arrContent = scandir(__DIR__."/core");
$arrContent = array_filter($arrContent, function ($strFilename) {
return strpos($strFilename, ".phar") !== false;
});
return $arrContent;
}
private function checkPermissions()
{
echo "Checking write permissions on selected files and folders\n\n";
if (!is_file(__DIR__."/installer.php") && !is_writable(__DIR__)) {
echo " Directory ".__DIR__." is not writable, aborting!\n";
return false;
}
if (!is_writable(__DIR__."/project/temp")) {
echo " Directory ".__DIR__."/project/temp is no writable, aborting!\n";
return false;
}
$bitAllPharsWritable = true;
foreach ($this->getPharList() as $strOnePhar) {
if (!is_writable(__DIR__."/core/".$strOnePhar)) {
$bitAllPharsWritable = false;
echo "Phar ".__DIR__."/core/".$strOnePhar." not writable, aborting\n";
}
}
return $bitAllPharsWritable;
}
private function checkPhpVersion()
{
if (version_compare(phpversion(), "7.0", "<")) {
echo "At least php version 7.0 is required, currently available: ".phpversion().PHP_EOL."Aborting".PHP_EOL;
return false;
}
return true;
}
private function createInstallerFile()
{
if (!is_file(__DIR__."/installer.php")) {
$strInstaller = <<<PHP
<?php
/*"******************************************************************************************************
* (c) 2007-2016 by Kajona, www.kajona.de *
* Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt *
********************************************************************************************************/
if(is_dir("./core/module_system/")) {
require_once './core/module_system/bootstrap.php';
}
else {
require_once 'phar://'.__DIR__.'/core/module_system.phar/bootstrap.php';
}
if(is_dir("./core/module_installer/")) {
require_once './core/module_installer/installer.php';
}
else {
require_once 'phar://'.__DIR__.'/core/module_installer.phar/installer.php';
}
PHP;
return file_put_contents(__DIR__."/installer.php", $strInstaller);
}
return true;
}
}
echo "<pre>";
echo "\n\n<b>Kajona upgrade helper</b>\n\n";
$objUpdater = new KajonaUpgrade();
$objUpdater->main();
echo "</pre>";