Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes when using MySQL
- db_query of an insert returns 0 if the table doesn't have an AI PK!!
  • Loading branch information
torinfo committed Jun 2, 2014
1 parent 80118eb commit 6acc4d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
25 changes: 5 additions & 20 deletions library/Xerte/Authentication/Db.php
Expand Up @@ -44,40 +44,25 @@ public function getSurname()
public function check()
{
global $xerte_toolkits_site;
if (!function_exists('mysql_query')) {
$this->addError("MySQL not available?");
return false;
}
_debug("Calling check");
// check for existence of the 'user' db table?
$x = db_query("SHOW CREATE TABLE {$xerte_toolkits_site->database_table_prefix}user");
if (empty($x)) {
// Create the user table
$x = db_query("create table {$xerte_toolkits_site->database_table_prefix}user ( `iduser` INT NOT NULL AUTO_INCREMENT, `username` VARCHAR(45) NULL , `password` VARCHAR(45) NULL , `firstname` VARCHAR(45) NULL , `surname` VARCHAR(45) NULL , `email` VARCHAR(45) NULL, PRIMARY KEY (`iduser`) )");
if (empty($x))
{
_debug("Failed: Does the user table exist?");
$this->addError("Does the user table exist?");
return false;
}
else
return true;
}
else
{
$row = mysql_fetch_array($x);
if(strpos($row[1], "email") === false)
{

// Add column email
$x = db_query("ALTER TABLE {$xerte_toolkits_site->database_table_prefix}user ADD COLUMN `email` VARCHAR(45) NULL AFTER `surname`");
if (empty($x))
{
$this->addError("Could not add email column to the user table.");
return false;
}
else
return true;
_debug("Succeeded!");
return true;
}
}
_debug("Succeeded!");
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion website_code/php/template_status.php
Expand Up @@ -119,7 +119,7 @@ function has_template_multiple_editors($template_id){
. "{$prefix}templaterights.template_id = {$prefix}templatedetails.template_id and "
. "{$prefix}templatedetails.creator_id = {$prefix}logindetails.login_id and "
. "{$prefix}templaterights.template_id= ? AND role = ?";
$params = array($_GET['template_id']. "read-only");
$params = array($_GET['template_id'], "read-only");

$query_response = db_query($query_for_read_only, $params);
$read_only_rows = sizeof($query_response);
Expand Down
10 changes: 6 additions & 4 deletions website_code/php/templates/new_template.php
Expand Up @@ -43,14 +43,16 @@
}
$query_for_new_template = "INSERT INTO {$xerte_toolkits_site->database_table_prefix}templatedetails (template_id, creator_id, template_type_id, date_created, date_modified, number_of_uses, access_to_whom, template_name, extra_flags)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$ok = db_query($query_for_new_template, array($new_template_id, $_SESSION['toolkits_logon_id'] , $row_template_type['template_type_id'] , date('Y-m-d'), date('Y-m-d'), 0, "Private", str_replace(" ","_", $_POST['tutorialname']), $extraflags));
$lastid = db_query($query_for_new_template, array($new_template_id, $_SESSION['toolkits_logon_id'] , $row_template_type['template_type_id'] , date('Y-m-d'), date('Y-m-d'), 0, "Private", str_replace(" ","_", $_POST['tutorialname']), $extraflags));

if($ok) {
// templatedetails doesn't have a AI field, so $lastid returns always 0, check explicitly for false
if($lastid !== false) {
_debug("Created new template entry in db");
$query_for_template_rights = "INSERT INTO {$xerte_toolkits_site->database_table_prefix}templaterights (template_id, user_id, role, folder) VALUES (?,?,?,?)";
$ok = db_query($query_for_template_rights, array($new_template_id, $_SESSION['toolkits_logon_id'], "creator", "" . $root_folder_id));
$lastid = db_query($query_for_template_rights, array($new_template_id, $_SESSION['toolkits_logon_id'], "creator", "" . $root_folder_id));

if($ok) {
// templaterights doesn't have a AI field, so $lastid returns always 0, check explicitly for false
if($lastid !==false) {
_debug("Setup template rights ok");
receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "SUCCESS", "Created new template record for the database", $query_for_new_template . " " . $query_for_template_rights);
include $xerte_toolkits_site->root_file_path . $xerte_toolkits_site->module_path . $row_template_type['template_framework'] . "/new_template.php";
Expand Down

0 comments on commit 6acc4d9

Please sign in to comment.