Skip to content

Commit

Permalink
Merged branch Hotfix-1.4.1 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffnm committed Oct 24, 2016
2 parents bbb6ed4 + e5f1078 commit f2b36d7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
61 changes: 61 additions & 0 deletions admin/classes/common/DBService.php
Expand Up @@ -93,6 +93,67 @@ public function processQuery($sql, $type = NULL) {
return $data;
}

/**
* Version of processQuery() that deals with prepared statements. As prepared
* statements use variadic functions, much of this function's complexity
* comes from wrapping a variadic function in a PHP 5.5 compatible way.
*
* @param string $query Same format as mysqli::prepare(), with usually one
* or more "?" inside it.
*
* @param string $type Must be "num" or "assoc". Contrary to processQuery(),
* it's not an optionnal argument. Due to this function being variadic.
*
* @param mixed ...$paramsToBind Same format as mysqli_stmt::bind_param()
* It's a variadic function based on this PHP 5.5 compatible implementation
* https://wiki.php.net/rfc/variadics#introduction
* We will be able to simplify this once we require PHP 5.6
* https://secure.php.net/manual/en/migration56.new-features.php#migration56.new-features.variadics
*/
public function processPreparedQuery($query, $type) {
$paramsToBind = array_slice(func_get_args(), 2); // additional arguments
// prepared statements specific code
$statement = $this->db->prepare($query);
$this->checkForError();
// The following is an implementation of the splat operator. This
// will be simpler with PHP 5.6
// https://secure.php.net/manual/en/migration56.new-features.php#migration56.new-features.splat
// We need to pass references to bind_param(), hence the use of refValues()
call_user_func_array([$statement, "bind_param"], self::refValues($paramsToBind)) ;
$statement->execute();
$result = $statement->get_result();

// same as processQuery()
$this->checkForError();
$data = array();

if ($result instanceof mysqli_result) {
$resultType = MYSQLI_NUM;
if ($type == 'assoc') {
$resultType = MYSQLI_ASSOC;
}
while ($row = $result->fetch_array($resultType)) {
if ($this->db->affected_rows > 1) {
array_push($data, $row);
} else {
$data = $row;
}
}
$result->free();
} else if ($result) {
$data = $this->db->insert_id;
}

return $data;
}

private static function refValues($arr){
$refs = array();
foreach($arr as $key => $value) {
$refs[$key] = &$arr[$key];
}
return $refs;
}
}

?>
6 changes: 4 additions & 2 deletions admin/classes/common/DatabaseObject.php
Expand Up @@ -282,8 +282,10 @@ public function allAsArray() {
public function load() {
//if exists in the database
if (isset($this->primaryKey)) {
$query = "SELECT * FROM `$this->tableName` WHERE `$this->primaryKeyName` = '$this->primaryKey'";
$result = $this->db->processQuery($query, 'assoc');
$query = "SELECT * FROM `$this->tableName` WHERE `$this->primaryKeyName` = ?";
$result = $this->db->processPreparedQuery($query, "assoc",
"s",
$this->primaryKey);

foreach (array_keys($result) as $attributeName) {
$this->addAttribute($attributeName);
Expand Down
4 changes: 4 additions & 0 deletions install/UPGRADE_README.txt
@@ -1,3 +1,7 @@
1.4.1 The 1.4.1 update is a security fix

- No database changes.

1.4 The 1.4 update to the CORAL Resources module includes the following enhancements:

-Added Issue tracker feature that allows tracking of down resources.
Expand Down
2 changes: 1 addition & 1 deletion templates/footer.php
Expand Up @@ -28,6 +28,6 @@
<div class="push">&nbsp;</div>
</div>

<div class="footer">Copyright &copy; 2015. Resources Module version 1.4<br/><a href="http://coral-erm.org/">CORAL Project Website</a> | <a href="https://github.com/ndlibersa/resources">GitHub Site</a></div>
<div class="footer">Copyright &copy; 2015. Resources Module version 1.4.1<br/><a href="http://coral-erm.org/">CORAL Project Website</a> | <a href="https://github.com/ndlibersa/resources">GitHub Site</a></div>
</body>
</html>

0 comments on commit f2b36d7

Please sign in to comment.