Skip to content

Commit

Permalink
More cleanup in the dev launch and adding some database sanity checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Mar 22, 2014
1 parent 90acf80 commit 4f2e649
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions dev-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"resource_link_id" => "292832126",
"resource_link_title" => "Weekly Blog",
"resource_link_description" => "A weekly blog.",
"lis_result_sourcedid" => "sdid:292832126",
"context_id" => "456434513",
"context_label" => "SI106",
"context_title" => "Introduction to Programming",
Expand Down
5 changes: 4 additions & 1 deletion dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function doSubmit(name) {
hash = ((hash<<5)-hash)+character;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
return Math.abs(hash);
}

function doSubmitTool(name) {
Expand All @@ -129,6 +129,9 @@ function doSubmitTool(name) {
document.getElementById("actionform").appendChild(nei);
$("input[name='custom_assn']").val(name);
$("input[name='resource_link_id']").val(name.hashCode());
pieces = name.split('/');
$("input[name='resource_link_title']").val('Activity: '+pieces[1]);
$("input[name='lis_result_sourcedid']").val('sdid:'+name.hashCode());
document.getElementById("actionform").submit();
}
</script>
Expand Down
4 changes: 4 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
?>
</head>
<body>
<?php
require_once("sanity-db.php");
?>
<form method="post" id="actionform">
<div class="container">
<!-- Static navbar -->
Expand Down Expand Up @@ -69,6 +72,7 @@
'Note: Currently this server is running in developer mode.'.
"\n</div>\n";
}

?>
<p>
Hello and welcome to <b><?php echo($CFG->servicename); ?></b>.
Expand Down
13 changes: 9 additions & 4 deletions pdo.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php

try {
if ( defined('PDO_WILL_CATCH') ) {
$pdo = new PDO($CFG->pdo, $CFG->dbuser, $CFG->dbpass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $ex){
error_log("DB connection: "+$ex->getMessage());
die($ex->getMessage());
} else {
try {
$pdo = new PDO($CFG->pdo, $CFG->dbuser, $CFG->dbpass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $ex){
error_log("DB connection: "+$ex->getMessage());
die($ex->getMessage());
}
}

function pdoQueryDie($pdo, $sql, $arr=FALSE, $error_log=TRUE) {
Expand Down
40 changes: 40 additions & 0 deletions sanity-db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

// Lets check to see if we have a database or not and give a decent error message
try {
define('PDO_WILL_CATCH', true);
require_once("pdo.php");
} catch(PDOException $ex){
$msg = $ex->getMessage();
error_log("DB connection: "+$msg);
echo('<div class="alert alert-danger" style="margin-top: 10px;">'."\n");
if ( strpos($msg, 'Unknown database') !== false ) {
echo("<p>It does not appear as though your database exists.</p>
<p> If you have full access to your MySql instance (i.e. like
MAMP or XAMPP, you may need to run commands like this:</p>
<pre>
CREATE DATABASE tsugi DEFAULT CHARACTER SET utf8;
GRANT ALL ON tsugi.* TO 'ltiuser'@'localhost' IDENTIFIED BY 'ltipassword';
GRANT ALL ON tsugi.* TO 'ltiuser'@'127.0.0.1' IDENTIFIED BY 'ltipassword';
</pre>
<p>Make sure to choose appropriate passwords when setting this up.</p>
<p>If you are running in a hosted environment and are using an admin tool like
CPanel (or equivalent). You must user this interface to create a database,
user, and password.</p>
<p>
Once you have the database, account and password you must update your
<b>config.php</b> with this information.</p>
");
} else {
echo("<p>There is a problem with your database connection.</p>\n");
echo("<p>Database error: ".$msg."</p>\n");
}

echo("<p>Once you have fixed the problem, come back to this page and refresh
to see if this message goes away.</p>");
echo('<p>Installation instructions are avaiable at <a href="http://www.tsugi.org/"
target="_blank">tsugi.org</a>');

echo("\n</div>\n");
die();
}

0 comments on commit 4f2e649

Please sign in to comment.