Skip to content

Commit 3a372b4

Browse files
committed
1.1.0 - added test to check compatibility with FT3
1 parent f7950d9 commit 3a372b4

File tree

9 files changed

+209
-9
lines changed

9 files changed

+209
-9
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## module-system_check
22

3-
This module replaces the older Database Integrity module. It offers a few simple, quick tests to run on your Form Tools installation: kind of like taking your car to get it serviced - except this is free!
3+
This module replaces the older Database Integrity module. It offers a few simple, quick tests to run on your Form Tools
4+
installation: kind of like taking your car to get it serviced - except this is free!
45

56
### Documentation
67

ft3.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
require_once("../../global/library.php");
4+
ft_init_module_page();
5+
6+
$page_vars = array(
7+
"php_version" => phpversion(),
8+
"php_version_compatible" => version_compare(phpversion(), 5.3, ">="),
9+
"pdo_available" => extension_loaded("PDO"),
10+
"pdo_mysql_available" => extension_loaded("pdo_mysql")
11+
);
12+
13+
$page_vars["head_string"] =<<< EOF
14+
<script src="{$g_root_url}/modules/system_check/global/scripts/tests.js"></script>
15+
<link type="text/css" rel="stylesheet" href="{$g_root_url}/modules/system_check/global/css/styles.css">
16+
EOF;
17+
18+
ft_display_module_page("templates/ft3.tpl", $page_vars);

global/code/actions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@
114114
$results = sc_find_table_orphans($request["table_name"], $remove_orphans);
115115
echo ft_convert_to_json($results);
116116
break;
117+
118+
case "test_pdo_connection":
119+
include_once("pdo.php");
120+
echo ft_convert_to_json(sc_check_pdo_connection($request["port"]));
121+
break;
117122
}
118123

119124

global/code/pdo.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file gets included if the user has PDO installed on their system. It attempts to check the connection to
5+
* the database using PDO.
6+
*/
7+
8+
9+
function sc_check_pdo_connection($port)
10+
{
11+
global $g_db_hostname, $g_db_name, $g_db_username, $g_db_password;
12+
13+
try {
14+
$dsn = sprintf("mysql:host=%s;port=%s;dbname=%s;charset=utf8", $g_db_hostname, $port, $g_db_name);
15+
new PDO($dsn, $g_db_username, $g_db_password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
16+
} catch (PDOException $e) {
17+
return array("success" => false, "msg" => $e->getMessage(), "port" => $port);
18+
}
19+
20+
return array("success" => true, "port" => $port);
21+
}

global/scripts/tests.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,37 @@ var sc_ns = {
453453
ft.display_message("ft_message", error_type, message);
454454
return;
455455
}
456+
},
457+
458+
test_pdo_connection: function () {
459+
var port = $("#pdo_port").val();
460+
461+
$("#pdo_test_loading").html("<img src=\"images/loading.gif\" />");
462+
$("#pdo_test_btn").attr("disabled", true);
463+
$(".pdo_result").addClass("hidden");
464+
465+
$.ajax({
466+
url: g.root_url + "/modules/system_check/global/code/actions.php",
467+
data: { action: "test_pdo_connection", port: port },
468+
type: "POST",
469+
dataType: "json",
470+
success: function(result) {
471+
$("#pdo_test_loading").html("");
472+
$("#pdo_test_btn").removeAttr("disabled");
473+
474+
if (result.success) {
475+
if (result.port == 3306) {
476+
$("#pdo_result_success").removeClass("hidden");
477+
} else {
478+
$("#custom_port").html(result.port);
479+
$("#pdo_result_success_with_port").removeClass("hidden");
480+
}
481+
} else {
482+
$("#pdo_result_error").removeClass("hidden");
483+
$("#pdo_result_error_msg").html(result.msg);
484+
}
485+
}
486+
})
456487
}
457488

458489
};

lang/en_us.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
$L["module_description"] = "This replaces the older Database Integrity module. It offers various tests to analyze and repair your Form Tools installation.";
66

77
$L["word_untested"] = "Untested";
8+
$L["word_test"] = "Test";
89
$L["word_testing_c"] = "Testing: ";
910
$L["word_help"] = "Help";
1011
$L["word_component"] = "Component";
@@ -40,6 +41,8 @@
4041
$L["phrase_suhosin_extension"] = "Suhosin Extension";
4142
$L["phrase_curl_extension"] = "Curl Extension";
4243
$L["phrase_simplexml_extension"] = "SimpleXML Extension";
44+
$L["phrase_ft3_compatibility"] = "FT3 compatibility";
45+
$L["phrase_formtools3_compatibility"] = "Form Tools 3 compatibility";
4346

4447
$L["text_tables_test"] = "The following tables will be tested to confirm they exist, and that the column information is valid.";
4548
$L["text_module_intro"] = "This module lets you run tests on your Form Tools installation to look for potential problems. Choose one of the tests below.";
@@ -53,6 +56,7 @@
5356
$L["text_orphan_record_check_intro"] = "This is a house-keeping test to examine the Core database tables for any unwanted orphaned records and references. Orphaned records are database entries that are no longer needed and should have been deleted along with their \"parents\". For example, when you delete a form, any references to that form ID should also be deleted. Orphaned records shouldn't cause problems, but add unnecessary clutter to your database. <b>If this test finds anything, we'd appreciate it if you <a href=\"http://forums.formtools.org/\">report them in the forums</a>!</b>";
5457
$L["text_orphan_desc_short"] = "A housekeeping test to identify and remove old database records and references that are no longer needed and should have been deleted.";
5558
$L["text_environment_overview_summary"] = "This section below contains a report of key information about your Form Tools installation and environment, which can be helpful when reporting bugs.";
59+
$L["text_ft3_compatibility"] = "Form Tools 3 has slightly difference server requirements than Form Tools 2. This page runs a couple of simple tests to confirm you will be able to run the newer version.";
5660

5761
$L["notify_test_complete_problems"] = "The test is complete. We found a problem with one or more of your installed components.";
5862
$L["notify_test_complete_no_problems"] = "The test is complete. No problems were found.";
@@ -63,4 +67,4 @@
6367
$L["notify_problems_resetting_module_hooks"] = "There was a problem resetting the module hooks. This is most likely caused by an error in the form of your hook_calls table. Please run the Table Verification step to check.";
6468
$L["notify_file_verification_complete_problems"] = "One or more of your components is missing some files. You will need to download those version and FTP the missing files to your server.";
6569

66-
$L["validation_no_components_selected"] = "Please select one or more components to test.";
70+
$L["validation_no_components_selected"] = "Please select one or more components to test.";

module.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
* Module file: System Check
55
*/
66

7-
$MODULE["author"] = "Encore Web Studios";
8-
$MODULE["author_email"] = "formtools@encorewebstudios.com";
9-
$MODULE["author_link"] = "http://www.encorewebstudios.com";
10-
$MODULE["version"] = "1.0.3";
11-
$MODULE["date"] = "2012-03-05";
7+
$MODULE["author"] = "Ben Keen";
8+
$MODULE["author_email"] = "ben.keen@gmail.com";
9+
$MODULE["author_link"] = "http://formtools.org";
10+
$MODULE["version"] = "1.1.0";
11+
$MODULE["date"] = "2017-06-04";
1212
$MODULE["origin_language"] = "en_us";
1313

1414
// define the module navigation - the keys are keys defined in the language file. This lets
1515
// the navigation - like everything else - be customized to the users language. The paths are always built
1616
// relative to the module's root, so help/index.php means: /[form tools root]/modules/export_manager/help/index.php
1717
$MODULE["nav"] = array(
1818
"module_name" => array('{$module_dir}/index.php', false),
19+
"phrase_ft3_compatibility" => array('{$module_dir}/ft3.php', true),
1920
"phrase_file_verification" => array('{$module_dir}/files.php', true),
2021
"phrase_table_verification" => array('{$module_dir}/tables.php', true),
2122
"phrase_hook_verification" => array('{$module_dir}/hooks.php', true),
2223
"phrase_orphan_clean_up" => array('{$module_dir}/orphans.php', true),
2324
"phrase_environment_info" => array('{$module_dir}/env.php', false),
2425
"word_help" => array('{$module_dir}/help.php', false)
25-
);
26+
);

templates/ft3.tpl

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{include file='modules_header.tpl'}
2+
3+
<table cellpadding="0" cellspacing="0">
4+
<tr>
5+
<td width="45"><img src="images/icon.png" width="34" height="34" /></td>
6+
<td class="title">
7+
<a href="../../admin/modules">{$LANG.word_modules}</a>
8+
<span class="joiner">&raquo;</span>
9+
<a href="./">{$L.module_name}</a>
10+
<span class="joiner">&raquo;</span>
11+
{$L.phrase_ft3_compatibility}
12+
</td>
13+
</tr>
14+
</table>
15+
16+
{include file="messages.tpl"}
17+
18+
<div class="margin_bottom_large">
19+
{$L.text_ft3_compatibility}
20+
</div>
21+
22+
<table class="list_table" cellspacing="1" cellpadding="0" style="width: 600px">
23+
<tr>
24+
<th>{$L.word_test}</th>
25+
<th>{$L.word_result}</th>
26+
<th>{$L.word_result}</th>
27+
</tr>
28+
<tr>
29+
<td class="pad_left_small medium_grey">Compatible PHP Version</td>
30+
<td class="pad_left_small">{$php_version}</td>
31+
<td align="center">
32+
{if $php_version_compatible}
33+
<span class="green">{$LANG.word_pass|upper}</span>
34+
{else}
35+
<span class="red">{$LANG.word_fail|upper}</span>
36+
{/if}
37+
</td>
38+
</tr>
39+
<tr>
40+
<td class="pad_left_small medium_grey">PDO Available</td>
41+
<td class="pad_left_small">
42+
{if $pdo_available}
43+
{$LANG.word_yes}
44+
{else}
45+
{$LANG.word_no}
46+
{/if}
47+
</td>
48+
<td align="center">
49+
{if $pdo_available}
50+
<span class="green">{$LANG.word_pass|upper}</span>
51+
{else}
52+
<span class="red">{$LANG.word_fail|upper}</span>
53+
{/if}
54+
</td>
55+
</tr>
56+
<tr>
57+
<td class="pad_left_small medium_grey">PDO-MySQL extension available</td>
58+
<td class="pad_left_small">
59+
{if $pdo_mysql_available}
60+
{$LANG.word_yes}
61+
{else}
62+
{$LANG.word_no}
63+
{/if}
64+
</td>
65+
<td align="center">
66+
{if $pdo_mysql_available}
67+
<span class="green">{$LANG.word_pass|upper}</span>
68+
{else}
69+
<span class="red">{$LANG.word_fail|upper}</span>
70+
{/if}
71+
</td>
72+
</tr>
73+
</table>
74+
75+
{if $php_version_compatible && $pdo_available && $pdo_mysql_available}
76+
77+
<br />
78+
79+
<p><b>Test Database Connection</b></p>
80+
81+
<p>
82+
This attempts to make a database connection using PDO. By default PDO connects on port <b>3306</b>.
83+
</p>
84+
85+
<p>
86+
Port:
87+
<input type="text" id="pdo_port" size="6" value="3306" />
88+
<input type="button" id="pdo_test_btn" value="{$L.phrase_run_test}" onclick="sc_ns.test_pdo_connection()" />
89+
<span id="pdo_test_loading"></span>
90+
</p>
91+
92+
<div id="pdo_result_error" class="error pdo_result hidden">
93+
<div style="padding: 6px">
94+
Sorry, there was a problem connecting. Here's the error that was returned:
95+
<p><b id="pdo_result_error_msg"></b></p>
96+
</div>
97+
</div>
98+
99+
<div id="pdo_result_success" class="notify pdo_result hidden">
100+
<div style="padding: 6px">
101+
Excellent! You will be able to upgrade to Form Tools 3 without making any changes to your configuration.
102+
</div>
103+
</div>
104+
105+
<div id="pdo_result_success_with_port" class="notify pdo_result hidden">
106+
<div style="padding: 6px">
107+
Excellent! You will be able to upgrade to Form Tools 3 but will need to add the following setting to your
108+
<b>/global/config.php</b> file:
109+
<p><b>$g_db_port = <span id="custom_port"></span>;</b></p>
110+
</div>
111+
</div>
112+
113+
{/if}
114+
115+
{include file='modules_footer.tpl'}

templates/index.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<hr size="1" />
2121

2222
<table cellspacing="0" class="index_link_table">
23+
<tr>
24+
<td valign="top" width="160"><a href="ft3.php">{$L.phrase_formtools3_compatibility}</a></td>
25+
<td>{$L.text_ft3_compatibility}</td>
26+
</tr>
2327
<tr>
2428
<td valign="top" width="160"><a href="files.php">{$L.phrase_file_verification}</a></td>
2529
<td>{$L.text_file_check} {$L.text_problems_identified_not_fixed}</td>
@@ -38,4 +42,4 @@
3842
</tr>
3943
</table>
4044

41-
{include file='modules_footer.tpl'}
45+
{include file='modules_footer.tpl'}

0 commit comments

Comments
 (0)