1 | <?php |
||
13 | class Installer { |
||
14 | const MAIN_CONFIG_STUB = /** @lang JSON */ |
||
15 | <<<CONFIG |
||
16 | { |
||
17 | //Domain of main mirror |
||
18 | "domain" : "@domain", |
||
19 | //Base timezone |
||
20 | "timezone" : "@timezone", |
||
21 | //Settings of main DB |
||
22 | "db_host" : "@db_host", |
||
23 | "db_type" : "@db_type", |
||
24 | "db_name" : "@db_name", |
||
25 | "db_user" : "@db_user", |
||
26 | "db_password" : "@db_password", |
||
27 | "db_prefix" : "@db_prefix", |
||
28 | //Settings of main Storage |
||
29 | "storage_type" : "Local", |
||
30 | "storage_url" : "", |
||
31 | "storage_host" : "localhost", |
||
32 | "storage_user" : "", |
||
33 | "storage_password" : "", |
||
34 | //Base language |
||
35 | "language" : "@language", |
||
36 | //Cache engine |
||
37 | "cache_engine" : "FileSystem", |
||
38 | //Settings of Memcached cache engine |
||
39 | "memcache_host" : "127.0.0.1", |
||
40 | "memcache_port" : "11211", |
||
41 | //Any length |
||
42 | "public_key" : "@public_key" |
||
43 | } |
||
44 | |||
45 | CONFIG; |
||
46 | /** |
||
47 | * @param string $source |
||
48 | * @param string $target |
||
49 | * @param string $site_name |
||
50 | * @param string $url |
||
51 | * @param string $timezone |
||
52 | * @param string $db_host |
||
53 | * @param string $db_engine |
||
54 | * @param string $db_name |
||
55 | * @param string $db_user |
||
56 | * @param string $db_password |
||
57 | * @param string $db_prefix |
||
58 | * @param string $language |
||
59 | * @param string $admin_email |
||
60 | * @param string $admin_password |
||
61 | * @param int $mode |
||
62 | * |
||
63 | * @throws RuntimeException |
||
64 | */ |
||
65 | 4 | public static function install ( |
|
115 | /** |
||
116 | * @param string $source |
||
117 | * @param string $target |
||
118 | * @param string $db_engine |
||
119 | * |
||
120 | * @throws RuntimeException |
||
121 | */ |
||
122 | 4 | protected static function pre_installation_checks ($source, $target, $db_engine) { |
|
130 | /** |
||
131 | * @param string $source |
||
132 | * |
||
133 | * @return array[] |
||
134 | */ |
||
135 | 4 | protected static function initialize_filesystem ($source) { |
|
136 | 4 | $file_index_map = json_decode(file_get_contents("$source/fs_installer.json"), true); |
|
137 | 4 | require_once "$source/fs/".$file_index_map['core/thirdparty/upf.php']; |
|
138 | 4 | require_once "$source/fs/".$file_index_map['core/functions.php']; |
|
139 | // Remove default autoloader, since we have special autoloader suitable for operating inside installer where default will fail hard |
||
140 | 4 | spl_autoload_unregister(array_reverse(spl_autoload_functions())[0]); |
|
141 | /** |
||
142 | * Special autoloader for installer |
||
143 | */ |
||
144 | 4 | spl_autoload_register( |
|
145 | 4 | function ($class) use ($file_index_map, $source) { |
|
146 | 4 | $prepared_class_name = ltrim($class, '\\'); |
|
147 | 4 | if (strpos($prepared_class_name, 'cs\\') === 0) { |
|
148 | 4 | $prepared_class_name = substr($prepared_class_name, 3); |
|
149 | } |
||
150 | 4 | $prepared_class_name = explode('\\', $prepared_class_name); |
|
151 | 4 | $namespace = count($prepared_class_name) > 1 ? implode('/', array_slice($prepared_class_name, 0, -1)) : ''; |
|
152 | 4 | $class_name = array_pop($prepared_class_name); |
|
153 | /** |
||
154 | * Try to load classes from different places. If not found in one place - try in another. |
||
155 | */ |
||
156 | if ( |
||
157 | 4 | strlen($file = @$file_index_map[str_replace('//', '/', "core/classes/$namespace/$class_name.php")]) || //Core classes |
|
158 | 4 | strlen($file = @$file_index_map[str_replace('//', '/', "core/thirdparty/$namespace/$class_name.php")]) || //Third party classes |
|
159 | 4 | strlen($file = @$file_index_map[str_replace('//', '/', "core/traits/$namespace/$class_name.php")]) || //Core traits |
|
160 | 4 | strlen($file = @$file_index_map[str_replace('//', '/', "core/engines/$namespace/$class_name.php")]) || //Core engines |
|
161 | 4 | strlen($file = @$file_index_map[str_replace('//', '/', "$namespace/$class_name.php")]) //Classes in modules |
|
162 | ) { |
||
163 | 4 | require_once "$source/fs/$file"; |
|
164 | 4 | return true; |
|
165 | } |
||
166 | return false; |
||
167 | 4 | } |
|
168 | ); |
||
169 | 4 | return $file_index_map; |
|
170 | } |
||
171 | /** |
||
172 | * @param array[] $file_index_map |
||
173 | * @param string $source |
||
174 | * @param string $target |
||
175 | * |
||
176 | * @throws RuntimeException |
||
177 | */ |
||
178 | 4 | protected static function extract ($file_index_map, $source, $target) { |
|
179 | /** |
||
180 | * Extracting of engine's files |
||
181 | */ |
||
182 | 4 | foreach ($file_index_map as $file_path => $file_index) { |
|
183 | 4 | $dir = dirname("$target/$file_path"); |
|
184 | 4 | if (!@mkdir($dir, 0770, true) && !is_dir($dir)) { |
|
185 | throw new RuntimeException("Can't extract system files from the archive, creating directory $dir failed! Installation aborted."); |
||
186 | } |
||
187 | 4 | if (!copy("$source/fs/$file_index", "$target/$file_path")) { |
|
188 | 4 | throw new RuntimeException("Can't extract system files from the archive, creating file $target/$file_path failed! Installation aborted."); |
|
189 | } |
||
190 | } |
||
191 | 4 | file_put_json("$target/core/fs.json", array_keys(file_get_json("$source/fs.json"))); |
|
192 | /** |
||
193 | * Make CLI executable |
||
194 | */ |
||
195 | 4 | chmod("$target/cli", 0770); |
|
196 | 4 | } |
|
197 | /** |
||
198 | * @param string $target |
||
199 | * @param string $domain |
||
200 | * @param string $timezone |
||
201 | * @param string $db_host |
||
202 | * @param string $db_engine |
||
203 | * @param string $db_name |
||
204 | * @param string $db_user |
||
205 | * @param string $db_password |
||
206 | * @param string $db_prefix |
||
207 | * @param string $language |
||
208 | * @param string $public_key |
||
209 | * |
||
210 | * @throws RuntimeException |
||
211 | */ |
||
212 | 4 | protected static function initialize_core_config ( |
|
236 | /** |
||
237 | * @param DB\_Abstract $cdb |
||
238 | * @param string $source |
||
239 | * @param string $db_engine |
||
240 | * |
||
241 | * @throws RuntimeException |
||
242 | */ |
||
243 | 4 | protected static function initialize_db_structure ($cdb, $source, $db_engine) { |
|
252 | /** |
||
253 | * @param DB\_Abstract $cdb |
||
254 | * @param string $source |
||
255 | * @param string $site_name |
||
256 | * @param string $url |
||
257 | * @param string $admin_email |
||
258 | * @param string $language |
||
259 | * @param string $domain |
||
260 | * @param string $timezone |
||
261 | * @param int $mode |
||
262 | * |
||
263 | * @throws RuntimeException |
||
264 | */ |
||
265 | 4 | protected static function initialize_system_config ($cdb, $source, $site_name, $url, $admin_email, $language, $domain, $timezone, $mode) { |
|
350 | /** |
||
351 | * @param DB\_Abstract $cdb |
||
352 | * @param string $admin_email |
||
353 | * @param string $admin_password |
||
354 | * @param string $public_key |
||
355 | * |
||
356 | * @throws RuntimeException |
||
357 | */ |
||
358 | 4 | protected static function create_root_administrator ($cdb, $admin_email, $admin_password, $public_key) { |
|
380 | } |
||
381 |