Skip to content

Commit d9c3424

Browse files
committed
More updates
1 parent 6763d53 commit d9c3424

12 files changed

Lines changed: 269 additions & 271 deletions

File tree

env.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,27 @@
1212
$L = Modules::getModuleLangFile("system_check", Core::$user->getLang());
1313

1414
$page = Modules::loadModuleField("system_check", "page", "page", "summary");
15-
16-
$page_vars = array();
17-
15+
$root_url = Core::getRootUrl();
1816
$same_page = General::getCleanPhpSelf();
19-
$tabs = array(
20-
"summary" => array(
21-
"tab_label" => $L["word_summary"],
22-
"tab_link" => "{$same_page}?page=summary",
23-
"pages" => array("summary")
17+
18+
$page_vars = array(
19+
"page" => $page,
20+
"tabs" => array(
21+
"summary" => array(
22+
"tab_label" => $L["word_summary"],
23+
"tab_link" => "{$same_page}?page=summary",
24+
"pages" => array("summary")
25+
),
26+
"phpinfo" => array(
27+
"tab_label" => "phpinfo",
28+
"tab_link" => "{$same_page}?page=phpinfo",
29+
"pages" => array("phpinfo")
30+
)
2431
),
25-
"phpinfo" => array(
26-
"tab_label" => "phpinfo",
27-
"tab_link" => "{$same_page}?page=phpinfo",
28-
"pages" => array("phpinfo")
29-
)
32+
"css_files" => array("{$root_url}/modules/system_check/global/css/styles.css")
3033
);
3134

32-
$page_vars["page"] = $page;
33-
$page_vars["tabs"] = $tabs;
34-
35-
switch ($page)
36-
{
35+
switch ($page) {
3736
case "summary":
3837
require_once("env_tab_summary.php");
3938
break;

files.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
$page_vars["core_version"] = Core::getVersionString();
2424
$page_vars["module_list"] = General::getCompatibleModules("files");
2525
$page_vars["theme_list"] = Files::getCompatibleThemes();
26+
$page_vars["css_files"] = array("{$root_url}/modules/system_check/global/css/styles.css");
2627
$page_vars["head_string"] =<<< EOF
2728
<script src="{$root_url}/modules/system_check/global/scripts/tests.js"></script>
28-
<link type="text/css" rel="stylesheet" href="{$root_url}/modules/system_check/global/css/styles.css">
2929
<script>
3030
g.messages = [];
3131
g.messages["word_testing_c"] = "{$L["word_testing_c"]}";

global/code/Orphans.class.php

Lines changed: 99 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
namespace FormTools\Modules\SystemCheck;
55

6+
use PDO;
7+
use FormTools\Core;
8+
use FormTools\Themes;
9+
10+
611
/**
712
* Contains all functions relating to the Orphan Record Check page. This test has specific,
813
* hardcoded tests to run on each table. The tests may vary depending on the current Core version.
@@ -18,102 +23,102 @@ class Orphans
1823
*
1924
* @param string $table_name
2025
*/
21-
function sc_find_table_orphans($table_name, $remove_orphans)
26+
public static function findTableOrphans($table_name, $remove_orphans)
2227
{
2328
global $g_table_prefix;
2429

2530
$results = array(
26-
"table_name" => $table_name,
27-
"num_tests" => 0,
28-
"num_orphans" => 0,
29-
"test_descriptions" => "",
30-
"problems" => ""
31+
"table_name" => $table_name,
32+
"num_tests" => 0,
33+
"num_orphans" => 0,
34+
"test_descriptions" => "",
35+
"problems" => ""
3136
);
3237

3338
$table_name_without_prefix = preg_replace("/^{$g_table_prefix}/", "", $table_name);
3439

3540
$has_test = true;
3641
switch ($table_name_without_prefix) {
3742
case "accounts":
38-
$response = sc_orphan_test__accounts($remove_orphans);
43+
$response = Orphans::testAccounts($remove_orphans);
3944
break;
4045
case "account_settings":
41-
$response = sc_orphan_test__account_settings($remove_orphans);
46+
$response = Orphans::testAccountSettings($remove_orphans);
4247
break;
4348
case "client_forms":
44-
$response = sc_orphan_test__client_forms($remove_orphans);
49+
$response = Orphans::testClientForms($remove_orphans);
4550
break;
4651
case "client_views":
47-
$response = sc_orphan_test__client_views($remove_orphans);
52+
$response = Orphans::testClientViews($remove_orphans);
4853
break;
4954
case "email_templates":
50-
$response = sc_orphan_test__email_templates($remove_orphans);
55+
$response = Orphans::testEmailTemplates($remove_orphans);
5156
break;
5257
case "email_template_edit_submission_views":
53-
$response = sc_orphan_test__email_template_edit_submission_views($remove_orphans);
58+
$response = Orphans::testEmailTemplateEditSubmissionViews($remove_orphans);
5459
break;
5560
case "email_template_recipients":
56-
$response = sc_orphan_test__email_template_recipients($remove_orphans);
61+
$response = Orphans::testEmailTemplateRecipients($remove_orphans);
5762
break;
5863
case "email_template_when_sent_views":
59-
$response = sc_orphan_test__email_template_when_sent_views($remove_orphans);
64+
$response = Orphans::testEmailTemplateWhenSentViews($remove_orphans);
6065
break;
6166
case "field_options":
62-
$response = sc_orphan_test__field_options($remove_orphans);
67+
$response = Orphans::testFieldOptions($remove_orphans);
6368
break;
6469
case "field_settings":
65-
$response = sc_orphan_test__field_settings($remove_orphans);
70+
$response = Orphans::orphanTestFieldSettings($remove_orphans);
6671
break;
6772
case "field_type_settings":
68-
$response = sc_orphan_test__field_type_settings($remove_orphans);
73+
$response = Orphans::testFieldTypeSettings($remove_orphans);
6974
break;
7075
case "field_type_setting_options":
71-
$response = sc_orphan_test__field_type_setting_options($remove_orphans);
76+
$response = Orphans::testFieldTypeSettingOptions($remove_orphans);
7277
break;
7378
case "field_type_validation_rules":
74-
$response = sc_orphan_test__field_type_validation_rules($remove_orphans);
79+
$response = Orphans::testFieldTypeValidationRules($remove_orphans);
7580
break;
7681
case "field_validation":
77-
$response = sc_orphan_test__field_validation($remove_orphans);
82+
$response = Orphans::testFieldValidation($remove_orphans);
7883
break;
7984
case "form_email_fields":
80-
$response = sc_orphan_test__form_email_fields($remove_orphans);
85+
$response = Orphans::testFormEmailFields($remove_orphans);
8186
break;
8287
case "form_fields":
83-
$response = sc_orphan_test__form_fields($remove_orphans);
88+
$response = Orphans::testFormFields($remove_orphans);
8489
break;
8590
case "menu_items":
86-
$response = sc_orphan_test__menu_items($remove_orphans);
91+
$response = Orphans::testMenuItems($remove_orphans);
8792
break;
8893
case "multi_page_form_urls":
89-
$response = sc_orphan_test__multi_page_form_urls($remove_orphans);
94+
$response = Orphans::testMultiPageFormUrls($remove_orphans);
9095
break;
9196
case "new_view_submission_defaults":
92-
$response = sc_orphan_test__new_view_submission_defaults($remove_orphans);
97+
$response = Orphans::testNewViewSubmissionDefaults($remove_orphans);
9398
break;
9499
case "new_view_submission_defaults":
95-
$response = sc_orphan_test__new_view_submission_defaults($remove_orphans);
100+
$response = Orphans::testNewViewSubmissionDefaults($remove_orphans);
96101
break;
97102
case "public_form_omit_list":
98-
$response = sc_orphan_test__public_form_omit_list($remove_orphans);
103+
$response = Orphans::testPublicFormOmitList($remove_orphans);
99104
break;
100105
case "public_view_omit_list":
101-
$response = sc_orphan_test__public_view_omit_list($remove_orphans);
106+
$response = Orphans::testPublicViewOmitList($remove_orphans);
102107
break;
103108
case "views":
104-
$response = sc_orphan_test__views($remove_orphans);
109+
$response = Orphans::testViews($remove_orphans);
105110
break;
106111
case "view_columns":
107-
$response = sc_orphan_test__view_columns($remove_orphans);
112+
$response = Orphans::testViewColumns($remove_orphans);
108113
break;
109114
case "view_fields":
110-
$response = sc_orphan_test__view_fields($remove_orphans);
115+
$response = Orphans::testViewFields($remove_orphans);
111116
break;
112117
case "view_filters":
113-
$response = sc_orphan_test__view_filters($remove_orphans);
118+
$response = Orphans::testViewFilters($remove_orphans);
114119
break;
115120
case "view_tabs":
116-
$response = sc_orphan_test__view_tabs($remove_orphans);
121+
$response = Orphans::testViewTabs($remove_orphans);
117122
break;
118123

119124
default:
@@ -138,14 +143,14 @@ function sc_find_table_orphans($table_name, $remove_orphans)
138143

139144
public static function cleanOrphans()
140145
{
141-
global $g_root_dir;
146+
$root_dir = Core::getRootDir();
142147

143-
require_once("$g_root_dir/global/misc/config_core.php");
148+
require_once("$root_dir/global/misc/config_core.php");
144149
$tables = Tables::getComponentTables($STRUCTURE);
145150

146151
$problems = array();
147152
foreach ($tables as $table_name) {
148-
$response = sc_find_table_orphans($table_name, true);
153+
$response = Orphans::findTableOrphans($table_name, true);
149154
if (!empty($response["clean_up_problems"])) {
150155
$problems[] = $response["clean_up_problems"];
151156
}
@@ -175,36 +180,46 @@ public static function cleanOrphans()
175180
/**
176181
* Tests: account_id
177182
*/
178-
function sc_orphan_test__account_settings($remove_orphans)
183+
private static function testAccountSettings($remove_orphans)
179184
{
180-
global $g_table_prefix, $g_current_version, $g_cache;
185+
$db = Core::$db;
181186

182187
$response = array(
183-
"test_descriptions" => "Looks for settings associated with non-existent user accounts.",
184-
"problems" => array()
188+
"test_descriptions" => "Looks for settings associated with non-existent user accounts.",
189+
"problems" => array()
185190
);
186191

187192
$valid_account_ids = General::getAccountIds();
188193

189-
$settings_query = mysql_query("SELECT * FROM {$g_table_prefix}account_settings");
194+
$db->query("SELECT * FROM {PREFIX}account_settings");
195+
$db->execute();
196+
$rows = $db->fetchAll();
197+
190198
$num_tests = 0;
191199
$num_orphans = 0;
192-
while ($row = mysql_fetch_assoc($settings_query)) {
200+
foreach ($rows as $row) {
193201
$curr_account_id = $row["account_id"];
202+
194203
if (!in_array($curr_account_id, $valid_account_ids)) {
195204
$response["problems"][] = "Invalid account ID: $curr_account_id";
196205
$num_orphans++;
197206

198207
// clean-up code
199208
if ($remove_orphans) {
200-
@mysql_query("
201-
DELETE FROM {$g_table_prefix}account_settings
202-
WHERE account_id = $curr_account_id AND
203-
setting_name = '{$row["setting_name"]}'
204-
LIMIT 1
205-
");
209+
$db->query("
210+
DELETE FROM {PREFIX}account_settings
211+
WHERE account_id = :account_id AND
212+
setting_name = :setting_name
213+
LIMIT 1
214+
");
215+
$db->bindAll(array(
216+
"account_id" => $curr_account_id,
217+
"setting_name" => $row["setting_name"]
218+
));
219+
$db->execute();
206220
}
207221
}
222+
208223
$num_tests++;
209224
}
210225

@@ -218,41 +233,41 @@ function sc_orphan_test__account_settings($remove_orphans)
218233
/**
219234
* Tests: theme, menu_id.
220235
*/
221-
function sc_orphan_test__accounts($remove_orphans)
236+
private static function testAccounts($remove_orphans)
222237
{
223-
global $g_table_prefix, $g_current_version, $g_cache;
238+
$db = Core::$db;
224239

225240
$response = array(
226-
"test_descriptions" => "Checks theme associated with accounts is a valid, enabled theme, and checks the menu ID of accounts exists.",
227-
"problems" => array(),
228-
"clean_up_problems" => array()
241+
"test_descriptions" => "Checks theme associated with accounts is a valid, enabled theme, and checks the menu ID of accounts exists.",
242+
"problems" => array(),
243+
"clean_up_problems" => array()
229244
);
230245

231-
$query = mysql_query("
232-
SELECT account_id, account_type, theme, menu_id
233-
FROM {$g_table_prefix}accounts
234-
");
246+
$db->query("SELECT account_id, account_type, theme, menu_id FROM {PREFIX}accounts");
247+
$db->execute();
248+
$account_rows = $db->fetchAll();
235249

236250
$valid_menu_ids = General::getMenuIds();
237251

238252
$first_client_menu_id = "";
239253
if ($remove_orphans) {
240-
$menu_query = mysql_query("SELECT menu_id FROM {$g_table_prefix}menus WHERE menu_type = 'client' LIMIT 1");
241-
$info = mysql_fetch_assoc($menu_query);
242-
if (!empty($info["menu_id"])) {
243-
$first_client_menu_id = $info["menu_id"];
254+
$db->query("SELECT menu_id FROM {PREFIX}menus WHERE menu_type = 'client' LIMIT 1");
255+
$db->execute();
256+
$menu_id = $db->fetch(PDO::FETCH_COLUMN);
257+
if (!empty($menu_id)) {
258+
$first_client_menu_id = $menu_id;
244259
}
245260
}
246261

247262
// get a list of valid theme folders
248-
$themes = ft_get_themes(true);
263+
$themes = Themes::getList(true);
249264
$valid_theme_folders = array();
250265
foreach ($themes as $theme_info) {
251266
$valid_theme_folders[] = $theme_info["theme_folder"];
252267
}
253268

254269
$num_tests = 0;
255-
while ($row = mysql_fetch_assoc($query)) {
270+
foreach ($account_rows as $row) {
256271
if (!in_array($row["menu_id"], $valid_menu_ids)) {
257272
$response["problems"][] = "Invalid menu ID: {$row["menu_id"]}";
258273

@@ -266,11 +281,16 @@ function sc_orphan_test__accounts($remove_orphans)
266281
if (empty($new_menu_id)) {
267282
$response["clean_up_problems"][] = "There's no client menu. Please create one, then re-run the test to fix all dud references.";
268283
} else {
269-
@mysql_query("
270-
UPDATE {$g_table_prefix}accounts
271-
SET menu_id = $new_menu_id
272-
WHERE account_id = {$row["account_id"]}
273-
");
284+
$db->query("
285+
UPDATE {PREFIX}accounts
286+
SET menu_id = :menu_id,
287+
WHERE account_id = :account_id
288+
");
289+
$db->bindAll(array(
290+
"menu_id" => $new_menu_id,
291+
"account_id" => $row["account_id"]
292+
));
293+
$db->execute();
274294
}
275295
}
276296
}
@@ -281,12 +301,14 @@ function sc_orphan_test__accounts($remove_orphans)
281301

282302
// clean-up code
283303
if ($remove_orphans) {
284-
@mysql_query("
285-
UPDATE {$g_table_prefix}accounts
286-
SET theme = 'default',
287-
swatch = 'green'
288-
WHERE account_id = {$row["account_id"]}
289-
");
304+
$db->query("
305+
UPDATE {PREFIX}accounts
306+
SET theme = 'default',
307+
swatch = 'green'
308+
WHERE account_id = :account_id
309+
");
310+
$db->bind("account_id", $row["account_id"]);
311+
$db->execute();
290312
}
291313
}
292314
$num_tests++;
@@ -299,13 +321,11 @@ function sc_orphan_test__accounts($remove_orphans)
299321
}
300322

301323

302-
function sc_orphan_test__client_forms($remove_orphans)
324+
private static function testClientForms($remove_orphans)
303325
{
304-
global $g_table_prefix, $g_current_version, $g_cache;
305-
306326
$response = array(
307-
"test_descriptions" => "Checks for invalid account IDs and invalid form IDs.",
308-
"problems" => array()
327+
"test_descriptions" => "Checks for invalid account IDs and invalid form IDs.",
328+
"problems" => array()
309329
);
310330

311331
$query = mysql_query("SELECT * FROM {$g_table_prefix}client_forms");

0 commit comments

Comments
 (0)