1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Adam Jakab. |
4
|
|
|
* Date: 08/03/16 |
5
|
|
|
* Time: 16.07 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SuiteCrm\Install; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class SystemChecker { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Run all system checks prior to installation |
15
|
|
|
* @throws \Exception |
16
|
|
|
*/ |
17
|
|
|
public static function runChecks() { |
18
|
|
|
self::checkPhpVersion(); |
19
|
|
|
self::checkPhpBackwardCompatibilityVersion(); |
20
|
|
|
self::checkDatabaseConnection(); |
21
|
|
|
self::checkXmlParsing(); |
22
|
|
|
self::checkMbstrings(); |
23
|
|
|
self::checkZipSupport(); |
24
|
|
|
self::checkConfigFile(); |
25
|
|
|
self::checkConfigOverrideFile(); |
26
|
|
|
self::checkCustomDirectory(); |
27
|
|
|
self::checkCacheDirs(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @throws \Exception |
32
|
|
|
*/ |
33
|
|
|
protected static function checkCacheDirs() { |
34
|
|
|
$cache_files = [ |
35
|
|
|
'images', |
36
|
|
|
'layout', |
37
|
|
|
'pdf', |
38
|
|
|
'xml', |
39
|
|
|
'include/javascript' |
40
|
|
|
]; |
41
|
|
|
foreach ($cache_files as $cache_file) { |
42
|
|
|
$dirname = PROJECT_ROOT . '/' . sugar_cached( $cache_file); |
43
|
|
|
$ok = FALSE; |
44
|
|
|
if ((is_dir($dirname)) || @sugar_mkdir($dirname, 0755, TRUE)) { |
45
|
|
|
$ok = make_writable($dirname); |
46
|
|
|
} |
47
|
|
|
if (!$ok) { |
48
|
|
|
throw new \Exception("The Cache Directory($dirname) is not writable."); |
49
|
|
|
} else { |
50
|
|
|
echo "\n" . $dirname; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws \Exception |
57
|
|
|
*/ |
58
|
|
|
protected static function checkCustomDirectory() { |
59
|
|
|
if (!make_writable(PROJECT_ROOT . '/custom')) { |
60
|
|
|
throw new \Exception("The Custom Directory exists but is not writable."); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @throws \Exception |
66
|
|
|
*/ |
67
|
|
|
protected static function checkConfigOverrideFile() { |
68
|
|
|
if (file_exists(PROJECT_ROOT . '/config_override.php') |
69
|
|
|
&& (!(make_writable(PROJECT_ROOT . '/config_override.php')) |
70
|
|
|
|| !(is_writable( |
71
|
|
|
PROJECT_ROOT . '/config_override.php' |
72
|
|
|
))) |
73
|
|
|
) { |
74
|
|
|
throw new \Exception("The config_override file is not writable!"); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @throws \Exception |
80
|
|
|
*/ |
81
|
|
|
protected static function checkConfigFile() { |
82
|
|
|
if (file_exists(PROJECT_ROOT . '/config.php') |
83
|
|
|
&& (!(make_writable(PROJECT_ROOT . '/config.php')) || !(is_writable(PROJECT_ROOT . '/config.php'))) |
84
|
|
|
) { |
85
|
|
|
throw new \Exception("The config file is not writable!"); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @throws \Exception |
92
|
|
|
*/ |
93
|
|
|
protected static function checkZipSupport() { |
94
|
|
|
if (!class_exists('ZipArchive')) { |
95
|
|
|
throw new \Exception("ZIP support is unavailable!"); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @throws \Exception |
101
|
|
|
*/ |
102
|
|
|
protected static function checkMbstrings() { |
103
|
|
|
if (!function_exists('mb_strlen')) { |
104
|
|
|
throw new \Exception("MBString support is unavailable!"); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @throws \Exception |
110
|
|
|
*/ |
111
|
|
|
protected static function checkXmlParsing() { |
112
|
|
|
if (!function_exists('xml_parser_create')) { |
113
|
|
|
throw new \Exception("XML Parser Libraries are unavailable!"); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @throws \Exception |
119
|
|
|
*/ |
120
|
|
|
protected static function checkDatabaseConnection() { |
121
|
|
|
$drivers = \DBManagerFactory::getDbDrivers(); |
122
|
|
|
if (empty($drivers)) { |
123
|
|
|
throw new \Exception("No Database driver is available!"); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @throws \Exception |
129
|
|
|
*/ |
130
|
|
|
protected static function checkPhpBackwardCompatibilityVersion() { |
131
|
|
|
if (ini_get("zend.ze1_compatibility_mode")) { |
132
|
|
|
throw new \Exception("Php Backward Compatibility mode is turned on. Set zend.ze1_compatibility_mode to Off!"); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @throws \Exception |
138
|
|
|
*/ |
139
|
|
|
protected static function checkPhpVersion() { |
140
|
|
|
$php_version = constant('PHP_VERSION'); |
141
|
|
|
if (check_php_version($php_version) == -1) { |
142
|
|
|
throw new \Exception("Your version of PHP is not supported by SuiteCRM: $php_version!"); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |