-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_configuration.php
More file actions
128 lines (96 loc) · 3.72 KB
/
create_configuration.php
File metadata and controls
128 lines (96 loc) · 3.72 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
<?php
include ('classes/Database.php');
include ('classes/FileLoader.php');
include ('classes/Config.php');
include ('user/local.php');
# parameters
$delete_configuration_files = false;
$drop_configuration_table = true;
if (php_sapi_name() == 'cli') {
$line_end = "\n";
} else {
$line_end = '<br>' . "\n";
}
# database connection
$db = Database::getDB();
$mysqli = $db->getCon();
# drop configuration table before creating
if ($drop_configuration_table) {
$sql = 'DROP TABLE IF EXISTS `configuration`;';
$result = $mysqli->query($sql);
if (!$result) {
echo 'Error: Could not drop table `configuration`.' . $line_end;
die('Error: ' . $mysqli->error . $line_end);
} else {
while ($mysqli->next_result()) {;}
echo 'Success: Dropped table `configuration`.' . $line_end;
}
}
# create configuration table
$sql = 'CREATE TABLE `configuration` (
`option_set` VARCHAR(128) NOT NULL,
`option_name` VARCHAR(128) NOT NULL,
`option_value` VARCHAR(128) NOT NULL,
PRIMARY KEY (`option_set`(128), `option_name`(128))
) CHARSET=utf8 COLLATE utf8_unicode_ci;';
$result = $mysqli->query($sql);
if (!$result) {
echo 'Error: Could not create table `configuration`.' . $line_end;
die('Error: ' . $mysqli->error . $line_end);
} else {
echo 'Success: Created table `configuration`.' . $line_end;
}
# load configuration from file
$system_config = FileLoader::loadIni('system/config.ini');
$user_config = FileLoader::loadIni('user/config.ini');
$config = array_merge($system_config, $user_config);
# store configuration to database
$fields = array('option_set', 'option_name', 'option_value');
$value_rows = array();
### site configuration
$site_config_set = 'site';
$site_config_copy = array('url_schema', 'language', 'theme',
'category_page_length');
foreach ($site_config_copy as $option_name) {
$value_rows[] = array($site_config_set, $option_name,
$config[$option_name]);
}
### site information
$site_info_set = 'meta';
$value_rows[] = array($site_info_set, 'mail',
$config['server_mail']);
$value_rows[] = array($site_info_set, 'name',
$config['site_name']);
$value_rows[] = array($site_info_set, 'title',
$config['site_title']);
### external configuration
$ext_config_set = 'ext';
$value_rows[] = array($ext_config_set, 'amazon_tag',
$config['amazon_tag']);
$value_rows[] = array($ext_config_set, 'google_analytics',
$config['google_analytics']);
### developer configuration
$dev_config_set = 'dev';
$value_rows[] = array($dev_config_set, 'debug', 0);
$value_rows[] = array($dev_config_set, 'dev_server_address',
$config['devServer']);
$value_rows[] = array($dev_config_set, 'remote_server_address',
$config['remote_address']);
### search configuration
$search_set = 'search';
$value_rows[] = array($search_set, 'marks',
$config['search.marks']);
$value_rows[] = array($search_set, 'case_sensitive',
$config['search.case_sensitive']);
$values = array('sss', $value_rows);
$result = $db->insertMany('configuration', $fields, $values);
if ($result === null) {
echo 'Error: Could not copy configuration values to DB.' . $line_end;
die('Error: ' . $mysqli->error . $line_end);
} else {
echo 'Success: Copied configuration values to DB.' . $line_end;
}
# delete configuration files
if ($delete_configuration_files) {
}
?>