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_driver" : "@db_driver", |
||
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_driver" : "Local", |
||
30 | "storage_url" : "", |
||
31 | "storage_host" : "localhost", |
||
32 | "storage_user" : "", |
||
33 | "storage_password" : "", |
||
34 | //Base language |
||
35 | "language" : "@language", |
||
36 | //Cache driver |
||
37 | "cache_driver" : "FileSystem", |
||
38 | //Settings of Memcached cache driver |
||
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_driver |
||
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 ( |
|
66 | $source, |
||
67 | $target, |
||
68 | $site_name, |
||
69 | $url, |
||
70 | $timezone, |
||
71 | $db_host, |
||
72 | $db_driver, |
||
73 | $db_name, |
||
74 | $db_user, |
||
75 | $db_password, |
||
76 | $db_prefix, |
||
77 | $language, |
||
78 | $admin_email, |
||
79 | $admin_password, |
||
80 | $mode |
||
81 | ) { |
||
82 | 4 | static::pre_installation_checks($source, $target, $db_driver); |
|
83 | 4 | $file_index_map = static::initialize_filesystem($source); |
|
84 | 4 | static::extract($file_index_map, $source, $target); |
|
85 | 4 | $domain = explode('/', $url)[2]; |
|
86 | 4 | $public_key = hash('sha512', random_bytes(1000)); |
|
87 | 4 | static::initialize_core_config( |
|
88 | 4 | $target, |
|
89 | 4 | $domain, |
|
90 | 4 | $timezone, |
|
91 | 4 | $db_host, |
|
92 | 4 | $db_driver, |
|
93 | 4 | $db_name, |
|
94 | 4 | $db_user, |
|
95 | 4 | $db_password, |
|
96 | 4 | $db_prefix, |
|
97 | 4 | $language, |
|
98 | 4 | $public_key |
|
99 | ); |
||
100 | /** |
||
101 | * @var \cs\DB\_Abstract $cdb |
||
102 | */ |
||
103 | 4 | $cdb = "cs\\DB\\$db_driver"; |
|
104 | 4 | $cdb = new $cdb($db_name, $db_user, $db_password, $db_host, $db_prefix); |
|
105 | 4 | if (!is_object($cdb) || !$cdb->connected()) { |
|
106 | throw new RuntimeException("Can't connect to database! Installation aborted."); |
||
107 | } |
||
108 | 4 | static::initialize_db_structure($cdb, $source, $db_driver); |
|
109 | 4 | static::initialize_system_config($cdb, $source, $site_name, $url, $admin_email, $language, $domain, $timezone, $mode); |
|
110 | 4 | static::create_root_administrator($cdb, $admin_email, $admin_password, $public_key); |
|
111 | 4 | unset($cdb); |
|
112 | 4 | } |
|
113 | /** |
||
114 | * @param string $source |
||
115 | * @param string $target |
||
116 | * @param string $db_driver |
||
117 | * |
||
118 | * @throws RuntimeException |
||
119 | */ |
||
120 | 4 | protected static function pre_installation_checks ($source, $target, $db_driver) { |
|
128 | /** |
||
129 | * @param string $source |
||
130 | * |
||
131 | * @return array[] |
||
132 | */ |
||
133 | 4 | protected static function initialize_filesystem ($source) { |
|
169 | /** |
||
170 | * @param array[] $file_index_map |
||
171 | * @param string $source |
||
172 | * @param string $target |
||
173 | * |
||
174 | * @throws RuntimeException |
||
175 | */ |
||
176 | 4 | protected static function extract ($file_index_map, $source, $target) { |
|
195 | /** |
||
196 | * @param string $target |
||
197 | * @param string $domain |
||
198 | * @param string $timezone |
||
199 | * @param string $db_host |
||
200 | * @param string $db_driver |
||
201 | * @param string $db_name |
||
202 | * @param string $db_user |
||
203 | * @param string $db_password |
||
204 | * @param string $db_prefix |
||
205 | * @param string $language |
||
206 | * @param string $public_key |
||
207 | * |
||
208 | * @throws RuntimeException |
||
209 | */ |
||
210 | 4 | protected static function initialize_core_config ( |
|
234 | /** |
||
235 | * @param DB\_Abstract $cdb |
||
236 | * @param string $source |
||
237 | * @param string $db_driver |
||
238 | * |
||
239 | * @throws RuntimeException |
||
240 | */ |
||
241 | 4 | protected static function initialize_db_structure ($cdb, $source, $db_driver) { |
|
250 | /** |
||
251 | * @param DB\_Abstract $cdb |
||
252 | * @param string $source |
||
253 | * @param string $site_name |
||
254 | * @param string $url |
||
255 | * @param string $admin_email |
||
256 | * @param string $language |
||
257 | * @param string $domain |
||
258 | * @param string $timezone |
||
259 | * @param int $mode |
||
260 | * |
||
261 | * @throws RuntimeException |
||
262 | */ |
||
263 | 4 | protected static function initialize_system_config ($cdb, $source, $site_name, $url, $admin_email, $language, $domain, $timezone, $mode) { |
|
310 | /** |
||
311 | * @param DB\_Abstract $cdb |
||
312 | * @param string $admin_email |
||
313 | * @param string $admin_password |
||
314 | * @param string $public_key |
||
315 | * |
||
316 | * @throws RuntimeException |
||
317 | */ |
||
318 | 4 | protected static function create_root_administrator ($cdb, $admin_email, $admin_password, $public_key) { |
|
340 | } |
||
341 |