blob: 1b363b9501ec7e5008f6576c1efe04d7f088e013 (
plain)
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
|
<?php
/**
* Elgg installation
* Various functions to assist with installing and upgrading the system
*
* @package Elgg
* @subpackage Core
* @author Curverider Ltd
* @link http://elgg.org/
*/
/**
* Check that the installed version of PHP meets the minimum requirements (currently 5.2 or greater).
*
* @return bool
*/
function php_check_version() {
if (version_compare(phpversion(), '5.1.2', '>=')) {
return true;
}
return false;
}
/**
* Validate the platform Elgg is being installed on.
*
* @throws ConfigurationException if the validation fails.
* @return bool
*/
function validate_platform() {
// Get database version
if (!db_check_version()) {
throw new ConfigurationException(elgg_echo('ConfigurationException:BadDatabaseVersion'));
}
// Now check PHP
if (!php_check_version()) {
throw new ConfigurationException(elgg_echo('ConfigurationException:BadPHPVersion'));
}
// TODO: Consider checking for installed modules etc
return true;
}
/**
* Returns whether or not the database has been installed
*
* @return true|false Whether the database has been installed
*/
function is_db_installed() {
global $CONFIG;
if (isset($CONFIG->db_installed)) {
return $CONFIG->db_installed;
}
if ($dblink = get_db_link('read')) {
mysql_query("select name from {$CONFIG->dbprefix}datalists limit 1", $dblink);
if (mysql_errno($dblink) > 0) {
return false;
}
} else {
return false;
}
// Set flag if db is installed (if false then we want to check every time)
$CONFIG->db_installed = true;
return true;
}
/**
* Returns whether or not other settings have been set
*
* @return true|false Whether or not the rest of the installation has been followed through with
*/
function is_installed() {
global $CONFIG;
return datalist_get('installed');
}
/**
* Copy and create a new settings.php from settings.example.php, substituting the variables in
* $vars where appropriate.
*
* $vars is an associate array of $key => $value, where $key is the variable text you wish to substitute (eg
* CONFIG_DBNAME will replace {{CONFIG_DBNAME}} in the settings file.
*
* @param array $vars The array of vars
* @param string $in_file Optional input file (if not settings.example.php)
* @return string The file containing substitutions.
*/
function create_settings(array $vars, $in_file="engine/settings.example.php") {
$file = file_get_contents($in_file);
if (!$file) {
return false;
}
foreach ($vars as $k => $v) {
$file = str_replace("{{".$k."}}", $v, $file);
}
return $file;
}
/**
* Initialisation for installation functions
*
*/
function install_init() {
register_action("systemsettings/install",true);
}
register_elgg_event_handler("boot","system","install_init");
|