Skip to content

Commit

Permalink
1.1.0 - added test to check compatibility with FT3
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed Jun 4, 2017
1 parent f7950d9 commit 3a372b4
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## module-system_check

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!
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!

### Documentation

Expand Down
18 changes: 18 additions & 0 deletions ft3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

require_once("../../global/library.php");
ft_init_module_page();

$page_vars = array(
"php_version" => phpversion(),
"php_version_compatible" => version_compare(phpversion(), 5.3, ">="),
"pdo_available" => extension_loaded("PDO"),
"pdo_mysql_available" => extension_loaded("pdo_mysql")
);

$page_vars["head_string"] =<<< EOF
<script src="{$g_root_url}/modules/system_check/global/scripts/tests.js"></script>
<link type="text/css" rel="stylesheet" href="{$g_root_url}/modules/system_check/global/css/styles.css">
EOF;

ft_display_module_page("templates/ft3.tpl", $page_vars);
5 changes: 5 additions & 0 deletions global/code/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
$results = sc_find_table_orphans($request["table_name"], $remove_orphans);
echo ft_convert_to_json($results);
break;

case "test_pdo_connection":
include_once("pdo.php");
echo ft_convert_to_json(sc_check_pdo_connection($request["port"]));
break;
}


21 changes: 21 additions & 0 deletions global/code/pdo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* This file gets included if the user has PDO installed on their system. It attempts to check the connection to
* the database using PDO.
*/


function sc_check_pdo_connection($port)
{
global $g_db_hostname, $g_db_name, $g_db_username, $g_db_password;

try {
$dsn = sprintf("mysql:host=%s;port=%s;dbname=%s;charset=utf8", $g_db_hostname, $port, $g_db_name);
new PDO($dsn, $g_db_username, $g_db_password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (PDOException $e) {
return array("success" => false, "msg" => $e->getMessage(), "port" => $port);
}

return array("success" => true, "port" => $port);
}
31 changes: 31 additions & 0 deletions global/scripts/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,37 @@ var sc_ns = {
ft.display_message("ft_message", error_type, message);
return;
}
},

test_pdo_connection: function () {
var port = $("#pdo_port").val();

$("#pdo_test_loading").html("<img src=\"images/loading.gif\" />");
$("#pdo_test_btn").attr("disabled", true);
$(".pdo_result").addClass("hidden");

$.ajax({
url: g.root_url + "/modules/system_check/global/code/actions.php",
data: { action: "test_pdo_connection", port: port },
type: "POST",
dataType: "json",
success: function(result) {
$("#pdo_test_loading").html("");
$("#pdo_test_btn").removeAttr("disabled");

if (result.success) {
if (result.port == 3306) {
$("#pdo_result_success").removeClass("hidden");
} else {
$("#custom_port").html(result.port);
$("#pdo_result_success_with_port").removeClass("hidden");
}
} else {
$("#pdo_result_error").removeClass("hidden");
$("#pdo_result_error_msg").html(result.msg);
}
}
})
}

};
6 changes: 5 additions & 1 deletion lang/en_us.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$L["module_description"] = "This replaces the older Database Integrity module. It offers various tests to analyze and repair your Form Tools installation.";

$L["word_untested"] = "Untested";
$L["word_test"] = "Test";
$L["word_testing_c"] = "Testing: ";
$L["word_help"] = "Help";
$L["word_component"] = "Component";
Expand Down Expand Up @@ -40,6 +41,8 @@
$L["phrase_suhosin_extension"] = "Suhosin Extension";
$L["phrase_curl_extension"] = "Curl Extension";
$L["phrase_simplexml_extension"] = "SimpleXML Extension";
$L["phrase_ft3_compatibility"] = "FT3 compatibility";
$L["phrase_formtools3_compatibility"] = "Form Tools 3 compatibility";

$L["text_tables_test"] = "The following tables will be tested to confirm they exist, and that the column information is valid.";
$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.";
Expand All @@ -53,6 +56,7 @@
$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>";
$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.";
$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.";
$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.";

$L["notify_test_complete_problems"] = "The test is complete. We found a problem with one or more of your installed components.";
$L["notify_test_complete_no_problems"] = "The test is complete. No problems were found.";
Expand All @@ -63,4 +67,4 @@
$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.";
$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.";

$L["validation_no_components_selected"] = "Please select one or more components to test.";
$L["validation_no_components_selected"] = "Please select one or more components to test.";
13 changes: 7 additions & 6 deletions module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
* Module file: System Check
*/

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

// define the module navigation - the keys are keys defined in the language file. This lets
// the navigation - like everything else - be customized to the users language. The paths are always built
// relative to the module's root, so help/index.php means: /[form tools root]/modules/export_manager/help/index.php
$MODULE["nav"] = array(
"module_name" => array('{$module_dir}/index.php', false),
"phrase_ft3_compatibility" => array('{$module_dir}/ft3.php', true),
"phrase_file_verification" => array('{$module_dir}/files.php', true),
"phrase_table_verification" => array('{$module_dir}/tables.php', true),
"phrase_hook_verification" => array('{$module_dir}/hooks.php', true),
"phrase_orphan_clean_up" => array('{$module_dir}/orphans.php', true),
"phrase_environment_info" => array('{$module_dir}/env.php', false),
"word_help" => array('{$module_dir}/help.php', false)
);
);
115 changes: 115 additions & 0 deletions templates/ft3.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{include file='modules_header.tpl'}

<table cellpadding="0" cellspacing="0">
<tr>
<td width="45"><img src="images/icon.png" width="34" height="34" /></td>
<td class="title">
<a href="../../admin/modules">{$LANG.word_modules}</a>
<span class="joiner">&raquo;</span>
<a href="./">{$L.module_name}</a>
<span class="joiner">&raquo;</span>
{$L.phrase_ft3_compatibility}
</td>
</tr>
</table>

{include file="messages.tpl"}

<div class="margin_bottom_large">
{$L.text_ft3_compatibility}
</div>

<table class="list_table" cellspacing="1" cellpadding="0" style="width: 600px">
<tr>
<th>{$L.word_test}</th>
<th>{$L.word_result}</th>
<th>{$L.word_result}</th>
</tr>
<tr>
<td class="pad_left_small medium_grey">Compatible PHP Version</td>
<td class="pad_left_small">{$php_version}</td>
<td align="center">
{if $php_version_compatible}
<span class="green">{$LANG.word_pass|upper}</span>
{else}
<span class="red">{$LANG.word_fail|upper}</span>
{/if}
</td>
</tr>
<tr>
<td class="pad_left_small medium_grey">PDO Available</td>
<td class="pad_left_small">
{if $pdo_available}
{$LANG.word_yes}
{else}
{$LANG.word_no}
{/if}
</td>
<td align="center">
{if $pdo_available}
<span class="green">{$LANG.word_pass|upper}</span>
{else}
<span class="red">{$LANG.word_fail|upper}</span>
{/if}
</td>
</tr>
<tr>
<td class="pad_left_small medium_grey">PDO-MySQL extension available</td>
<td class="pad_left_small">
{if $pdo_mysql_available}
{$LANG.word_yes}
{else}
{$LANG.word_no}
{/if}
</td>
<td align="center">
{if $pdo_mysql_available}
<span class="green">{$LANG.word_pass|upper}</span>
{else}
<span class="red">{$LANG.word_fail|upper}</span>
{/if}
</td>
</tr>
</table>

{if $php_version_compatible && $pdo_available && $pdo_mysql_available}

<br />

<p><b>Test Database Connection</b></p>

<p>
This attempts to make a database connection using PDO. By default PDO connects on port <b>3306</b>.
</p>

<p>
Port:
<input type="text" id="pdo_port" size="6" value="3306" />
<input type="button" id="pdo_test_btn" value="{$L.phrase_run_test}" onclick="sc_ns.test_pdo_connection()" />
<span id="pdo_test_loading"></span>
</p>

<div id="pdo_result_error" class="error pdo_result hidden">
<div style="padding: 6px">
Sorry, there was a problem connecting. Here's the error that was returned:
<p><b id="pdo_result_error_msg"></b></p>
</div>
</div>

<div id="pdo_result_success" class="notify pdo_result hidden">
<div style="padding: 6px">
Excellent! You will be able to upgrade to Form Tools 3 without making any changes to your configuration.
</div>
</div>

<div id="pdo_result_success_with_port" class="notify pdo_result hidden">
<div style="padding: 6px">
Excellent! You will be able to upgrade to Form Tools 3 but will need to add the following setting to your
<b>/global/config.php</b> file:
<p><b>$g_db_port = <span id="custom_port"></span>;</b></p>
</div>
</div>

{/if}

{include file='modules_footer.tpl'}
6 changes: 5 additions & 1 deletion templates/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<hr size="1" />

<table cellspacing="0" class="index_link_table">
<tr>
<td valign="top" width="160"><a href="ft3.php">{$L.phrase_formtools3_compatibility}</a></td>
<td>{$L.text_ft3_compatibility}</td>
</tr>
<tr>
<td valign="top" width="160"><a href="files.php">{$L.phrase_file_verification}</a></td>
<td>{$L.text_file_check} {$L.text_problems_identified_not_fixed}</td>
Expand All @@ -38,4 +42,4 @@
</tr>
</table>

{include file='modules_footer.tpl'}
{include file='modules_footer.tpl'}

0 comments on commit 3a372b4

Please sign in to comment.