Skip to content

Commit

Permalink
Merge pull request coral-erm#503 from jeffnm/Issue_470_export_resourc…
Browse files Browse the repository at this point in the history
…es_bug

Issue 470 export resources bug
  • Loading branch information
veggiematts authored Nov 30, 2018
2 parents f41517c + 21fec80 commit 57ac224
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 25 deletions.
13 changes: 13 additions & 0 deletions auth/install/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,19 @@ function register_auth_provider()
];


case "3.0.1":
return [
"function" => function($shared_module_info) {
$return = new stdClass();
$return->yield = new stdClass();
$return->success = true;
$return->yield->title = _("Auth Module");
return $return;
}
];



/**
* This code is for when the upgrade requires no changes to the
* database or conf files etc.
Expand Down
4 changes: 2 additions & 2 deletions install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
*
* NOTE: It is assumed that version strings can be understood by php's version_compare function
*/
$INSTALLATION_VERSION = "3.0.0";
$INSTALLATION_VERSIONS = ["1.9.0", "2.0.0", "3.0.0"];
$INSTALLATION_VERSION = "3.0.1";
$INSTALLATION_VERSIONS = ["1.9.0", "2.0.0", "3.0.0", "3.0.1"];

function make_sure_template_is_drawn()
{
Expand Down
42 changes: 23 additions & 19 deletions install/providers/db_tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,33 @@ function register_db_tools_provider()
}
else
{
// Run the file - checking for errors at each SQL execution
// Run the file - checking for errors at each SQL execution
$f = fopen($sql_file,"r");
$sqlFile = fread($f,filesize($sql_file));
$sqlArray = explode(";",$sqlFile);
// Process the sql file by statements
foreach ($sqlArray as $stmt)
{
if (strlen(trim($stmt))>3)
{
try
{
/**
* Considering implementing dry running of some kind?
* https://secure.php.net/manual/en/mysqli.autocommit.php
*/
$db->processQuery($stmt);
}
catch (Exception $e)
{
$ret["messages"][] = $db->getError() . "<br />For statement: " . $stmt;
//$sqlFile = mysqli_real_escape_string($db->getDatabase(), $sqlFile);

if(mysqli_multi_query($db->getDatabase(), $sqlFile)){
do {
if ($result = mysqli_store_result($db->getDatabase())) {
mysqli_free_result($result);
}

if(mysqli_errno($db->getDatabase())) {
// report error
$ret["messages"][] = mysqli_error($db->getDatabase()) . "<br />For SQL file: " . $sql_file;
$ret["success"] = false;
}

} while (mysqli_next_result($db->getDatabase()));

if(mysqli_errno($db->getDatabase())) {
// report error
$ret["messages"][] = mysqli_error($db->getDatabase()) . "<br />For SQL file: " . $sql_file;
$ret["success"] = false;
}
}
}else{
$ret["messages"][] = mysqli_error($db->getDatabase()) . "<br /> Occurred while trying to run mysqli_multi_query for SQL file: " . $sql_file;
$ret["success"] = false;
}
}
return $ret;
Expand Down
10 changes: 10 additions & 0 deletions licensing/install/licensing.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ function register_licensing_provider()
return $return;
}
];
case "3.0.1":
return [
"function" => function($shared_module_info) {
$return = new stdClass();
$return->yield = new stdClass();
$return->success = true;
$return->yield->title = _("Licensing Module");
return $return;
}
];

/**
* This code is for when the upgrade requires no changes to the
Expand Down
11 changes: 10 additions & 1 deletion management/install/management.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ function register_management_provider()
return $return;
}
];

case "3.0.1":
return [
"function" => function($shared_module_info) {
$return = new stdClass();
$return->yield = new stdClass();
$return->success = true;
$return->yield->title = _("Management Module");
return $return;
}
];

default:
return null;
Expand Down
11 changes: 10 additions & 1 deletion organizations/install/organizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,16 @@ function register_organizations_provider()
return $return;
}
];

case "3.0.1":
return [
"function" => function($shared_module_info) {
$return = new stdClass();
$return->yield = new stdClass();
$return->success = true;
$return->yield->title = _("Organizations Module");
return $return;
}
];

default:
return null;
Expand Down
11 changes: 10 additions & 1 deletion reports/install/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ function register_reports_provider()
return $return;
}
];

case "3.0.1":
return [
"function" => function($shared_module_info) {
$return = new stdClass();
$return->yield = new stdClass();
$return->success = true;
$return->yield->title = _("Reports Module");
return $return;
}
];

default:
return null;
Expand Down
22 changes: 22 additions & 0 deletions resources/install/protected/3.0.1/001-470.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
DROP PROCEDURE IF EXISTS add_missing_taxfield;

CREATE DEFINER=CURRENT_USER PROCEDURE add_missing_taxfield(missing_taxfield TEXT charset utf8)
BEGIN
DECLARE colName TEXT;
SELECT column_name INTO colName
FROM information_schema.columns
WHERE table_name='ResourcePayment'
AND column_name=missing_taxfield;

IF colName is null THEN
SET @stmt=CONCAT('ALTER TABLE `ResourcePayment` ADD `',missing_taxfield,'` int(10) unsigned default NULL');
PREPARE stmt FROM @stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL add_missing_taxfield('priceTaxExcluded');
CALL add_missing_taxfield('taxRate');
CALL add_missing_taxfield('priceTaxIncluded');
DROP PROCEDURE add_missing_taxfield;
45 changes: 45 additions & 0 deletions resources/install/resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,52 @@ function register_resources_provider()
}
];

case "3.0.1":
$conf_data = parse_ini_file($protected_module_data["config_file_path"], true);
return [
"dependencies_array" => [ "db_tools", "have_read_write_access_to_config" ],
"sharedInfo" => [
"config_file" => [
"path" => $protected_module_data["config_file_path"],
],
"database_name" => $conf_data["database"]["name"]
],
"function" => function($shared_module_info) use ($MODULE_VARS, $protected_module_data, $version) {
$return = new stdClass();
$return->success = true;
$return->yield = new stdClass();
$return->yield->title = _("Resources Module");
$return->yield->messages = [];

$conf_data = parse_ini_file($protected_module_data["config_file_path"], true);

// PROCESS SQL FILES
$db_name = $conf_data["database"]["name"];
$dbconnection = $shared_module_info["provided"]["get_db_connection"]( $db_name );
$ret = $shared_module_info["provided"]["process_sql_files"]( $dbconnection, $version, $MODULE_VARS["uid"] );
if (!$ret["success"])
{
$return->success = false;
$return->yield->messages = array_merge($return->yield->messages, $ret["messages"]);
return $return;
}

// EDIT CONF FILE
// Note the "have_read_write_access_to_config" dependency above - it ensure we have the "provided" method below...
$configFile = $protected_module_data["config_file_path"];
// Make sure the parent category exists
if (empty($conf_data["settings"]))
$conf_data["settings"] = [];
// Populate the variable with a value
// Warning: do not set $conf_data["general"] = ["random" => "something"] or you will lose other variables. Rather:
$conf_data["settings"]["ebscoKbEnabled"] = "N";
$conf_data["settings"]["ebscoKbCustomerId"] = "";
$conf_data["settings"]["ebscoKbApiKey"] = "";
$shared_module_info["provided"]["write_config_file"]($configFile, $conf_data);

return $return;
}
];
default:
return null;
}
Expand Down
11 changes: 10 additions & 1 deletion usage/install/usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,16 @@ function register_usage_provider()
return $return;
}
];

case "3.0.1":
return [
"function" => function($shared_module_info) {
$return = new stdClass();
$return->yield = new stdClass();
$return->success = true;
$return->yield->title = _("Usage Module");
return $return;
}
];
default:
return null;
}
Expand Down

0 comments on commit 57ac224

Please sign in to comment.