Conditions | 48 |
Paths | > 20000 |
Total Lines | 195 |
Code Lines | 115 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
32 | function initial_sanity_check() { |
||
33 | |||
34 | $errors = array(); |
||
35 | |||
36 | if (!file_exists("config.php")) { |
||
37 | array_push($errors, "Configuration file not found. Looks like you forgot to copy config.php-dist to config.php and edit it."); |
||
38 | } else { |
||
39 | |||
40 | require_once "sanity_config.php"; |
||
41 | |||
42 | if (file_exists("install") && !file_exists("config.php")) { |
||
43 | array_push($errors, "Please copy config.php-dist to config.php or run the installer in install/"); |
||
44 | } |
||
45 | |||
46 | if (strpos(PLUGINS, "auth_") === false) { |
||
47 | array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php"); |
||
48 | } |
||
49 | |||
50 | if (function_exists('posix_getuid') && posix_getuid() == 0) { |
||
51 | array_push($errors, "Please don't run this script as root."); |
||
52 | } |
||
53 | |||
54 | if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
||
55 | array_push($errors, "PHP version 5.6.0 or newer required. You're using ".PHP_VERSION."."); |
||
56 | } |
||
57 | |||
58 | if (!class_exists("UConverter")) { |
||
59 | array_push($errors, "PHP UConverter class is missing, it's provided by the Internationalization (intl) module."); |
||
60 | } |
||
61 | |||
62 | if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) { |
||
63 | array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value."); |
||
64 | } |
||
65 | |||
66 | if (!is_writable(CACHE_DIR."/images")) { |
||
67 | array_push($errors, "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)"); |
||
68 | } |
||
69 | |||
70 | if (!is_writable(CACHE_DIR."/upload")) { |
||
71 | array_push($errors, "Upload cache is not writable (chmod -R 777 ".CACHE_DIR."/upload)"); |
||
72 | } |
||
73 | |||
74 | if (!is_writable(CACHE_DIR."/export")) { |
||
75 | array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)"); |
||
76 | } |
||
77 | |||
78 | if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) { |
||
79 | array_push($errors, |
||
80 | "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh"); |
||
81 | } |
||
82 | |||
83 | foreach ($required_defines as $d) { |
||
84 | if (!defined($d)) { |
||
85 | array_push($errors, |
||
86 | "Required configuration file parameter $d is not defined in config.php. You might need to copy it from config.php-dist."); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | if (SINGLE_USER_MODE && class_exists("PDO")) { |
||
91 | $pdo = DB::pdo(); |
||
92 | |||
93 | $res = $pdo->query("SELECT id FROM ttrss_users WHERE id = 1"); |
||
94 | |||
95 | if (!$res->fetch()) { |
||
96 | array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found."); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | $ref_self_url_path = make_self_url_path(); |
||
101 | $ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path); |
||
102 | |||
103 | if (SELF_URL_PATH == "http://example.org/tt-rss/") { |
||
104 | array_push($errors, |
||
105 | "Please set SELF_URL_PATH to the correct value for your server (possible value: <b>$ref_self_url_path</b>)"); |
||
106 | } |
||
107 | |||
108 | if (isset($_SERVER["HTTP_HOST"]) && |
||
109 | (!defined('_SKIP_SELF_URL_PATH_CHECKS') || !_SKIP_SELF_URL_PATH_CHECKS) && |
||
110 | SELF_URL_PATH != $ref_self_url_path && SELF_URL_PATH != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path) - 1)) { |
||
111 | array_push($errors, |
||
112 | "Please set SELF_URL_PATH to the correct value detected for your server: <b>$ref_self_url_path</b>"); |
||
113 | } |
||
114 | |||
115 | if (!is_writable(ICONS_DIR)) { |
||
116 | array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n"); |
||
117 | } |
||
118 | |||
119 | if (!is_writable(LOCK_DIRECTORY)) { |
||
120 | array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 ".LOCK_DIRECTORY.").\n"); |
||
121 | } |
||
122 | |||
123 | if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { |
||
124 | array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL."); |
||
125 | } |
||
126 | |||
127 | if (!function_exists("json_encode")) { |
||
128 | array_push($errors, "PHP support for JSON is required, but was not found."); |
||
129 | } |
||
130 | |||
131 | if (DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
||
132 | array_push($errors, "PHP support for MySQL is required for configured DB_TYPE in config.php."); |
||
133 | } |
||
134 | |||
135 | if (DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
||
136 | array_push($errors, "PHP support for PostgreSQL is required for configured DB_TYPE in config.php"); |
||
137 | } |
||
138 | |||
139 | if (!class_exists("PDO")) { |
||
140 | array_push($errors, "PHP support for PDO is required but was not found."); |
||
141 | } |
||
142 | |||
143 | if (!function_exists("mb_strlen")) { |
||
144 | array_push($errors, "PHP support for mbstring functions is required but was not found."); |
||
145 | } |
||
146 | |||
147 | if (!function_exists("hash")) { |
||
148 | array_push($errors, "PHP support for hash() function is required but was not found."); |
||
149 | } |
||
150 | |||
151 | if (ini_get("safe_mode")) { |
||
152 | array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss."); |
||
153 | } |
||
154 | |||
155 | if (!function_exists("mime_content_type")) { |
||
156 | array_push($errors, "PHP function mime_content_type() is missing, try enabling fileinfo module."); |
||
157 | } |
||
158 | |||
159 | if (!class_exists("DOMDocument")) { |
||
160 | array_push($errors, "PHP support for DOMDocument is required, but was not found."); |
||
161 | } |
||
162 | |||
163 | if (DB_TYPE == "mysql") { |
||
164 | $bad_tables = check_mysql_tables(); |
||
165 | |||
166 | if (count($bad_tables) > 0) { |
||
167 | $bad_tables_fmt = []; |
||
168 | |||
169 | foreach ($bad_tables as $bt) { |
||
170 | array_push($bad_tables_fmt, sprintf("%s (%s)", $bt['table_name'], $bt['engine'])); |
||
171 | } |
||
172 | |||
173 | $msg = "<p>The following tables use an unsupported MySQL engine: <b>". |
||
174 | implode(", ", $bad_tables_fmt)."</b>.</p>"; |
||
175 | |||
176 | $msg .= "<p>The only supported engine on MySQL is InnoDB. MyISAM lacks functionality to run |
||
177 | tt-rss. |
||
178 | Please backup your data (via OPML) and re-import the schema before continuing.</p> |
||
179 | <p><b>WARNING: importing the schema would mean LOSS OF ALL YOUR DATA.</b></p>"; |
||
180 | |||
181 | |||
182 | array_push($errors, $msg); |
||
183 | } |
||
184 | } |
||
185 | } |
||
186 | |||
187 | if (count($errors) > 0 && $_SERVER['REQUEST_URI']) { ?> |
||
188 | <!DOCTYPE html> |
||
189 | <html> |
||
190 | <head> |
||
191 | <title>Startup failed</title> |
||
192 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
||
193 | <link rel="stylesheet" type="text/css" href="css/default.css"> |
||
194 | </head> |
||
195 | <body class='sanity_failed claro ttrss_utility'> |
||
196 | <div class="content"> |
||
197 | |||
198 | <h1>Startup failed</h1> |
||
199 | |||
200 | <p>Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade. Please fix |
||
201 | errors indicated by the following messages:</p> |
||
202 | |||
203 | <?php foreach ($errors as $error) { echo format_error($error); } ?> |
||
204 | |||
205 | <p>You might want to check tt-rss <a href="http://tt-rss.org/wiki">wiki</a> or the |
||
206 | <a href="http://tt-rss.org/forum">forums</a> for more information. Please search the forums before creating new topic |
||
207 | for your question.</p> |
||
208 | |||
209 | </div> |
||
210 | </body> |
||
211 | </html> |
||
212 | |||
213 | <?php |
||
214 | die; |
||
215 | } else if (count($errors) > 0) { |
||
216 | echo "Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade.\n"; |
||
217 | echo "Please fix errors indicated by the following messages:\n\n"; |
||
218 | |||
219 | foreach ($errors as $error) { |
||
220 | echo " * $error\n"; |
||
221 | } |
||
222 | |||
223 | echo "\nYou might want to check tt-rss wiki or the forums for more information.\n"; |
||
224 | echo "Please search the forums before creating new topic for your question.\n"; |
||
225 | |||
226 | exit(-1); |
||
227 | } |
||
233 |